def blipCurve(y): x1 = random.uniform(0, 10) z1 = random.uniform(0, 10) x2 = random.uniform(10, 20) z2 = random.uniform(10, 100) # this is on purpose this is blip x3 = random.uniform(20, 30) z3 = random.uniform(10, 20) x4 = random.uniform(3, 40) z4 = random.uniform(0, 10) x5 = random.uniform(40, 50) z5 = random.uniform(0, 10) listOfPoints = [(x1, y, z1), (x2, y, z2), (x3, y, z3), (x4, y, z4), (x5, y, z5)] return rs.AddInterpCurve(listOfPoints, 3)
def generate_frame(pt_array): crv_frame = [] for i in xrange(len(pt_array)): pt_list = [] tmp_list = pt_array[i] ### closed, add -1 for j in xrange(len(tmp_list)): pt_list.append(tmp_list[j]) pt_list.append(tmp_list[0]) crv = rs.AddInterpCurve(pt_list) rs.CloseCurve(crv) crv_frame.append(crv) return crv_frame
def draw_coaming(c): pts = [[0, 0, 0]] half = [[(i + 1) * c.spacing, c.points[i], 0] for i in range(len(c.points))] pts.extend(half) pts.append([c.length, 0, 0]) half = [[(i + 1) * c.spacing, -c.points[i], 0] for i in range(len(c.points))] half.reverse() pts.extend(half) pts.append([0, 0, 0]) crv = rs.AddInterpCurve(pts, degree=3, knotstyle=0, start_tangent=[0, 1, 0], end_tangent=[0, 1, 0]) strip = [crv, rs.OffsetCurve(crv, [-1, 0, 0], c.width1)] rs.CopyObjects(strip, [0, c.beam + 2 * c.width1, 0]) strip2 = [rs.CopyObjects(crv), rs.OffsetCurve(crv, [-1, 0, 0], c.width2)] rs.MoveObjects(strip2, [0, -c.beam - c.width1 - c.width2, 0])
def veryBlipCurve(y): x1 = random.uniform(0,10) z1 = random.uniform(0,100) x2 = random.uniform(10,20) z2 = random.uniform(10,1000) #VERY BLIP x3 = random.uniform(20,30) z3 = random.uniform(10,200) x4 = random.uniform(30,40) z4 = random.uniform(0,100) x5 = random.uniform(40,50) z5 = random.uniform(0,100) listOfPoints = [(x1,y,z1),(x2,y,z2),(x3,y,z3),(x4,y,z4), (x5,y,z5)] rs.AddInterpCurve(listOfPoints,3)
def jump(self, force, dis): #make three points that together they can make an Arc, the first point would be heading position) distance = rs.VectorScale(self.direction, dis) startPoint = rs.PointCoordinates(self.point) endpoint = [ startPoint[0] + distance.X, startPoint[1] + distance.Y, startPoint[2] + distance.Z ] midpoint = [ startPoint[0] + distance.X / 2, startPoint[1] + distance.Y / 2, startPoint[2] + distance.Z / 2 ] rotatevec = rs.VectorRotate(self.direction, 90, [0, 0, 1]) heightvec = rs.VectorScale(rotatevec, force) midpoint1 = rs.AddPoint(midpoint) forcepoint = rs.MoveObject(midpoint1, heightvec) # jumppath2=rs.AddCurve([startPoint, forcepoint, endpoint]) dirVec = rs.VectorCreate(endpoint, startpoint) rs.MoveObject(self.point, dirVec) jumppath3 = rs.AddInterpCurve([startPoint, forcepoint, endpoint])
def blipCurve(y, bleepValue): x1 = random.uniform(0, 10) z1 = random.uniform(0, 10) x2 = random.uniform(10, 20) z2 = random.uniform(0, bleepValue) #bleep x3 = random.uniform(20, 30) z3 = random.uniform(10, 20) x4 = random.uniform(30, 40) z4 = random.uniform(0, 10) x5 = random.uniform(40, 50) z5 = random.uniform(0, 10) listOfPoints = [(x1, y, z1), (x2, y, z2), (x3, y, z3), (x4, y, z4), (x5, y, z5)] rs.AddInterpCurve(listOfPoints, 3) ## 1: straight line, 2, 3,
def createcurve(offset, np): #List definition pts = [] #Layer creation rs.AddLayer("PythonCurve", Color.Blue) rs.AddLayer("PythonCosineCurve", Color.Aquamarine) rs.AddLayer("CosineCurve", Color.Red) ##################Geometric Operations################## #rs.CurrentLayer("PythonCurve") rs.CurrentLayer("CosineCurve") for i in range(np): x = i y = 0 + offset - 20 z = cos(i + 1) pts.append([x, y, z]) #rs.addInterpCurve(pts) rs.AddInterpCurve(pts, 3, 0)
def addcurvaturegraphsection(idCrv, t0, t1, samples, scale): if (t1 - t0) <= 0.0: return N = -1 tstep = (t1 - t0) / samples t = t0 points = [] objects = [] while t <= (t1 + (0.5 * tstep)): if t >= t1: t = t1 - 1e-10 N += 1 cData = rs.CurveCurvature(idCrv, t) if not cData: points.append(rs.EvaluateCurve(idCrv, t)) else: c = rs.VectorScale(cData[4], scale) a = cData[0] b = rs.VectorSubtract(a, c) objects.append(rs.AddLine(a, b)) points.append(b) t += tstep objects.append(rs.AddInterpCurve(points)) return objects
def CreateKeyCurve(self, r, z0, d=0, close=False): a = 0.15 - d / r x = r * math.sin(a) y = r * math.cos(a) points = [] # yr = 18.1 yr = self.coreInnerRadius - self.coreSpacerLedgeWidth + 0.4 points.append((-x, -y, z0)) points.append((-1.5, -yr - d, z0)) points.append((-0.8, -yr + 0.3 - d, z0)) points.append((0.8, -yr + 0.3 - d, z0)) points.append((1.5, -yr - d, z0)) points.append((x, -y, z0)) start_tangent = (y / r, -x / r, 0) end_tangent = (y / r, x / r, 0) degree = 3 knotstyle = 0 curve = rs.AddInterpCurve(points, degree, knotstyle, start_tangent, end_tangent) if close: arc = rs.AddArc3Pt((-x, -y, z0), (x, -y, z0), (0, -r, z0)) curve = rs.JoinCurves([curve, arc], True) return curve
def resample_curve(self, le): try: # rs_poly = rs.AddPolyline(self.polyline.points) crv = rs.AddInterpCurve(self.polyline.points) if le <= self.polyline.length: a = rs.DivideCurveLength(crv, le, False) div = rs.DivideCurveLength(crv, le, False, False) new_pts = rs.DivideCurve(crv, len(div), False, True) new_par = rs.DivideCurve(crv, len(div), False, False) else: print('it is a line!') new_pts = [rs.CurveStartPoint(crv), rs.CurveEndPoint(crv)] new_par = [0.0, rs.CurveLength(crv)] out_pts = [] out_vec = [] for idx, pt in enumerate(new_pts): pt = [pt.X, pt.Y, pt.Z] v = rs.CurveTangent(crv, new_par[idx]) vec = [v.X, v.Y, v.Z] # vec = compas.geometry.normalize_vector(vec) out_pts.append(pt) out_vec.append(vec) # print('succesfully resampled') return out_pts, out_vec except Exception: print('Interpolated Curve could not be resampled.') return None, None
# Random numbers part II to generate lines import rhinoscriptsyntax as rs import random pts = [] for i in range(0, 100): x = random.uniform(0, 100) y = random.uniform(0, 100) z = random.uniform(0, 100) pt = [x, y, z] pts.append(pt) pl = rs.AddPolyline(pts) crv = rs.AddCurve(pts) intCrv = rs.AddInterpCurve(pts) color01 = [0, 255, 255] color02 = [255, 0, 255] color03 = [255, 255, 0] rs.ObjectColor(pl, color01) rs.ObjectColor(crv, color02) rs.ObjectColor(intCrv, color03) rs.AddBox([[0, 0, 0], [100, 0, 0], [100, 100, 0], [0, 100, 0], [0, 0, 100], [100, 0, 100], [100, 100, 100], [0, 100, 100]])
#Python Workshop Lesson:04 #http://designalyze.com/int2pythonscripting04_listscurvetypes #Lists of Points + Curve Types #Bonus simple for loop import rhinoscriptsyntax as rs listPoints = [] listPoints = rs.GetPoints(True, True, "Pick a starting point", "Keep picking points until you get tired") #Curve Types myPolyline = rs.AddPolyline(listPoints) myCurve = rs.AddCurve(listPoints) myIntpCurve = rs.AddInterpCurve(listPoints) #Curve Colors #Colors are Arrays of [r,g,b] color01 = [0, 255, 255] #cyan color02 = [255, 0, 255] #magenta color03 = [255, 255, 0] #yellow #Change Color of Curves rs.ObjectColor(myPolyline, color01) rs.ObjectColor(myCurve, color02) rs.ObjectColor(myIntpCurve, color03) #Bonus For Loop for point in listPoints: rs.AddPoint(point)
z2 = random.randint(0,50) x3 = random.randint(0,50) y3 = random.randint(0,50) z3 = random.randint(0,50) x4 = random.randint(0,50) y4 = random.randint(0,50) z4 = random.randint(0,50) p1 = rs.AddPoint(x1,y1,0) p2 = rs.AddPoint(x2,0,z2) p3 = rs.AddPoint(0,y3,z3) p4 = rs.AddPoint(x4,y4,50) p5 = rs.AddPoint(x4,50,z4) p6 = rs.AddPoint(50,y4,z4) A = rs.AddInterpCurve([a,p3,b],3,0,None,None) B = rs.AddInterpCurve([b,p4,c],3,0,None,None) C = rs.AddInterpCurve([c,p6,d],3,0,None,None) D = rs.AddInterpCurve([d,p1,a],3,0,None,None) rs.ReverseCurve(B) rs.ReverseCurve(D) rs.AddLoftSrf([A,B],None,None,0,0,0,False) rs.AddLoftSrf([C,B],None,None,0,0,0,False) rs.AddLoftSrf([C,D],None,None,0,0,0,False) rs.AddLoftSrf([A,D],None,None,0,0,0,False)
moverList = [] for i in range(10): moverList.append(Mover()) # a = Attractor() # THE BELOW FUNCTION SIMULATES THE DRAW LOOP IN PROCESSING for x in rs.frange(0, 15000, 1): for n1 in range(len(moverList)): for n2 in range(len(moverList)): if n1 != n2: attraction = moverList[n2].attract(moverList[n1]) # a.update() # print attraction # print m.vecAcceleration moverList[n1].applyForce(attraction) # moverList[n].applyForce([0,.1,.1]) moverList[n1].update() moverList[n1].display() # rs.AddPoint(m.location) # print m.location[0] # print m.listPoints for p in range(len(moverList)): rs.AddInterpCurve(moverList[p].listPoints) # rs.AddPoint(m.listPoints)
c = 0 while c < 100: v1 = random.uniform(-100,100) v2 = random.uniform(-100,100) v3 = random.uniform(-100,100) v4 = random.uniform(-100,100) v5 = random.uniform(-100,100) v6 = random.uniform(-100,100) v7 = random.uniform(-100,100) v8 = random.uniform(-100,100) v9 = random.uniform(-100,100) myPointA = [v1,v2,v3] myPointB = [v4,v5,v6] myPointC = [v7,v8,v9] rs.AddInterpCurve([myPointA,myPointB,myPointC], 3) c += 1 #the code below accomplishes the same task without the use of a counting variable for c in range(100): v1 = random.uniform(-100,100) v2 = random.uniform(-100,100) v3 = random.uniform(-100,100) v4 = random.uniform(-100,100) v5 = random.uniform(-100,100) v6 = random.uniform(-100,100) v7 = random.uniform(-100,100) v8 = random.uniform(-100,100) v9 = random.uniform(-100,100)
rad1 = 0.15 #radius for the downward structure rad2 = rad1 * 2 #radius fore the frame gpts_list1 = [] # list of new points for crv 1 gpts_list2 = [] # list of new points for crv 2 #makes the line between points for i in range(len(pts_crv1)): nz1 = pts_crv1[i][2] - gravity #n = new # z = coordinate nx1 = pts_crv1[i][0] # x = coordinate ny1 = pts_crv1[i][1] # y = coordinate npts_crv1 = (nx1, ny1, nz1) gpts_list1.append(npts_crv1) gline1 = rs.AddLine(pts_crv1[i], npts_crv1) #gravity line pipe_crv1 = rs.AddPipe(gline1, 0, rad1) nz2 = pts_crv2[i][2] - gravity #n = new # z = coordinate nx2 = pts_crv2[i][0] # x = coordinate ny2 = pts_crv2[i][1] # y = coordinate npts_crv2 = (nx2, ny2, nz2) gpts_list2.append(npts_crv2) gline2 = rs.AddLine(pts_crv2[i], npts_crv2) #gravity line pipe_crv2 = rs.AddPipe(gline2, 0, rad1) gcrv1 = rs.AddInterpCurve(gpts_list1) gcrv2 = rs.AddInterpCurve(gpts_list2) rs.AddPipe(gcrv1, 0, rad2) rs.AddPipe(gcrv2, 0, rad2)
def blipCurve(y): x1 = random.uniform(0, 10) z1 = random.uniform(0, 10) x2 = random.uniform(10, 20) z2 = random.uniform(10, 100) # this is on purpose this is blip x3 = random.uniform(20, 30) z3 = random.uniform(10, 20) x4 = random.uniform(3, 40) z4 = random.uniform(0, 10) x5 = random.uniform(40, 50) z5 = random.uniform(0, 10) listOfPoints = [(x1, y, z1), (x2, y, z2), (x3, y, z3), (x4, y, z4), (x5, y, z5)] return rs.AddInterpCurve(listOfPoints, 3) for c in range(1000): aCurve = blipCurve(c) #at this special moment if c == 700: points = rs.DivideCurve(aCurve, 100) randomIndex = random.randint(0, 99) points[randomIndex][2] = random.uniform(-500, -300) rs.AddInterpCurve(points) rs.DeleteObject(aCurve)
def LEAF(startX, startY, width, left): if (left == True): rotationAngle = random.uniform(40, 140) elif (left == False): rotationAngle = random.uniform(200, 300) halfLeaf = rs.AddArc3Pt((startX, startY, 0), (startX, startY + 12, 0), (startX + width, startY + 4, 0)) secondHalf = rs.MirrorObject(halfLeaf, (startX, startY, 0), (startX, startY + 12, 0), copy=True) rs.RotateObject(halfLeaf, (startX, startY, 0), rotationAngle, axis=None, copy=False) rs.RotateObject(secondHalf, (startX, startY, 0), rotationAngle, axis=None, copy=False) veinPoints = [(startX, startY, 0)] widthFixer = 2.2 for points in range(1, 12, 2): veinPoint = (startX + random.uniform(-1, 1), startY + points, 0) veinPoints.append(veinPoint) # rs.AddPoint(veinPoint) if (points < 7): points = (startX - width + widthFixer, startY + points + random.uniform(-.5, .5), 0), veinPoint, (startX + width - widthFixer, startY + points + random.uniform(-.5, .5), 0) vein = rs.AddCurve(points) rs.RotateObject(vein, (startX, startY, 0), rotationAngle, axis=None, copy=False) widthFixer = widthFixer - 1 # print(widthFixer) elif (points == 7): widthFixer = .2 points = (startX - width + widthFixer, startY + points + random.uniform(-.5, .5), 0), veinPoint, (startX + width - widthFixer, startY + points + random.uniform(-.5, .5), 0) vein = rs.AddCurve(points) rs.RotateObject(vein, (startX, startY, 0), rotationAngle, axis=None, copy=False) elif (points > 7): widthFixer = widthFixer + 1 points = (startX - width + widthFixer, startY + points + random.uniform(-.5, .5), 0), veinPoint, (startX + width - widthFixer, startY + points + random.uniform(-.5, .5), 0) vein = rs.AddCurve(points) rs.RotateObject(vein, (startX, startY, 0), rotationAngle, axis=None, copy=False) # print(widthFixer) middleVein = rs.AddInterpCurve(veinPoints) rs.RotateObject(middleVein, (startX, startY, 0), rotationAngle, axis=None, copy=False)
elevation = rs.GetReal("what's the elevation angle?") # ask for an elevation angle, just like up top azimuth = rs.GetReal("what's the azimuth angle?") # ask for an azimuth angle azimuth *= -1 # flip the azimuth - because by default, rhino rotates things CCW, and compasses go CW # rotate that first point to the elevation angle # rotate works like this: RotateObject( object_to_rotate, center_point, angle_to_rotate, rotation_axis, copy_yes/no ) rs.RotateObject(starterPt, [0,0,0], elevation, axis=[1,0,0], copy=True) rs.RotateObject(rs.FirstObject(), [0,0,0], azimuth, axis=[0,0,1], copy=False) # do the same thing for the azimuth listOfPoints.append(rs.FirstObject()) # once we have the final location, add that point to our listOfPoints list rs.CurrentLayer("sun rays") # switch to the sun rays layer sunRay = rs.AddLine([0,0,0],rs.FirstObject()) # on that layer, draw a line for the ray rs.CurrentLayer(dayName) # switch back to the current day (for the next loop) #this is the end of the "for loop" - note how the next "if" statement isn't indented as much if(listOfPoints): # check whether listOfPoints has anything in it sunpath = rs.AddInterpCurve(listOfPoints) # add an interpolated curve (one that goes THROUGH the points) newsunpath = rs.PullCurve(sunSphere, sunpath, False) # pull that curve to the sphere rs.ObjectName(newsunpath, dayName) # name it using the 'dayName' variable from earlier - fyi, object names show up if you type 'properties' in rhino rs.DeleteObject(sunpath) # delete the old (non-pulled) curve crvstojoin = rs.ObjectsByName(dayName, True) # sometimes pulling breaks up a curve, so we have to gather all those pieces if (len(crvstojoin) > 1): # if, in fact, there are multiple curves crvstojoin = rs.JoinCurves(crvstojoin, True) # join them rs.ObjectName(crvstojoin, dayName) # for some reason joining things kills their names - so if you want, rename the final curve rs.DeleteObject(starterPt) # finally, delete that original point that we copied and rotated around rs.DeleteObject(sunSphere) # and delete the sphere. else: # if we didn't successfully get points or radius print "please enter positive values!" # explain why nothing happened
x1 = random.randint(0, 50) y1 = random.randint(0, 50) z1 = random.randint(0, 50) x2 = random.randint(0, 50) y2 = random.randint(0, 50) z2 = random.randint(0, 50) x3 = random.randint(0, 50) y3 = random.randint(0, 50) z3 = random.randint(0, 50) x4 = random.randint(0, 50) y4 = random.randint(0, 50) z4 = random.randint(0, 50) p1 = rs.AddPoint(x1, y1, z1) p2 = rs.AddPoint(x2, y2, z2) p3 = rs.AddPoint(x3, y3, z3) p4 = rs.AddPoint(x4, y4, z4) A = rs.AddInterpCurve([a, p1, b], 3, 0, None, None) B = rs.AddInterpCurve([c, p2, d], 3, 0, None, None) C = rs.AddInterpCurve([e, p3, f], 3, 0, None, None) D = rs.AddInterpCurve([g, p4, h], 3, 0, None, None) m = 20 A1 = rs.DivideCurve(A, m, True, True) B1 = rs.DivideCurve(B, m, True, True) C1 = rs.DivideCurve(C, m, True, True) D1 = rs.DivideCurve(D, m, True, True) rs.AddLoftSrf([A, B], None, None, 0, 0, 0, False) for i in range(m): rs.AddLine(A1[i], B1[i]) rs.AddLine(B1[i], C1[i])
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 x = (R + a * (ma.cos(n * phi) - 1)) * ma.cos(phi) y = (R + a * (ma.cos(n * phi) - 1)) * ma.sin(phi) points.append([x, y, z]) sections.append(rs.AddInterpCurve(points)) top = rs.EvaluateCurve(curve, domain[1]) plane = rs.PlaneFromNormal(top, [0, 0, 1]) sections.append(rs.AddCircle(plane, 1)) rs.AddLayer("Cactus") rs.CurrentLayer("Cactus") surf = rs.AddLoftSrf(sections) rs.CapPlanarHoles(surf) #Draw spines cone = rs.AddCone([0, 0, -sh], sh, sr) basis = [] theta = ma.pi / 8 dphi = 2 * ma.pi / m for k in range(0, m):
else: layerName = "far" farCount += 1 projector = rs.AddLine(point, eyePoint) rs.ObjectLayer(projector, layerName) intersections = rs.CurveSurfaceIntersection(projector, picturePlane) if intersections: intersectionPoint = intersections[0][1] pointObjectInSpace = rs.AddPoint(point) rs.ObjectLayer(pointObjectInSpace, layerName) intersectionPoints.append(intersectionPoint) pointObs = rs.AddPoints(intersectionPoints) reconstructedCurve = rs.AddInterpCurve( intersectionPoints, 1) #what would be a more precise way to reconstruct the curve? if closeCount > middleCount and closeCount > farCount: rs.ObjectLayer(reconstructedCurve, "close") elif middleCount > farCount: rs.ObjectLayer(reconstructedCurve, "middle") else: rs.ObjectLayer(reconstructedCurve, "far") #add layer management to sep process content from finish content, and to use close/far distinction
#measure distance on 2D grid to nearby points for l in range(len(edgePts)): ptPos = gt001.myPos(edgePts[l][0], edgePts[l][1], landscape) ptPos[2] = 0 dist = rs.Distance(lastPtPos, ptPos) nowCell = edgePts[l] if dist < 25: if nowCell not in newLine: otherPossible.append([edgePts[l], dist]) if len(otherPossible) > 0: #sort options by distance sortedList = sorted(otherPossible, key=lambda k: k[1]) nowCell = sortedList[0][0] #reset i,j i = nowCell[0] j = nowCell[1] newLine.append(nowCell) check = True chains.append(newLine) #attempt to draw lines for i in range(len(chains)): #convert indices to points ptList = [] for j in range(len(chains[i])): pt = gt001.myPos(chains[i][j][0], chains[i][j][1], landscape) ptList.append(pt) rs.AddInterpCurve(ptList) rs.EnableRedraw(True)
# Random Numbers # Random Lines import rhinoscriptsyntax as rs import random pts = [] for i in range(0, 100): x = random.uniform(0, 100) y = random.uniform(0, 100) z = random.uniform(0, 100) pt = [x, y, z] pts.append(pt) pl = rs.AddPolyline(pts) crv = rs.AddCurve(pts) intpcrv = rs.AddInterpCurve(pts) color01 = [0, 255, 255] color02 = [255, 0, 255] color03 = [255, 255, 0] rs.ObjectColor(pl, color01) rs.ObjectColor(crv, color02) rs.ObjectColor(intpcrv, color03)
def draw_graph(vertices, edges, loop_size=1.0, spindle_size=1.0, node_radius=0.0, line_radius=0.0, key_to_colour={}): """Draw a graph in Rhino as grouped points and lines with optional element size and node colouring. Loops for edges (u, u) and parallel edges for multiple edges (u, v) and/or (v, u) are allowed. Parameters ---------- vertices : dict A dictionary of vertex keys pointing to point coordinates. edges : list A list of tuples of pairs of vertex indices. loop_size : float, optional Rough size of the loops due to edges (u, u). Default value is 1.0. spindle_size : float, optional Rough size of the spindles due to mutiple edges (u, v) and/or (v, u). Default value is 1.0. node_radius : float, optional Node radius representing the vertices. If equal to 0.0, a point is added, else a sphere. Default value is 1.0. line_radius : float, optional Line radius representing the edges. If equal to 0.0, a line is added, else a pipe. Default value is 1.0. key_to_colour : dict, optional An optional dictonary with vertex keys pointing to RGB colours. Returns ------- group : Rhino group A Rhino group with the list of points or sphere surfaces of the vertices, and the list of the list of curves or pipe surfaces of the edges. """ # nodes as points or spheres with optional colours nodes = [] for key, xyz in vertices.items(): nodes.append(rs.AddPoint(xyz) if node_radius == 0.0 else rs.AddSphere(xyz, node_radius)) if key in key_to_colour: rs.ObjectColor(nodes[-1], key_to_colour[key]) # curves curves = [] while len(edges) > 0: crvs = [] u0, v0 = edges.pop() # count occurences in case of multiple parallel edges n = 1 for u, v in edges: if (u == u0 and v == v0) or (u == v0 and v == u0): edges.remove((u, v)) n += 1 # if not loop edge if u0 != v0: start = vertices[u0] end = vertices[v0] # rough spindle of parallel edges based on third offset point mid = midpoint_line([start, end]) direction = cross_vectors(normalize_vector(subtract_vectors(end, start)), [0.0, 0.0, 1.0]) for i in range(n): k = (float(i) / float(n) * spindle_size) - spindle_size / 2.0 * (float(n) - 1.0) / float(n) dir_mid = add_vectors(mid, scale_vector(direction, k)) crvs.append(rs.AddInterpCurve([start, dir_mid, end], degree=3)) # if loop edge else: xyz0 = vertices[u0] x0, y0, z0 = xyz0 # rough loop based on three additional points xyz1 = [x0 + loop_size / 2.0, y0 - loop_size / 2.0, z0] xyz2 = [x0 + loop_size, y0, z0] xyz3 = [x0 + loop_size / 2.0, y0 + loop_size / 2.0, z0] crvs += [rs.AddInterpCurve([xyz0, xyz1, xyz2, xyz3, xyz0], degree=3) for i in range(n)] # spread if multiple loops for i, crv in enumerate(crvs): rs.RotateObject(crv, [x0, y0, z0], 360 * float(i) / float(n)) # pipe if non-null radius is specified if line_radius != 0.0: pipes = [rs.AddPipe(crv, 0, line_radius) for crv in crvs] rs.DeleteObjects(crvs) crvs = pipes curves += crvs # output group group = rs.AddGroup() rs.AddObjectsToGroup(nodes + curves, group) return group
list1 = coordinates(first_wire) list2 = coordinates(second_wire) coordinates1_list = [] for (x, y) in list1: coordinates1 = (x, y, 0) rs.AddPoint(coordinates1) coordinates1_list.append(coordinates1) coordinates2_list = [] for (x, y) in list2: coordinates2 = (x, y, 0) rs.AddPoint(coordinates2) coordinates2_list.append(coordinates2) curve1 = rs.AddInterpCurve(coordinates1_list) curve2 = rs.AddInterpCurve(coordinates2_list) intersection_list = rs.CurveCurveIntersection(curve1, curve2) #print(intersection_list) points_intersection_list = [] for intersection in intersection_list: if intersection[0] == 1: print "Intersection point on first curve: ", intersection[1] points_intersection_list.append(intersection[1]) #print(points_intersection_list) distances = [] for point in points_intersection_list: distances.append(rs.Distance((0, 0, 0), point)) print(distances) distanceAndPointsPaired = zip(distances, points_intersection_list) distanceAndPointsPaired.sort()
import rhinoscriptsyntax as rs import random import math point1 = [0, 0, 0] point2 = [5, 10, 0] point3 = [10, 10, 0] curvePoints = [point1, point2, point3] rs.AddInterpCurve(curvePoints, 3) point1 = [0, 0, 0] point2 = [10, 5, 0] point3 = [10, 10, 0] curvePoints = [point1, point2, point3] rs.AddInterpCurve(curvePoints, 5)
for i in range(0, 9): fPoints.append([]) bPoints.append([]) for j in range(0, 20): fPoints[i].append(rs.AddPoint(x[i][j], yface[i][j], 0)) bPoints[i].append(rs.AddPoint(x[i][j], yback[i][j], 0)) #Creating curves from Points fCurves = [] bCurves = [] cylCurves = [] cylsrf = [] _ax = rs.AddLine((-D, 0, 0), (D, 0, 0)) for i in range(0, 9): fCurves.append(rs.AddInterpCurve(fPoints[i], 3)) fCurves[i] = rs.RotateObject(fCurves[i], cPoint, 90) fCurves[i] = rs.MoveObject(fCurves[i], (0, dab[i], zr[i])) fCurves[i] = rs.RotateObject(fCurves[i], cPoint, rangle[i]) bCurves.append(rs.AddInterpCurve(bPoints[i], 3)) bCurves[i] = rs.RotateObject(bCurves[i], cPoint, 90) bCurves[i] = rs.MoveObject(bCurves[i], (0, dab[i], zr[i])) bCurves[i] = rs.RotateObject(bCurves[i], cPoint, rangle[i]) cylCurves.append(rs.AddLine((-D, 0, zr[i]), (D, 0, zr[i]))) cylsrf.append(rs.AddRevSrf(cylCurves[i], _ax, -90, 90)) #Projection of the curve surface pfCurves = [] pbCurves = []
def generate_gear_crv(teeth, module, pressure_angle=20, cone_angle=0, clearance=0.167, involute_samples=5): pressure_angle = radians(pressure_angle) pitch_diam = module * teeth base_circle = pitch_diam * cos(pressure_angle) addendum = module dedendum = (1 + clearance) * module outside_diam = pitch_diam + 2 * addendum root_diam = pitch_diam - 2 * dedendum chordal_thickness = pitch_diam * sin((pi / 2) / teeth) # Partial function to transform point from xy plane to surface # perpendicular to pitch cone surface. Used for bevel gears. tilt = partial(tilt_pt_around_circle, angle=cone_angle / 2, circle_diam=pitch_diam) invol_start_angle = (pi / 2 + asin(chordal_thickness / pitch_diam) - pressure_angle + sqrt((pitch_diam / base_circle)**2 - 1)) invol_end_angle = (invol_start_angle - sqrt((outside_diam / base_circle)**2 - 1)) if root_diam > base_circle: invol_angle_mod = sqrt((root_diam / base_circle)**2 - 1) else: invol_angle_mod = 0 invol_pts = generate_involute_pts(base_circle_diam=base_circle, start_angle=invol_start_angle, end_angle=invol_end_angle, angle_mod=invol_angle_mod, samples=involute_samples) invol_pts = map(tilt, invol_pts) tooth_crvs = [] invol_crv1 = rs.AddInterpCurve(invol_pts, degree=3, knotstyle=1) invol_crv2 = rs.MirrorObject(invol_crv1, [0, 0, 0], [0, 1, 0], copy=True) top_arc = rs.AddArc3Pt(start=rs.CurveEndPoint(invol_crv1), end=rs.CurveEndPoint(invol_crv2), point_on_arc=tilt([0, outside_diam / 2, 0])) tooth_crvs.append(invol_crv1) tooth_crvs.append(invol_crv2) tooth_crvs.append(top_arc) # Dedendum if root_diam < base_circle: pt = [ root_diam / 2 * cos(invol_start_angle), root_diam / 2 * sin(invol_start_angle), 0 ] ded_crv1 = rs.AddLine(rs.CurveStartPoint(invol_crv1), tilt(pt)) ded_crv2 = rs.MirrorObject(ded_crv1, [0, 0, 0], [0, 1, 0], copy=True) tooth_crvs.append(ded_crv1) tooth_crvs.append(ded_crv2) tooth = rs.JoinCurves(tooth_crvs, delete_input=True)[0] # Tooth bottom angle = 2 * pi / teeth start_pt = rs.CurveStartPoint(tooth) end_pt = rs.CurveEndPoint(tooth) end_pt = [ end_pt[0] * cos(angle) - end_pt[1] * sin(angle), end_pt[1] * cos(angle) + end_pt[0] * sin(angle), end_pt[2] ] pt_on_arc = [ -sin(angle / 2) * (root_diam / 2), cos(angle / 2) * (root_diam / 2), 0 ] bottom_arc = rs.AddArc3Pt(start_pt, end_pt, tilt(pt_on_arc)) tooth = rs.JoinCurves([tooth, bottom_arc], delete_input=True)[0] # Copy and rotate tooth N times crvs = [tooth] for i in xrange(1, teeth): crv = rs.RotateObject(tooth, [0, 0, 0], degrees(i * angle), copy=True) crvs.append(crv) crvs = rs.JoinCurves(crvs, delete_input=True) return crvs
import rhinoscriptsyntax as rhino import math x = float(0.0) y = float(1.0) z = float(0.0) dt = float(0.0001) t = float(0.0) iterations = 1000000 points = [] num_points = 1000 for i in range(iterations): dx = float(10*(y-x)) * dt dy = float(28*x - y - x * z) * dt dz = float(x*y - float(8/3)*z) * dt # dt = dt * 0.9 if i % (iterations / num_points) == 0: points.append([x, y, z]) x = x + dx y = y + dy z = z + dz t = t + dt for p in points: rhino.AddPoint(p) rhino.AddInterpCurve(points)