def create_cross_sections(self): crvdomain = rs.CurveDomain(self.curve_object) self.cross_sections = [] self.cross_section_planes = [] t_step = (crvdomain[1] - crvdomain[0]) / self.SAMPLES pi_step_size = math.pi / self.SAMPLES pi_step = 0 prev_normal = None prev_perp = None for t in rs.frange(crvdomain[0], crvdomain[1], t_step): crvcurvature = rs.CurveCurvature(self.curve_object, t) crosssectionplane = None if not crvcurvature: crosssectionplane = self.cross_section_plane_no_curvature( t, prev_normal, prev_perp) else: crosssectionplane = self.cross_section_plane_curvature( crvcurvature, prev_normal, prev_perp) if crosssectionplane: prev_perp = crosssectionplane.XAxis prev_normal = crosssectionplane.YAxis pi_scalar = self.create_scalar(pi_step) radii = self.ellipse_radii(pi_scalar) csec = rs.AddEllipse(crosssectionplane, radii[0], radii[1]) self.cross_sections.append(csec) self.cross_section_planes.append(crosssectionplane) pi_step += pi_step_size
def circleLine(start, end): circles = [] for c in range(start, end, 1): anotherCircle = rs.AddEllipse((c, c, 0), random.uniform(1, 2), random.uniform(1, 2)) circles.append(anotherCircle) rs.AddObjectsToGroup(circles, "lottacircles") print(circles)
def flatWorm(): curveObject = rs.GetObject("pick a backbone curve", 4, True, False) samples = rs.GetInteger("# of crosssections", 100, 5) bend_radius = rs.GetReal("bend radius", 0.5, 0.001) # r1 perp_radius = rs.GetReal("ribbon plan radius", 2.0, 0.001) #r2 crvDom = rs.CurveDomain( curveObject ) # domain != length // why do we use domains? == "The domain is the set of all possible input values to the function that defines the curve or surface." crossSections = [] # empty array to store sections t_step = (crvDom[1] - crvDom[0]) / samples # this is starting to be a pattern! t = crvDom[0] # start pt for loop at the start of the line for t in rs.frange(crvDom[0], crvDom[1], t_step): # loop thru entire domain w/ floats crvCurvature = rs.CurveCurvature( curveObject, t ) # evaluate curve with a circle - gives 3d normals & gives radius info crossSecPlane = None if not crvCurvature: crvPoint = rs.EvaluateCurve(curveObject, t) crvTan = rs.CurveTangent(curveObject, t) # get tangent vector crvPerp = (0, 0, 1) crvNorm = rs.VectorCrossProduct(crvTan, crvPerp) # = product of 2 vectors crossSecPlane = rs.PlaneFromFrame(crvPoint, crvPerp, crvNorm) else: crvPoint = crvCurvature[0] crvTan = crvCurvature[1] crvPerp = rs.VectorUnitize(crvCurvature[4]) crvNorm = rs.VectorCrossProduct(crvTan, crvPerp) # look up crossSecPlane = rs.PlaneFromFrame(crvPoint, crvPerp, crvNorm) if crossSecPlane: csec = rs.AddEllipse( crossSecPlane, bend_radius, perp_radius ) # draw ellipse at tan/normal to point along curve with radii crossSections.append(csec) # add ellipses to an array t += t_step # step through domain rs.AddLoftSrf(crossSections) # loft list of curves rs.DeleteObjects( crossSections) # delete original list of curves as cleanup
def FlatWorm(): curve_object = rs.GetObject("Pick a backbone curve", 4, True, False) if not curve_object: return samples = rs.GetInteger("Number of cross sections", 100, 5) if not samples: return bend_radius = rs.GetReal("Bend plane radius", 0.5, 0.001) if not bend_radius: return perp_radius = rs.GetReal("Ribbon plane radius", 2.0, 0.001) if not perp_radius: return crvdomain = rs.CurveDomain(curve_object) crosssections = [] t_step = (crvdomain[1]-crvdomain[0])/samples t = crvdomain[0] while t<=crvdomain[1]: crvcurvature = rs.CurveCurvature(curve_object, t) crosssectionplane = None if not crvcurvature: crvPoint = rs.EvaluateCurve(curve_object, t) crvTangent = rs.CurveTangent(curve_object, t) crvPerp = (0,0,1) crvNormal = rs.VectorCrossProduct(crvTangent, crvPerp) crosssectionplane = rs.PlaneFromFrame(crvPoint, crvPerp, crvNormal) else: crvPoint = crvcurvature[0] crvTangent = crvcurvature[1] crvPerp = rs.VectorUnitize(crvcurvature[4]) crvNormal = rs.VectorCrossProduct(crvTangent, crvPerp) crosssectionplane = rs.PlaneFromFrame(crvPoint, crvPerp, crvNormal) if crosssectionplane: csec = rs.AddEllipse(crosssectionplane, bend_radius, perp_radius) crosssections.append(csec) t += t_step if not crosssections: return rs.AddLoftSrf(crosssections) rs.DeleteObjects(crosssections)
import rhinoscriptsyntax as rs import random aCircle = rs.AddEllipse((random.uniform(5, 10), 0, 0), 1, 1) def circleLine(start, end): circles = [] for c in range(start, end, 1): anotherCircle = rs.AddEllipse((c, c, 0), random.uniform(1, 2), random.uniform(1, 2)) circles.append(anotherCircle) rs.AddObjectsToGroup(circles, "lottacircles") print(circles) mz = circleLine(9, 14) obj = aCircle # start = (0,0,0) # end = (4,4,0) # if start and end: rs.MirrorObject(obj, (0, 0, 0), (4, 4, 0), True)
import rhinoscriptsyntax as rs import random stretch = 10 centerX = 0 centerY = 0 for circles in range(0, 15, 1): circ = rs.AddEllipse((centerX, centerY, 0), 10, stretch) centerX += 1 stretch += 1
import rhinoscriptsyntax as rs import random import math centerCircle = rs.AddEllipse(rs.WorldXYPlane(), 10, 10.0) points = [] for p in range(10): point = rs.GetPointOnCurve(centerCircle, "Point on curve") rs.AddPoint(point) points.append(point) print(points) def coolCurvy(x, y): curvePoints = [(x, y, 0), (x + 10, y - 5, 0), (x + 20, y + 10, 0), (x + 30, y - 10, 0), (x + 25, y, 0)] return rs.AddCurve(curvePoints, 3) for p in range(len(points)): a = coolCurvy(points[p][0], points[p][1]) if points[p][0] < 0: rs.RotateObject(a, (points[p][0], points[p][1], 0), 180, None, copy=False) #one cool prompt:If the center of a circle is inside the previous circle, make a new circle of random size #overlapping circles will make a nice sticker!
import rhinoscriptsyntax as rs import random # aCircle = rs.AddEllipse((0,0,0),1,1) for c in range(0, 10, 1): rs.AddEllipse((c, c, 0), random.uniform(1, 2), random.uniform(1, 2))
def RedrawNetwork(path): # open text file m = open(path, 'r') # read first line of text file; length of the domain l = m.readline() # convert length to float length = float(l) # read the second line of the domain; shape of the fracture shape = m.readline().split() #corners = ([(0,0,0),(length,0,0),(length,length,0),(0,length,0),(0,0,length),(length,0,length),(length,length,length),(0,length,length)]) #rs.AddBox(corners) # create the domain dom = Domain.Domain(length) # display the domain dom.Show() if shape[0] != 'polygon': # a list to store GUIDs of regenerated fractures frac_list = [] # list to store the x_axis of the fracture plane x_axis = [] # list to store the y_axis of the fracture plane y_axis = [] # list to store the origin of the fracture location origin = [] # list to store the size of fracture size = [] # read file line by line for line in m: # split line by comma words = line.split(",") #if words[0] != 'circle': # append the origin, x_axis and y_axis values in each line origin.append(float(words[0])) origin.append(float(words[1])) origin.append(float(words[2])) x_axis.append(float(words[3])) x_axis.append(float(words[4])) x_axis.append(float(words[5])) y_axis.append(float(words[6])) y_axis.append(float(words[7])) y_axis.append(float(words[8])) size.append(float((words[9]))) # if the shape is ellipse, we have two radii, so append the second radius if shape[0] == 'ellipse': size.append(float((words[10]))) # close file m.close() # display fractures if they are circles/disks if shape[0] == 'circle': n = 0 # go through the lists of origin, x_axis and y_axis # we divide by 3, because the list contains 3 consecutive values # representing a single origin, x_axis or y_axis for i in range(int(len(origin) / 3)): # lists to store the origin, x_axis and y_axis of each fracture o = [] x = [] y = [] # append the origin, x_axis and y_axis of each fracture for j in range(3): o.append(origin[n + j]) x.append(x_axis[n + j]) y.append(y_axis[n + j]) # convert the origin, x_axis and y_axis to a plane plane = rs.PlaneFromFrame(o, x, y) # name the current layer # we are creating layers so that we can trim out of bounds fractures # the function that does this makes use of the layer names layer_name = "FRACTURE_" + str(i + 1) # give the layer a color rs.AddLayer(layer_name, rs.CreateColor(0, 255, 0)) # make layer the current layer rs.CurrentLayer(layer_name) # draw fracture my_disk = rs.AddCircle(plane, size[i]) # convert to a surface surf = rs.AddPlanarSrf(my_disk) #delete initial fracture drawn which is a curve rs.DeleteObject(my_disk) # append fracture frac_list.append(surf) # increment n used for parsing n += 3 # trim out of bounds fractures # the function all creates new fractures at the locations of all # exixting fractures dom.RemoveSurfacesOutsideOfBox(length) # delete all old fractures for frac in frac_list: rs.DeleteObject(frac) dom_frac = dom.my_fractures #get the fractures in the domain #print(dom_frac) #swap old guids with new ones and put new guids in old frac layers #new_frac_guids = Frac.NewFracturesGuids(dom_frac,frac_list) # display fractures if they are ellipse if shape[0] == 'ellipse': # lists to store the origin, x_axis and y_axis of each fracture n = 0 p = 0 q = 1 # go through the lists of origin, x_axis and y_axis # we divide by 3, because the list contains 3 consecutive values # representing a single origin, x_axis or y_axis for i in range(int(len(origin) / 3)): o = [] x = [] y = [] # append the origin, x_axis and y_axis of each fracture for j in range(3): o.append(origin[n + j]) x.append(x_axis[n + j]) y.append(y_axis[n + j]) # convert the origin, x_axis and y_axis to a plane plane = rs.PlaneFromFrame(o, x, y) # name the current layer # we are creating layers so that we can trim out of bounds fractures # the function that does this makes use of the layer names layer_name = "FRACTURE_" + str(i + 1) # give the layer a color rs.AddLayer(layer_name, rs.CreateColor(0, 255, 0)) # make layer current layer rs.CurrentLayer(layer_name) # draw fracture my_frac = rs.AddEllipse(plane, size[i + p], size[i + q]) # convert to a surface from curve surf = rs.AddPlanarSrf(my_frac) # delete initial fracture drawn which is a curve rs.DeleteObject(my_frac) # append fracture frac_list.append(surf) # increment varaiables used for parsing n += 3 p += 1 q += 1 # trim out of bounds fractures dom.RemoveSurfacesOutsideOfBox(length) # delete old fractures for frac in frac_list: rs.DeleteObject(frac) dom_frac = dom.my_fractures if shape[0] == 'polygon': # list to store origin origin = [] # list to store number of sides of each polygon size = [] # list to store number of angle of deviation of each polygon angle = [] # list to store fractures frac_list = [] # list to store points points = [] for line in m: # split each line by comma words = line.split(",") # store the number of sides of the polygon size.append(float(words[-1])) # store the angle of deviation angle.append(float(words[-2])) # stpre the origin origin.extend( (float(words[-5]), float(words[-4]), float(words[-3]))) # length of all points on the line # this will ensure we capture lines with disparate points when # generating polygon of different sides ex = int(3 * (size[-1] + 1)) # store all points on the line points.extend((words[:ex])) # close file m.close() # variables to use for parsing n = 0 m = 0 # iterate for the number of fractures generated for i in range(len(size)): # list to store points and origin o = [] p = [] # get the origin of the fracture for j in range(3): o.append(origin[n + j]) # variable for parsing r = 0 # get the points of fracture edges for k in range(int(size[i]) + 1): p.append([]) for l in range(3): p[k].append(float(points[m + l + r])) # increment r r += 3 # increment parsing variables m += ((int(size[i]) + 1) * 3) n += 3 # name the current layer # we are creating layers so that we can trim out of bounds fractures # the function that does this makes use of the layer names layer_name = "FRACTURE_" + str(i + 1) # give the layer a color rs.AddLayer(layer_name, rs.CreateColor(0, 255, 0)) # make layer the current layer rs.CurrentLayer(layer_name) # joing the points poly = rs.AddPolyline(p) # roatate the fracture frac = rs.RotateObject(poly, o, angle[i], [0, 1, 0]) # convert to a surface surf = rs.AddPlanarSrf(frac) #delete initial fracture drawn which is a curve rs.DeleteObject(frac) frac_list.append(surf) # trim out of bounds fractures # the function all creates new fractures at the locations of all # exixting fractures dom.RemoveSurfacesOutsideOfBox(length) # delete all old fractures for fr in frac_list: rs.DeleteObject(fr) dom_frac = dom.my_fractures return dom_frac
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
import rhinoscriptsyntax as rs import random # firstSquare = rs.AddRectangle((0,0,0),10,10) # secondSquare = rs.AddRectangle((40,50,0),10,20) # firstCircle = rs.AddEllipse((20,10,0),10,10) # secondCircle = rs.AddEllipse((random.uniform(0,15),random.uniform(0,15),0),4,8)
import rhinoscriptsyntax as rs circle = rs.AddEllipse((0, 0, 0), 40, 40) def spirograph(x, y): for squares in range(1, 360, 10): spot = rs.AddRectangle((x, y, 0), 10, 10) rs.RotateObject(spot, (x, y, 0), squares, None, copy=False) spirograph(0, 40) spirograph(-40, 0) spirograph(0, -40) spirograph(40, 0) points = [(0, 0, 0), (5, 5, 0), (5, 10, 0), (0, 15, 0), (-5, 10, 0), (0, 0, 0)] for angle in range(1, 360, 50): shape = rs.AddPolyline(points, replace_id=None) rs.RotateObject(shape, (0, 0, 0), angle, None, copy=True)