def drawBox( side, location, angle_degrees1, angle_degrees2): """画一个2D方块 参数: side(double): 方块的长度, double locaiton(tuple(double, double,double)): 方块中心的位置 angle_degrees1(double): xy平面旋转角度degree1 angle_degrees2(double): 到达位置后继续朝z轴方向旋转角度degree2 Returns: guid """ corners = [] corners.append((-side/2,-side/2,0)) corners.append(( side/2,-side/2,0)) corners.append((side/2,side/2,0)) corners.append((-side/2,side/2,0)) corners.append((-side/2,-side/2,side)) corners.append((side/2,-side/2,side)) corners.append((side/2,side/2,side)) corners.append((-side/2,side/2,side)) obj = rs.AddBox(corners) xform = rs.XformRotation2(angle_degrees1, (0,0,1), (0,0,0)) obj = rs.TransformObject( obj, xform, False ) vectorR1 = rs.VectorRotate( (1,0,0), angle_degrees1, (0,0,0)) vectorR2 = rs.VectorCrossProduct(vectorR1, (0,0,1)) xform = rs.XformRotation2(angle_degrees1, vectorR2, (0,0,0)) obj = rs.TransformObject( obj, xform, False ) xform = rs.XformTranslation( location) obj = rs.TransformObject( obj, xform, False ) return obj
def teardown(cfg): print("teardown") cfg['view'].Close() """ activate_display_mode(cfg['view_restore']['disp_mode'], cfg) cfg['view'].Maximized = cfg['view_restore']['maximized'] cfg['view'].Size = cfg['view_restore']['size'] """ if 'pad_obj_ids' in cfg and cfg['pad_obj_ids']: print("... deleting padding objects") rs.DeleteObjects(cfg['pad_obj_ids']) if 'tmp_obj_ids' in cfg and cfg['tmp_obj_ids']: print("... deleting xformed objects") rs.DeleteObjects(cfg['tmp_obj_ids']) if 'rot_group' in cfg and cfg['rot_group']: print("... rotating objects back to their starting position") rxf = rs.XformRotation2(-cfg['tot_rot'], (0, 0, 1), cfg['rot_group']['bbox'].Center) rs.TransformObjects(cfg['rot_group']['obj_ids'], rxf) show_all_groups(cfg) sc.doc.RenderSettings = cfg['render_settings'] for mode in cfg['display_modes'].keys(): if mode == 'rndr': continue if not Rhino.Display.DisplayModeDescription.DeleteDiplayMode( cfg['display_modes'][mode].Id): print( "Temporary display mode {} was not deleted. Consider removing this yourself." .format(cfg['display_modes'][mode].EnglishName)) delete_residual_display_modes() return
def drawRect( side, location, angle_degrees ): """画一个2D方块 参数: side(double): 方块的长度, double locaiton(tuple(double, double,double)): 方块中心的位置 angle_degrees(double): 旋转角度degree Returns: guid """ p0 = (-side/2,-side/2,0) p1 = (side/2,-side/2,0) p2 = (side/2,side/2,0) p3 = (-side/2,side/2,0) obj = rs.AddPolyline([p0,p1,p2,p3,p0]) xform = rs.XformRotation2(angle_degrees, (0,0,1), (0,0,0)) obj = rs.TransformObject( obj, xform, False ) xform = rs.XformTranslation( location) obj = rs.TransformObject( obj, xform, False ) return obj
def GenerateCrossSection(sectionPoints, radius, rotation, smooth, curve, samples, p, q): points = [] avoidRoundoff = 0.01 for angle in rs.frange(0.0, 360.0 + avoidRoundoff, 360.0 / sectionPoints): points.append(rs.Polar((0.0, 0.0, 0.0), angle, radius)) rotXform = rs.XformRotation2(rotation, (0, 0, 1), (0, 0, 0)) points = rs.PointArrayTransform(points, rotXform) t = curve.Domain[0] crossSections = [] curveCurvature = curve.CurvatureAt(t) crossSectionPlane = None if not curveCurvature: crvPoint = curve.PointAt(t) crvTangent = curve.TangentAt(t) crvPerp = (0, 0, 1) crvNormal = Rhino.Geometry.Vector3d.CrossProduct(crvTangent, crvPerp) crossSectionPlane = Rhino.Geometry.Plane(crvPoint, crvPerp, crvNormal) else: crvPoint = curve.PointAt(t) crvTangent = curve.TangentAt(t) crvPerp = curve.CurvatureAt(t) crvPerp.Unitize crvNormal = Rhino.Geometry.Vector3d.CrossProduct(crvTangent, crvPerp) crossSectionPlane = Rhino.Geometry.Plane(crvPoint, crvPerp, crvNormal) if crossSectionPlane: xform = rs.XformChangeBasis(crossSectionPlane, rs.WorldXYPlane()) sectionVerts = rs.PointArrayTransform(points, xform) if (smooth): # Degree 3 curve to smooth it sectionCurve = Rhino.Geometry.Curve.CreateControlPointCurve( sectionVerts, 3) else: # Degree 1 curve (polyline) sectionCurve = Rhino.Geometry.Curve.CreateControlPointCurve( sectionVerts, 1) crossSection = rs.coercecurve(sectionCurve) return crossSection
def main(): cfg = setup() rs.CurrentView(cfg['view'].ActiveViewportID) # MAIN LOOP msg0 = "{} views at {} zoom levels across {} xforms of {} objects.".format( cfg['view_count'], len(cfg['obj_bbox_pads']), cfg['xform_count'], len(cfg['groups_info'])) msg1 = "{} images will result.".format(cfg['total_image_count']) print(msg0) print(msg1) if rs.MessageBox( "This script will plot {}\n{}\nThe folder {} has been created for this purpose.\nShall we proceed?" .format(msg0, msg1, cfg['pth_save']), 4, "Ready to plot {} images?".format(cfg['total_image_count'])) != 6: teardown(cfg) exit() cfg['tmp_obj_ids'] = False cfg['rot_group'] = False cfg['tot_rot'] = False try: #raise Exception("nope") for g, group_info in enumerate(cfg['groups_info']): print("##### {} ({} of {})".format(group_info['name'].lower(), g + 1, len(cfg['groups_info']))) #print("{} objects in this group".format(len(group_info['obj_ids']))) #set_camera(group_info['bbox'], cfg) isolate_group(g, cfg) deg = 360.0 / cfg['view_count'] rxf = rs.XformRotation2(deg, (0, 0, 1), group_info['bbox'].Center) cfg['rot_group'] = group_info cfg['tot_rot'] = 0 for r in range(cfg['view_count']): for x, xf in enumerate( xforms_to_apply(group_info['bbox'], cfg, DEBUG)): all_layers_on(cfg) cfg['tmp_obj_ids'] = apply_xf( xf, group_info['obj_ids']) # apply this transformation rs.RemoveObjectsFromGroup(cfg['tmp_obj_ids'], group_info['name']) rs.HideGroup(group_info['name']) for p, pad in enumerate(cfg['obj_bbox_pads']): xbbox = bbox_of_objects(cfg['tmp_obj_ids']) set_camera(xbbox, pad, cfg) name = "{}_r{:03}_x{:02}_p{:02}_{}".format( group_info['name'].lower(), r, x, p, cfg['layer_info']['parent'].Name.lower()) is_first = (r == 0 and x == 0) do_capture(name, is_first, cfg) # capture view isolate_group(g, cfg) all_layers_on(cfg) rs.DeleteObjects(cfg['tmp_obj_ids']) cfg['tmp_obj_ids'] = False Rhino.RhinoApp.Wait() if (sc.escape_test(False)): raise Exception('Esc key caught in main()') rs.TransformObjects(group_info['obj_ids'], rxf) cfg['tot_rot'] += deg cfg['rot_group'] = False cfg['tot_rot'] = 0 except Exception as e: print("!!!! SCRIPT STOPPED !!!!") print e exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] print(exc_type, fname, exc_tb.tb_lineno) finally: teardown(cfg)
import math as ma n = 12 a = 4 m = 6 sh = 10 sr = 0.5 curve = rs.GetObject("Select a curve", 4) #Draw ridge curves ridges = [] dphi = 360.0 / n for k in range(0, n): phi = k * dphi xform = rs.XformRotation2(phi, [0, 0, 1], [0, 0, 0]) ridges.append(rs.TransformObject(curve, xform, True)) #Draw cactus body domain = rs.CurveDomain(curve) sections = [] dt = (domain[1] - domain[0]) / 10 for i in range(0, 10): t = domain[0] + i * dt points = [] xyz = rs.EvaluateCurve(curve, t) R = xyz[0] z = xyz[2] dphi = 2 * ma.pi / 100 for k in range(0, 101): phi = k * dphi
def drawEhombusTilingByRegularOffsetLine(emblem): tmpObjs = [] # self.rhomboids for rhomboid in emblem.rhomboids: objs = [] # 中点長方形の対角四角形 for i in range(len(rhomboid.midPts)): p0 = rhomboid.midPts[i] if (i == 0): nextMidPt = rhomboid.midPts[i + 1] prevtMidPt = rhomboid.midPts[len(rhomboid.midPts) - 1] elif (i == len(rhomboid.midPts) - 1): nextMidPt = rhomboid.midPts[0] prevtMidPt = rhomboid.midPts[i - 1] else: nextMidPt = rhomboid.midPts[i + 1] prevtMidPt = rhomboid.midPts[i - 1] p1 = rs.VectorAdd(p0, nextMidPt) p1 = rs.VectorDivide(p1, 2.0) p2 = rhomboid.ellipsePts[0] p3 = rs.VectorAdd(p0, prevtMidPt) p3 = rs.VectorDivide(p3, 2.0) pts = [p0, p1, p2, p3, p0] obj = rs.AddPolyline(pts) if (i % 2 == 0): rs.ObjectLayer(obj, "srf%s" % rhomboid.lines[1].no) else: rs.ObjectLayer(obj, "srf%s" % rhomboid.lines[0].no) objs.append(obj) # 外周面 pts = [] for pt in rhomboid.pts: pts.append(pt) pts.append(pts[0]) obj = rs.AddPolyline(pts) rs.ObjectLayer(obj, "srfRhomboid") objs.append(obj) # 外周線 for i in range(len(rhomboid.pts)): if (i == len(rhomboid.pts) - 1): obj = rs.AddLine(rhomboid.pts[i], rhomboid.pts[0]) else: obj = rs.AddLine(rhomboid.pts[i], rhomboid.pts[i + 1]) rs.ObjectLayer(obj, "lineBlack") objs.append(obj) # rotate xform = rs.XformRotation2(rhomboid.rotateAng, [0, 0, 1], [0, 0, 0]) rs.TransformObjects(objs, xform) # move rs.MoveObjects(objs, rhomboid.movePt) # text txt = "%s" % (rhomboid.name) pt = rhomboid.getAbsolutePt(rhomboid.ellipsePts[0]) height = 1.2 pt = [pt[0], pt[1] + height / 2.0, pt[2]] obj = rs.AddText(txt, pt, height, font, font_style=0, justification=2 + 65536) rs.ObjectLayer(obj, "textRhomboid") objs.append(obj) # tmpObjs for obj in objs: tmpObjs.append(obj) # move to center pts = rs.BoundingBox(tmpObjs) center = rs.VectorAdd(pts[0], pts[2]) center = rs.VectorScale(center, 0.5) center = rs.VectorSubtract([0, 0, 0], center) rs.MoveObjects(tmpObjs, center) return tmpObjs
def drawRhombusOnRegularOffsetLine(emblem): tmpObjs = [] for rhomboid in emblem.rhomboids: objs = [] # 中点長方形の対角四角形 for i in range(len(rhomboid.midPts)): p0 = rhomboid.midPts[i] if (i == 0): nextMidPt = rhomboid.midPts[i + 1] prevtMidPt = rhomboid.midPts[len(rhomboid.midPts) - 1] elif (i == len(rhomboid.midPts) - 1): nextMidPt = rhomboid.midPts[0] prevtMidPt = rhomboid.midPts[i - 1] else: nextMidPt = rhomboid.midPts[i + 1] prevtMidPt = rhomboid.midPts[i - 1] p1 = rs.VectorAdd(p0, nextMidPt) p1 = rs.VectorDivide(p1, 2.0) p2 = rhomboid.ellipsePts[0] p3 = rs.VectorAdd(p0, prevtMidPt) p3 = rs.VectorDivide(p3, 2.0) pts = [p0, p1, p2, p3, p0] obj = rs.AddPolyline(pts) if (i % 2 == 0): rs.ObjectLayer(obj, "srf%s" % rhomboid.lines[1].no) else: rs.ObjectLayer(obj, "srf%s" % rhomboid.lines[0].no) objs.append(obj) # 外周面 pts = [] for pt in rhomboid.pts: pts.append(pt) pts.append(pts[0]) obj = rs.AddPolyline(pts) rs.ObjectLayer(obj, "srfRhomboid") objs.append(obj) # 外周線 for i in range(len(rhomboid.pts)): if (i == len(rhomboid.pts) - 1): obj = rs.AddLine(rhomboid.pts[i], rhomboid.pts[0]) else: obj = rs.AddLine(rhomboid.pts[i], rhomboid.pts[i + 1]) rs.ObjectLayer(obj, "lineBlack") objs.append(obj) # move to center objs = rs.MoveObjects(objs, [ -rhomboid.ellipsePts[0][0], -rhomboid.ellipsePts[0][1], -rhomboid.ellipsePts[0][2] ]) # rotate xform = rs.XformRotation2(rhomboid.rotateAng, [0, 0, 1], [0, 0, 0]) rs.TransformObjects(objs, xform) # move pts = rs.LineLineIntersection( [rhomboid.lines[0].sPt, rhomboid.lines[0].ePt], [rhomboid.lines[1].sPt, rhomboid.lines[1].ePt]) rs.MoveObjects(objs, pts[0]) # tmpObjs for obj in objs: tmpObjs.append(obj) return tmpObjs
def RotateX(centerPoint, angle, pIn): matrix = rs.XformRotation2(angle, [0, 0, 1], centerPoint) return rs.PointTransform(pIn, matrix)
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'
import rhinoscriptsyntax as rs from Rhino.Geometry import Point3d, Vector3d #lines = rs.GetObjects("Select lines", filter=4) lines = rs.AllObjects() for i in range(len(lines)): p = Point3d(i, 0, 0) v = p - rs.CurveStartPoint(lines[i]) rs.TransformObject(lines[i], rs.XformTranslation(v)) a = rs.Angle(rs.CurveStartPoint(lines[i]), rs.CurveEndPoint(lines[i]))[0] rs.TransformObject(lines[i], rs.XformRotation2(90 - a, Vector3d.ZAxis, p)) start = 1 while start < len(lines): current = start while current > 0 and rs.CurveLength(lines[current - 1]) > rs.CurveLength( lines[current]): rs.TransformObject(lines[current], rs.XformTranslation((-1, 0, 0))) rs.TransformObject(lines[current - 1], rs.XformTranslation((1, 0, 0))) lines[current], lines[current - 1] = lines[current - 1], lines[current] current -= 1 rs.Sleep(500) start += 1
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
def yaw(a): global state rotMat = rs.XformRotation2(a / 2, getZ(state), getPos(state)) state = rotMat * state
def pitch(a): global state rotMat = rs.XformRotation2(a / 2, getY(state), getPos(state)) state = rotMat * state
def roll(a): global state rotMat = rs.XformRotation2(a / 2, getX(state), getPos(state)) state = rotMat * state