def InsulationPanel(left_edge, right_edge): points = [] #insulation_left = ver_line_split_even[i] point_1 = rs.CurveStartPoint(left_edge) point_2 = rs.CurveEndPoint(left_edge) #insulation_right = ver_line_split_even[i + next_even_Cource] point_3 = rs.CurveEndPoint(right_edge) point_4 = rs.CurveStartPoint(right_edge) trans = rs.XformTranslation((0, 0, ipThick)) point_5 = rs.PointTransform(point_1, trans) point_6 = rs.PointTransform(point_2, trans) point_7 = rs.PointTransform(point_3, trans) point_8 = rs.PointTransform(point_4, trans) points.append(point_1) points.append(point_2) points.append(point_3) points.append(point_4) points.append(point_5) points.append(point_6) points.append(point_7) points.append(point_8) insulation = rs.AddBox(points) return insulation
def MirrorX(lineIn, pIn): pLine0 = lineIn[0] pLine1 = lineIn[1] normal = rs.VectorUnitize( rs.VectorCrossProduct([0, 0, 1], rs.VectorSubtract(pLine1, pLine0))) matrix = rs.XformMirror(pLine1, normal) return rs.PointTransform(pIn, matrix)
def WindowFrame(): surf_int_edge_all = rs.DuplicateSurfaceBorder(surf[1], type=2) print len(surf_int_edge_all) window_frame_all = [] for item in range(0, len(surf_int_edge_all), 1): surf_int_edge = surf_int_edge_all[item] surf_int_edge = rs.ExplodeCurves(surf_int_edge, True) trans1 = rs.XformTranslation((0, 0, 2 * ipThick)) trans2 = rs.XformTranslation((0, 0, -2 * ipThick)) point_1 = rs.CurveStartPoint(surf_int_edge[0]) point_2 = rs.CurveStartPoint(surf_int_edge[1]) point_3 = rs.CurveStartPoint(surf_int_edge[2]) point_4 = rs.CurveStartPoint(surf_int_edge[3]) point_5 = rs.PointTransform(point_1, trans1) point_6 = rs.PointTransform(point_2, trans1) point_7 = rs.PointTransform(point_3, trans1) point_8 = rs.PointTransform(point_4, trans1) point_1 = rs.PointTransform(point_1, trans2) point_2 = rs.PointTransform(point_2, trans2) point_3 = rs.PointTransform(point_3, trans2) point_4 = rs.PointTransform(point_4, trans2) frame_points = [] frame_points.append(point_1) frame_points.append(point_2) frame_points.append(point_3) frame_points.append(point_4) frame_points.append(point_5) frame_points.append(point_6) frame_points.append(point_7) frame_points.append(point_8) window_frame = rs.AddBox(frame_points) window_frame_all.append(window_frame) return window_frame_all
def RunScript(self, Listener_Location, Direction, Height): __author__ = "theomarchal" self.Params.Input[ 0].Description = "Location of the listener foots (as a point - Default is set to 0,0,0)" self.Params.Input[ 1].Description = "Direction of the listener (in degrees from 0 to 360)" self.Params.Input[ 2].Description = "How tall is the listener (default = 1.80)" self.Params.Output[ 0].Description = "Listener Geometry, size and direction" self.Params.Output[ 1].Description = "Listener Object (plug it into EsquisSons)" self.Name = "Listener Point" self.NickName = "Listener" self.Message = "EsquisSons V3" self.Category = "EsquisSons" self.SubCategory = "1/ Scene" import rhinoscriptsyntax as rs LL = Listener_Location LD = Direction LH = Height if LL is None: LL = rs.AddPoint(0, 0, 0) if LD is None: LD = 0 if LH is None: LH = 1.8 LV = rs.VectorRotate([0, (LH), 0], LD, [0, 0, 1]) matrix = rs.XformTranslation((0, 0, LH)) LHp = rs.PointTransform(LL, matrix) LV2 = rs.VectorScale((rs.VectorRotate(LV, 90, [0, 0, 1])), 0.5) LV3 = rs.VectorScale((rs.VectorRotate(LV, -90, [0, 0, 1])), 0.5) T1 = rs.PointTransform(LL, (rs.XformTranslation(LV))) Tl = rs.PointTransform(LL, (rs.XformTranslation(LV2))) Tr = rs.PointTransform(LL, (rs.XformTranslation(LV3))) ps = [T1, Tl, Tr] Geo = [ rs.AddSphere(LHp, (LH / 10)), rs.AddLine(LL, LHp), rs.AddSrfPt(ps) ] Tl = rs.PointTransform(Tl, matrix) Tr = rs.PointTransform(Tr, matrix) LP = [LHp, Tl, Tr, LH] Listener = [LP] return (Geo, Listener)
#coding=utf-8 import rhinoscriptsyntax as rs firstpoint = rs.GetPoint("Selet one point") #在rhinoceros中失区点 rangel = 4 #定义x方向上复制点的数量 multiplev = 12 #定义点间距的倍数 mpoints = [] #定义第一排x方向列表 #循环x方向上复制点数量的参数,形成第一排 for i in range(rangel): matrix1 = rs.XformTranslation((i * multiplev, 0, 0)) #建立x方向上的矩阵 mpoint1 = rs.PointTransform(firstpoint, matrix1) #根据变换矩阵移动点 mpoints.append(mpoint1) #将移动的点依次放置于事项定义的空列表 rs.AddPoint(mpoint1) #在rhino空间中增加每次移动的点 rangeh = 4 #定义Y方向上复制点的次数 dpoints = {} #定义空的字典,放置所有移动的点,每一横排的点放置于一个单独的列表中,作为值 mpointh = [] #放置所有点的空列表 deletep = [] #放置每一次内部循环即横排点的空列表,用于字典 #循环Y方向上的复制点的次数 for i in range(rangeh): matrixh = rs.XformTranslation((0, i * multiplev, 0)) #建立Y方向上的变换矩阵 for m in range(len(mpoints)): pointh = rs.PointTransform(mpoints[m], matrixh) #按照变换矩阵逐个移动每一个点 rs.AddPoint(pointh) #在rhino空间中增加每次移动点 mpointh.append(pointh) #将点加入列表 deletep.append(pointh) dpoints[i] = deletep #加入字典 deletep = [] print(dpoints)
def RotateX(centerPoint, angle, pIn): matrix = rs.XformRotation2(angle, [0, 0, 1], centerPoint) return rs.PointTransform(pIn, matrix)
def MoveX(startPoint, endPoint, pIn): matrix = rs.XformTranslation(rs.VectorSubtract(endPoint, startPoint)) return rs.PointTransform(pIn, matrix)
def ScaleX(startPoint, factor, pIn): matrix = rs.XformScale(factor, startPoint) return rs.PointTransform(pIn, matrix)
__author__ = "billpower" __version__ = "2019.12.27" import rhinoscriptsyntax as rs #start建立基本结构线 basicpoint = rs.GetPoint("pick one point") #1.拾取一个点 matrix = rs.XformTranslation((80, 0, 0)) #建立用于移动的矩阵 mbpoint = rs.PointTransform(basicpoint, matrix) #根据建立的矩阵移动点 basicline = rs.AddLine(basicpoint, mbpoint) #2.建立一条直线 offsetdistance = 10 offsetlineA = rs.OffsetCurve(basicline, [0, 0, 0], offsetdistance, [0, 0, 1]) #3.偏移复制直线 offsetlineB = rs.OffsetCurve(basicline, [0, 0, 0], -offsetdistance, [0, 0, 1]) #调整结构线,使用提取点移动 extendvalue = 2 #中间直线延长的距离 extendline = rs.ExtendCurveLength(basicline, 0, 2, extendvalue) #4.延长中间直线 startpoint = rs.CurveStartPoint(extendline) #5.拾取两侧端点 endpoint = rs.CurveEndPoint(extendline) midpoint = rs.CurveMidPoint(extendline) heightA = 10 heightB = 18 matrixstartend = rs.XformTranslation((0, 0, heightA)) #建立端点移动矩阵 matrixmid = rs.XformTranslation((0, 0, heightB)) #建立中间点移动矩阵 mstartpoint = rs.PointTransform(startpoint, matrixstartend) #根据矩阵移动开始点
def main(): # get our curves profile, cross = get_two_curves() if profile is None or cross is None: return ################################################## # get bounding box for cross section cross_bbox = rs.BoundingBox([cross]) cmin, cmax = box_to_points(cross_bbox) cz_range = cmax[2] - cmin[2] cz = 0.5 * (cmax[2] + cmin[2]) c_ctr, _ = rs.CurveAreaCentroid(cross) # make sure it's planar in XY if cz_range > 1e-9: print 'cross section curve should be planar in XY plane' return ################################################## # get bounding box for profile profile_bbox = rs.BoundingBox([profile]) # make sure it's planar in in YZ pmin, pmax = box_to_points(profile_bbox) px_range = pmax[0] - pmin[0] if px_range > 1e-9: print 'profile curve should be planar in YZ plane' return ################################################## # get the point closest to the center for the # cross-section curve r, pc = get_inscribed_radius(cross, c_ctr) ################################################## # get the range of z-values for the profile curve _, _, z0 = pmin _, _, z1 = pmax ################################################## # build list of rings and list of points points = [] ring_pipes = [] # for each level for i in range(num_levels): # get the Z value of the ith plane u = float(i) / (num_levels-1) z = z0 + u*(z1 - z0) # build the i'th plane plane = rs.PlaneFromNormal([0, 0, z], [0, 0, 1], [1, 0, 0]) # find out where the plane intersects the profile curve intersect = rs.PlaneCurveIntersection(plane, profile) # there should be exactly one intersection of type 1 (point) if intersect is None or len(intersect) > 1 or intersect[0][0] != 1: print 'bad intersection' return # get the intersection point pi = intersect[0][1] # get the desired XY radius at this z value ri = abs(pi[1]) # we need to set up some transformations: # translate cross section curve down to z=0 T1 = rs.XformTranslation(mz.vec_mul(list(c_ctr), -1.0)) # scale it along XY by the ratio of radii S1 = rs.XformScale([ri/r, ri/r, 1.0]) # scale a piped cross section along Z by a vertical scale factor S2 = rs.XformScale([1.0, 1.0, ring_vscale]) # translate piped cross section up to our desired z value T2 = rs.XformTranslation([0, 0, z]) # scale and translate cross section curve ci = rs.TransformObject(cross, rs.XformMultiply(S1, T1), copy=True) # pipe it ring = rs.AddPipe(ci, [0, 1], [ring_rad, ring_rad]) # scale vertically and transform up ring = rs.TransformObject(ring, rs.XformMultiply(T2, S2)) # delete the copy of the cross section curve rs.DeleteObject(ci) # add to list of ring pipes ring_pipes.append(ring) # create a rotation by the i'th angle angle_i_deg = i*360.0/num_sides Ri = rs.XformRotation2(angle_i_deg, [0, 0, 1], [0, 0, 0]) # transform the closest point by rotation and scale pci = rs.PointTransform(pc, rs.XformMultiply(rs.XformMultiply(Ri, T2), S1)) # add to list of points points.append(pci) # we have built up a list of points for a single spiral of struts to connect, # now we need to pipe them all together and do the ArrayPolar thing around # the z axis # first build a single spiral of struts strut_pipes = [] for i0 in range(num_levels-1): i1 = i0+1 p0 = points[i0] p1 = points[i1] l01 = rs.AddLine(p0, p1) pipe = rs.AddPipe(l01, [0, 1], [strut_rad, strut_rad], cap=2) rs.DeleteObject(l01) strut_pipes.append(pipe) # then array polar around Z axis all_strut_pipes = [] all_strut_pipes += strut_pipes for j in range(1, num_sides): angle_j_deg = j*360.0/num_sides Rj = rs.XformRotation2(angle_j_deg, [0, 0, 1], [0, 0, 0]) all_strut_pipes += rs.TransformObjects(strut_pipes, Rj, copy=True) # now just select all the objects we created rs.SelectObjects(ring_pipes + all_strut_pipes) # done! print 'yay'
def FixedFractureGen(n, aspect_ratio=None, sides=None): """ A function to add a fixed number of circles in a cube. It also writes data to fracture data text file for regenerating fracture networks. """ if fracture_shape == 'circle': # initialize a to store fractures fracture_list = [] # a loop to insert the fixed number of fractures for i in range(n): #layer name for the frcature layer_name = "FRACTURE_" + str(i + 1) #create an istance of Fracture class frac = Fracture() #store fracture name frac.fracture_name = layer_name #generate origin for fracture origin = GeneratePoint(boxlength) #store farcture center frac.fracture_center = origin #convert the origin to a plane plane = InclinePlane(origin) #add layer and color rs.AddLayer(layer_name, rs.CreateColor(0, 255, 0)) #make current layer rs.CurrentLayer(layer_name) #insert the fracture in the domain my_circle = rs.AddCircle(plane, radius) #circle_list.append(my_circle) surf = rs.AddPlanarSrf(my_circle) #delete initial fracture drawn which is a curve rs.DeleteObject(my_circle) #save fracture's GUID frac.fracture_GUID = surf[0] #append fracture into fracture list fracture_list.append(frac) elif fracture_shape == 'ellipse': #list to store fracture surface GUIDs fracture_list = [] for i in range(n): #layer name for the frcature layer_name = "FRACTURE_" + str(i + 1) #create an istance of Fracture class frac = Fracture() frac.fracture_name = layer_name #generate fracture origin origin = GeneratePoint(boxlength) frac.fracture_center = origin #plane for fracture plane = InclinePlane(origin) #calculate r_y ry = radius / aspect_ratio #create layer for fracture rs.AddLayer(layer_name, rs.CreateColor(0, 255, 0)) rs.CurrentLayer(layer_name) #draw ellipse fracture = rs.AddEllipse(plane, radius, ry) # write the plane, r_x and r_y to file for re-plotting ##file.write("\n" + str(plane[0]) + "," + str(plane[1]) + "," + str(plane[2]) + "," + str(radius) + ","+ str(ry)) #make fracture a surface frac_surf = rs.AddPlanarSrf(fracture) #delete initial fracture drawn which is a curve rs.DeleteObject(fracture) #append surface GUID to list of fracture surfaces frac.fracture_GUID = frac_surf[0] fracture_list.append(frac) elif fracture_shape == 'polygon': #list to store fracture surface GUIDs fracture_list = [] #write the shape type ##file.write('\npolygon\n') for i in range(n): layer_name = "FRACTURE_" + str(i + 1) frac = Fracture() frac.fracture_name = layer_name #theta in radian theta_rad = (2 * math.pi) / sides #theta in degree (interior angles) theta_deg = theta_rad * (180 / math.pi) #generate origin origin = GeneratePoint(boxlength) frac.fracture_center = origin #create a 3D point object which isn't visible to the rhino document pt_01 = rs.coerce3dvector( [radius + origin[0], origin[1], origin[2]]) #empty list to store all points points = [] #a rotation axis ax = rs.coerce3dvector([0, 0, 1]) #loop to generate points for polygon vertices #file.write("\n") for j in range(sides): #rotation transform with rotation from the origin trans = rs.XformRotation2(theta_deg * j, ax, origin) #transform the original 3D point and append to list points.append(rs.PointTransform(pt_01, trans)) # append the initial point to close the polygon points.append(pt_01) # create layer for fracture # layer_name = "FRACTURE_" + str(i+1) rs.AddLayer(layer_name, rs.CreateColor(0, 255, 0)) rs.CurrentLayer(layer_name) # get GUID of created polygon polygon = rs.AddPolyline(points) # polygon = rs.AddPolyline(points) plane = InclinePlane(origin, boxlength) cob = rs.XformChangeBasis(rs.WorldXYPlane(), plane) shear2d = rs.XformIdentity() shear2d[0, 2] = math.tan(math.radians(45.0)) cob_inverse = rs.XformChangeBasis(plane, rs.WorldXYPlane()) temp = rs.XformMultiply(shear2d, cob) xform = rs.XformMultiply(cob_inverse, temp) fracture = rs.TransformObjects(polygon, xform, False) # make fracture a surface frac_surf = rs.AddPlanarSrf(fracture) # delete initial fracture drawn which is a curve rs.DeleteObject(fracture) frac.fracture_GUID = frac_surf[0] fracture_list.append(frac) return fracture_list
def RandomFractureGen(frac_min, frac_max, radius_min, radius_max, aspect_min=None, aspect_max=None, polysize_min=None, polysize_max=None): """ Funtions to generate fractures of random number and sizes Parameters ---------- frac_min: int minimum number of fractures to generate frac_max: int maximum number of fractures to generate radius_min: float minimum size of fractures radius_max: float maximum number of fractures to generate aspect_min: float minimum aspect ratio fpr ellipses (Default:None) aspect_max: float maximum aspect ratio fpr ellipses (Default:None) polysize_min: int minimum size of polygon (Default:None) polysize_max: int maximum size of polygon (Default:None) """ # randomly determine the number of fractures to generate num_frac = random.randint(frac_min, frac_max) # open file and append to it file = open(path, 'a') if fracture_shape == 'circle': # write the shape type file.write('\ncircle') # initialize list to store fractures fracture_list = [] # loop to generate fractures for i in range(num_frac): # name the layer layer_name = "FRACTURE_" + str(i + 1) # an instance of fracture object frac = Fracture() # get fracture name frac.fracture_name = layer_name # generate fracture center origin = GeneratePoint(boxlength) # store fracture center frac.fracture_center = origin # convert the origin to a plane plane = InclinePlane(origin, boxlength) # add layer and create color for it rs.AddLayer(layer_name, rs.CreateColor(0, 255, 0)) # make layer current layer rs.CurrentLayer(layer_name) # generate fracture size radius = FractureSize(size_dist, radius_min, radius_max) # insert the circle in the domain my_circle = rs.AddCircle(plane, radius) # write the plane and radius to file for re-plotting file.write("\n" + str(plane[0]) + "," + str(plane[1]) + "," + str(plane[2]) + "," + str(radius)) surf = rs.AddPlanarSrf(my_circle) # delete initial fracture drawn which is a curve rs.DeleteObject(my_circle) # set fracture guid into its object frac.fracture_GUID = surf[0] fracture_list.append(frac) elif fracture_shape == 'ellipse': # initialize list to store fractures fracture_list = [] # write the shape type file.write('\nellipse') for i in range(num_frac): # name the layer layer_name = "FRACTURE_" + str(i + 1) # an instance of fracture object frac = Fracture() # get fracture name frac.fracture_name = layer_name # generate fracture center origin = GeneratePoint(boxlength) # store fracture center frac.fracture_center = origin # plane for fracture plane = InclinePlane(origin, boxlength) # randomly generate radius(rx) radius = FractureSize(size_dist, radius_min, radius_max) # randomly generate aspect ratio aspect_ratio = random.randint(aspect_min, aspect_max) # calculate r_y ry = radius / aspect_ratio # add layer with color rs.AddLayer(layer_name, rs.CreateColor(0, 255, 0)) # make current layer rs.CurrentLayer(layer_name) # draw fracture fracture = rs.AddEllipse(plane, radius, ry) # write the plane, r_x and r_y to file for re-plotting file.write("\n" + str(plane[0]) + "," + str(plane[1]) + "," + str(plane[2]) + "," + str(radius) + "," + str(ry)) # make fracture a surface frac_surf = rs.AddPlanarSrf(fracture) # delete initial fracture drawn which is a curve rs.DeleteObject(fracture) # set fracture guid into its object frac.fracture_GUID = frac_surf[0] # append fracture guid to list fracture_list.append(frac) elif fracture_shape == 'polygon': # initialize list to store fractures fracture_list = [] # write the shape type file.write('\npolygon\n') for i in range(num_frac): # name the layer layer_name = "FRACTURE" + str(i + 1) # an instance of fracture class frac = Fracture() # get farcture name frac.fracture_name = layer_name # randomly determine the sides of the polygon sides = random.randint(polysize_min, polysize_max) # theta in radian theta_rad = (2 * math.pi) / sides # theta in degree (interior angles) theta_deg = theta_rad * (180 / math.pi) # generate origin origin = GeneratePoint(boxlength) # save fracture center frac.fracture_center = origin # randomly generate radius(rx) radius = FractureSize(size_dist, radius_min, radius_max) # create a 3D point object which isn't visible to the rhino document pt_01 = rs.coerce3dvector( [radius + origin[0], origin[1], origin[2]]) # empty list to store all points points = [] # a rotation axis ax = rs.coerce3dvector([0, 0, 1]) # loop to generate points for polygon vertices for j in range(sides): # rotation transform with rotation from the origin trans = rs.XformRotation2(theta_deg * j, ax, origin) # transform the original 3D point and append to list points.append(rs.PointTransform(pt_01, trans)) if j == 0: file.write( str(rs.PointTransform(pt_01, trans)[0]) + "," + str(rs.PointTransform(pt_01, trans)[1]) + "," + str(rs.PointTransform(pt_01, trans)[2]) + ",") if j != 0: file.write( str(rs.PointTransform(pt_01, trans)[0]) + "," + str(rs.PointTransform(pt_01, trans)[1]) + "," + str(rs.PointTransform(pt_01, trans)[2]) + ",") # append the initial point to close the polygon points.append(pt_01) file.write( str(pt_01[0]) + "," + str(pt_01[1]) + "," + str(pt_01[2]) + ",") # create layer for fracture layer_name = "FRACTURE_" + str(i + 1) rs.AddLayer(layer_name, rs.CreateColor(0, 255, 0)) rs.CurrentLayer(layer_name) # get GUID of created polygon polygon = rs.AddPolyline(points) # get the plane plane = InclinePlane(origin, boxlength) # transform the polygon to the plane cob = rs.XformChangeBasis(rs.WorldXYPlane(), plane) shear2d = rs.XformIdentity() shear2d[0, 2] = math.tan(math.radians(45.0)) cob_inverse = rs.XformChangeBasis(plane, rs.WorldXYPlane()) temp = rs.XformMultiply(shear2d, cob) xform = rs.XformMultiply(cob_inverse, temp) fracture = rs.TransformObjects(polygon, xform, False) # write to file #file.write(str(origin[0]) + "," + str(origin[1]) + "," + str(origin[2])+ "," ) file.write( str(plane[0]) + "," + str(plane[1]) + "," + str(plane[2]) + "," + str(sides) + "\n") # make fracture a surface frac_surf = rs.AddPlanarSrf(fracture) # delete initial fracture drawn which is a curve rs.DeleteObject(fracture) # set fracture guid into its objects frac.fracture_GUID = frac_surf[0] # append fracture guid to list fracture_list.append(frac) # close file file.close() return fracture_list