def Moveobj(self, y_c_i): m_p = rs.CircleCenterPoint(self.circle_obj) y_p = rs.CircleCenterPoint(y_c_i.circle_obj) vector_m_y = rs.VectorCreate(y_p, m_p) vector_y_m = rs.VectorCreate(m_p, y_p) unit_vec_m_y = rs.VectorUnitize(vector_m_y) unit_vec_y_m = rs.VectorUnitize(vector_y_m) radius_1 = rs.CircleRadius(self.circle_obj) radius_2 = rs.CircleRadius(y_c_i.circle_obj) dis_1_2 = rs.Distance(m_p, y_p) dis = dis_1_2 - (radius_1 + radius_2) move_dis = (dis / 2) / 10 move_vec_m_y = rs.VectorScale(unit_vec_m_y, move_dis) move_vec_y_m = rs.VectorScale(unit_vec_y_m, move_dis) # status = self.getStatus(y_c_i) # # if(status == 1): # rs.MoveObject(self.circle_obj,move_vec_m_y) # rs.MoveObject(y_c_i.circle_obj,move_vec_y_m) # # if(status == 2): # rs.MoveObject(self.circle_obj,move_vec_y_m) # rs.MoveObject(y_c_i.circle_obj,move_vec_m_y) rs.MoveObject(self.circle_obj, move_vec_m_y) rs.MoveObject(y_c_i.circle_obj, move_vec_y_m)
def create_jig(self, list): jigs = [] for i in range(0, len(list), 2): domain = rs.CurveDomain(list[i]) start_point = rs.EvaluateCurve(list[i], domain[0]) end_point = rs.EvaluateCurve(list[i], domain[1]) start_plane = rs.PlaneFromNormal( start_point, rs.VectorUnitize(end_point - start_point)) end_plane = rs.PlaneFromNormal( end_point, rs.VectorUnitize(start_point - end_point)) start_curve_point = self.closest_intersection( rs.PlaneCurveIntersection(start_plane, self.curve_object), start_point) end_curve_point = self.closest_intersection( rs.PlaneCurveIntersection(end_plane, self.curve_object), end_point) start_vector = rs.VectorUnitize( rs.VectorCreate(start_point, start_curve_point)) end_vector = rs.VectorUnitize( rs.VectorCreate(end_point, end_curve_point)) start_vector_scale = rs.VectorScale(start_vector, -5) end_vector_scale = rs.VectorScale(end_vector, -5) start_square = self.create_square( rs.PointAdd(start_point, start_vector_scale), rs.PointAdd(end_point, end_vector_scale), start_vector) end_square = self.create_square( rs.PointAdd(end_point, end_vector_scale), rs.PointAdd(start_point, start_vector_scale), end_vector) jigs.append(self.create_jig_section(start_square, end_square)) return jigs
def drawQuadTab(self, island): pntA, pntD = self.get_coordinates(island) vecA = geom.Vector3d(pntA) vecD = geom.Vector3d(pntD) alpha = self.tabAngles[0] beta = self.tabAngles[1] lenI = self.tabWidth / math.sin(alpha * math.pi / 180.0) lenJ = self.tabWidth / math.sin(beta * math.pi / 180.0) if not self.tabOnLeft: alpha = -1 * alpha beta = -1 * beta vec = vecD.Subtract(vecD, vecA) vecUnit = rs.VectorUnitize(vec) vecI = rs.VectorScale(vecUnit, lenI) vecJ = rs.VectorScale(vecUnit, -lenJ) vecI = rs.VectorRotate(vecI, alpha, [0, 0, 1]) vecJ = rs.VectorRotate(vecJ, -beta, [0, 0, 1]) vecB = vecA + vecI vecC = vecD + vecJ pntB = geom.Point3d(vecB) pntC = geom.Point3d(vecC) points = [pntA, pntB, pntC, pntD] polyGuid = rs.AddPolyline(points) self.geom.append(polyGuid) return polyGuid
def blendcorners(): polyline_id = rs.GetObject("Polyline to blend", 4, True, True) if not polyline_id: return vertices = rs.PolylineVertices(polyline_id) if not vertices: return radius = rs.GetReal("Blend radius", 1.0, 0.0) if radius is None: return between = lambda a, b: (a + b) / 2.0 newverts = [] for i in range(len(vertices) - 1): a = vertices[i] b = vertices[i + 1] segmentlength = rs.Distance(a, b) vec_segment = rs.PointSubtract(b, a) vec_segment = rs.VectorUnitize(vec_segment) if radius < (0.5 * segmentlength): vec_segment = rs.VectorScale(vec_segment, radius) else: vec_segment = rs.VectorScale(vec_segment, 0.5 * segmentlength) w1 = rs.PointAdd(a, vec_segment) w2 = rs.PointSubtract(b, vec_segment) newverts.append(a) newverts.append(between(a, w1)) newverts.append(w1) newverts.append(between(w1, w2)) newverts.append(w2) newverts.append(between(w2, b)) newverts.append(vertices[len(vertices) - 1]) rs.AddCurve(newverts, 5) rs.DeleteObject(polyline_id)
def move2PtInside(self, p0, p1, scale0=0.2, scale1=None): if scale1 is None: scale1 = scale0 mp = [ (p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2, (p0[2] + p1[2]) / 2, ] v0 = rs.VectorCreate(mp, p0) v1 = rs.VectorCreate(mp, p1) v0 = rs.VectorScale(rs.VectorUnitize(v0), scale0) v1 = rs.VectorScale(rs.VectorUnitize(v1), scale1) v0 = rs.PointAdd(p0, v0) v1 = rs.PointAdd(p1, v1) return v0, v1 #eof #eoc
def get_edge_vectors(s_brep,length): """gets the direction vectors for extending the edges of the one-surface brep""" edges = s_brep.Edges normal = s_brep.Faces[0].NormalAt(0.5,0.5) midpoints = [] for edge in edges: mp = edge.Domain.Mid midpoints.append(edge.PointAt(mp)) edge_vectors = [] for i, edge in enumerate(edges): #get directions to test moving midpoint start = edge.StartVertex.Location end = edge.EndVertex.Location v = rs.VectorCreate(end,start) xprod1 = Rhino.Geometry.Vector3d.CrossProduct(normal,v) xprod1 = rs.VectorUnitize(xprod1) xprod2 = rs.VectorReverse(xprod1) p1 = edge.PointAt(edge.Domain.Mid) + xprod1 p2 = edge.PointAt(edge.Domain.Mid) + xprod2 print "p1", p1 print "p2", p2 dist1 = distance_to_brep(s_brep,p1) dist2 = distance_to_brep(s_brep,p2) print "dist1", dist1 print "dist2", dist2 if dist1 > dist2: edge_vectors.append(rs.VectorScale(xprod1,length)) else: edge_vectors.append(rs.VectorScale(xprod2,length)) return edge_vectors
def update(self): self.posP = self.pos # call the behaviors velboids1 = self.AlignmentVector() velboids2 = self.SeparationVector() velboids3 = self.CohesionVector() velav = self.avoid() veltrail = self.trail(4) # scale the behaviors velboids1 = rs.VectorScale(velboids1, 0.1) velboids2 = rs.VectorScale(velboids2, 0.1) velboids3 = rs.VectorScale(velboids3, 0.2) velav = rs.VectorScale(velav, 0.8) veltrail = rs.VectorScale(veltrail, 20) # add the behaviors to the vel #self.vel = rs.VectorAdd (self.vel, velboids1) self.vel = rs.VectorAdd(self.vel, velboids2) self.vel = rs.VectorAdd(self.vel, velboids3) self.vel = rs.VectorAdd(self.vel, velav) self.vel = rs.VectorAdd(self.vel, veltrail) # update pos self.vel = vectorlimit(self.vel, self.mv) self.pos = rs.VectorAdd(self.pos, self.vel)
def VectorInternalDivision(vector1, vector2, ratio1, ratio2): vector1 = rs.coerce3dvector(vector1) vector2 = rs.coerce3dvector(vector2) return rs.VectorDivide( rs.VectorAdd(rs.VectorScale(vector1, ratio2), rs.VectorScale(vector2, ratio1)), ratio1 + ratio2)
def ellipse(self, xheight, yheight, direction): centerPoint = rs.AddPoint(self.point) if direction == 'right': centerPoint = rs.MoveObject( centerPoint, rs.VectorScale(rs.VectorCreate([1, 0, 0], [0, 0, 0]), xheight / 2)) if direction == 'left': centerPoint = rs.MoveObject( centerPoint, rs.VectorScale(rs.VectorCreate([-1, 0, 0], [0, 0, 0]), xheight / 2)) if direction == 'top': centerPoint = rs.MoveObject( centerPoint, rs.VectorScale(rs.VectorCreate([0, 1, 0], [0, 0, 0]), xheight / 2)) if direction == 'bottom': centerPoint = rs.MoveObject( centerPoint, rs.VectorScale(rs.VectorCreate([0, -1, 0], [0, 0, 0]), xheight / 2)) newEllipse = rs.AddCircle(centerPoint, xheight / 2) yScaleFactor = yheight / xheight rs.ScaleObject(newEllipse, self.point, [1, yScaleFactor, 0]) rs.DeleteObject(centerPoint) return (newEllipse)
def deflect(self, deflectPoint): """ Takes a Point as an input. Point creates a force field. The turtle deflects around the point """ defPtPos = rs.PointCoordinates(deflectPoint) prevPos = rs.PointCoordinates(self.point) deflectVector1 = rs.VectorScale(rs.VectorCreate(prevPos, defPtPos), 0.33) deflectVector2 = -deflectVector1 deflectVector90_1 = rs.VectorScale( rs.VectorRotate(deflectVector1, 90, [0, 0, 1]), 0.33) deflectVector90_2 = -deflectVector90_1 deflectVectorList = [ deflectVector1, deflectVector2, deflectVector90_1, deflectVector90_2 ] forcePts = [] for i in deflectVectorList: newPt = rs.CopyObject(deflectPoint) rs.MoveObject(newPt, i) forcePts.append(newPt) gotoPt = rs.PointCoordinates(forcePts[0]) self.goto(gotoPt[0], gotoPt[1]) rs.AddArc3Pt(forcePts[0], forcePts[1], forcePts[2]) rs.AddArc3Pt(forcePts[1], forcePts[0], forcePts[3]) rs.DeleteObjects(forcePts)
def blendcorners(polyline_id, radius): # Fillets the corners of a polyline (from the McNeel website) if not polyline_id: return vertices = rs.PolylineVertices(polyline_id) if not vertices: return if radius is None: return between = lambda a, b: (a + b) / 2.0 newverts = [] for i in range(len(vertices) - 1): a = vertices[i] b = vertices[i + 1] segmentlength = rs.Distance(a, b) vec_segment = rs.PointSubtract(b, a) vec_segment = rs.VectorUnitize(vec_segment) if radius < (0.5 * segmentlength): vec_segment = rs.VectorScale(vec_segment, radius) else: vec_segment = rs.VectorScale(vec_segment, 0.5 * segmentlength) w1 = rs.PointAdd(a, vec_segment) w2 = rs.PointSubtract(b, vec_segment) newverts.append(a) newverts.append(between(a, w1)) newverts.append(w1) newverts.append(between(w1, w2)) newverts.append(w2) newverts.append(between(w2, b)) newverts.append(vertices[len(vertices) - 1]) CrvId = rs.AddCurve(newverts, 5) rs.DeleteObject(polyline_id) return CrvId
def setPts(self): #外周点 pt0 = [0, 0, 0] pt1 = [self.l, 0, 0] pt1 = rs.VectorRotate(pt1, self.angle / 2.0, [0, 0, 1]) pt3 = [self.l, 0, 0] pt3 = rs.VectorRotate(pt3, -self.angle / 2.0, [0, 0, 1]) pt2 = rs.VectorAdd(pt1, pt3) self.pts.append(pt0) self.pts.append(pt1) self.pts.append(pt2) self.pts.append(pt3) #ä¸ç‚¹ for i in range(len(self.pts)): if (i == len(self.pts) - 1): pt = rs.VectorAdd(self.pts[i], self.pts[0]) pt = rs.VectorDivide(pt, 2) else: pt = rs.VectorAdd(self.pts[i], self.pts[i + 1]) pt = rs.VectorDivide(pt, 2) self.midPts.append(pt) #楕円 pt0 = rs.VectorDivide(self.pts[2], 2.0) l0 = self.l * math.sin(math.radians(90 / 2.0)) l1 = self.l * math.cos(math.radians(self.angle / 2.0)) l2 = self.l * math.sin(math.radians(self.angle / 2.0)) pt1 = rs.VectorScale([self.l / 2.0, 0, 0], l1 / l0) pt1 = rs.VectorAdd(pt0, pt1) pt2 = rs.VectorScale([0, self.l / 2.0, 0], l2 / l0) pt2 = rs.VectorAdd(pt0, pt2) self.ellipsePts.append(pt0) self.ellipsePts.append(pt1) self.ellipsePts.append(pt2)
def getTwoParallelLineSelectionRegion(p0, p1, pi, width): lineDirect = rs.VectorUnitize(rs.VectorCreate(p1, p0)) lineCross = rs.VectorRotate(lineDirect, 90, (0, 0, 1)) piUp = rs.VectorAdd(pi, rs.VectorScale(lineCross, width)) piDown = rs.VectorAdd(pi, rs.VectorScale(rs.VectorReverse(lineCross), width)) piDownRight = rs.VectorAdd(piDown, lineDirect * width) return (geo.Point3d(piUp), geo.Point3d(piDown), geo.Point3d(piDownRight))
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)
def addExtlHandrail(self): hdrlPtList = [] hdrlEndPt = rs.AddPoint(rs.CurveEndPoint(self.guideCrv)) hdrlStPt = rs.AddPoint(rs.CurveStartPoint(self.guideCrv)) hdrlVec = rs.VectorCreate(hdrlStPt, hdrlEndPt) projHdrlVec = rs.VectorUnitize([hdrlVec.X, hdrlVec.Y, 0]) #Top Extension topExtEndPt = rs.CopyObject(hdrlEndPt) rs.MoveObject(topExtEndPt, rs.VectorScale(projHdrlVec, -.305)) hdrlPtList.append(topExtEndPt) #Btm Extension (tread length method) btmExtEndPt = rs.CopyObject(hdrlStPt) btmPtExtTemp = rs.CopyObject(hdrlStPt) btmVertPtExtTemp = rs.CopyObject(hdrlStPt) rs.MoveObject(btmPtExtTemp, hdrlVec) angledLineTemp = rs.AddLine(hdrlStPt, btmPtExtTemp) rs.MoveObject(btmVertPtExtTemp, [0, 0, -1]) vertLineTemp = rs.AddLine(btmVertPtExtTemp, hdrlStPt) rs.MoveObject(vertLineTemp, rs.VectorScale(projHdrlVec, self.treadLength)) btmExtPt = rs.LineLineIntersection(angledLineTemp, vertLineTemp)[0] hdrlPtList.append(hdrlEndPt) hdrlPtList.append(btmExtPt) #Make and move hdrlCrv = rs.AddPolyline(hdrlPtList) rs.MoveObject(hdrlCrv, [0, 0, self.hdrlHeight]) #move away from wall widthVec = rs.VectorUnitize( rs.VectorCreate(rs.CurveEndPoint(self.stairWidthEdge), rs.CurveStartPoint(self.stairWidthEdge))) rs.MoveObject(hdrlCrv, rs.VectorScale(widthVec, self.hdrlDistFromWall)) #cleanup rs.DeleteObject(topExtEndPt) rs.DeleteObject(hdrlEndPt) rs.DeleteObject(hdrlStPt) rs.DeleteObject(btmPtExtTemp) rs.DeleteObject(btmVertPtExtTemp) rs.DeleteObject(angledLineTemp) rs.DeleteObject(vertLineTemp) rs.DeleteObject(btmExtEndPt) return hdrlCrv
def getConfig1(self,p,q,r): pr=rs.VectorUnitize(rs.VectorCreate(r,p)) prN=rs.VectorScale(rs.VectorRotate(pr,90,[0,0,1]),self.b0) prA=rs.VectorScale(pr,self.b1) a=rs.PointAdd(q,prA) # goes from q to a along pr b=rs.PointAdd(q,prN) # goes from q to b perpendicular to pr c=rs.PointAdd(b,prA) t=self.checkContainment(a,b,c) if(t==True): #poly=rs.AddPolyline([q,a,c,b,q]) poly=[q,a,c,b,q] return poly else: return None
def genIntPoly(self, poly): cen=rs.CurveAreaCentroid(poly)[0] pts=rs.CurvePoints(poly) a=[(pts[0][0]+pts[1][0])/2,(pts[0][1]+pts[1][1])/2,0] b=[(pts[0][0]+pts[3][0])/2,(pts[0][1]+pts[3][1])/2,0] vec1=rs.VectorScale(rs.VectorUnitize(rs.VectorCreate(cen,a)),self.d0/2) vec2=rs.VectorScale(rs.VectorUnitize(rs.VectorCreate(cen,b)),self.d1/2) p=rs.PointAdd(cen,vec1) q=rs.PointAdd(cen,-vec1) r=rs.PointAdd(p,vec2) u=rs.PointAdd(p,-vec2) t=rs.PointAdd(q,vec2) s=rs.PointAdd(q,-vec2) poly=rs.AddPolyline([r,u,s,t,r]) self.req_poly.append(poly)
def offsetPoints(pList, startPt, endPt): pointList = [] sideVector = rs.VectorCreate(endPt, startPt) pointSpacing = (rs.VectorLength(sideVector) / len(pList)) gapVector = rs.VectorUnitize(sideVector) gapVector = rs.VectorScale(gapVector, pointSpacing) for i in range(0, len(pList)): scaledVector = rs.VectorScale(gapVector, i) pointMove = rs.VectorAdd(startPt, scaledVector) offsetPoint = rs.VectorAdd(pointMove, pList[i] * rs.VectorLength(sideVector)) point = (0, 0, 0) movedPoint = rs.PointAdd(point, offsetPoint) pointList.append(movedPoint) return pointList
def drawBranch(origin, dir, minDistance, maxDistance, maxAngle): vecTwig = rs.VectorUnitize(dir) vecTwig = rs.VectorScale(vecTwig, minDistance+random.random()*(maxDistance-minDistance)) mutationPlane = rs.PlaneFromNormal((0, 0, 0), vecTwig) vecTwig = rs.VectorRotate(vecTwig, random.random()*maxAngle, mutationPlane[1]) vecTwig = rs.VectorRotate(vecTwig, random.random()*360, dir) return rs.PointAdd(origin, vecTwig)
def forward(self, magnitude): print self.direction movement = rs.VectorScale(self.direction, magnitude) prevPos = rs.PointCoordinates(self.point) rs.MoveObject(self.point, movement) currentPos = rs.PointCoordinates(self.point) rs.AddLine(prevPos, currentPos)
def nextStep(self): newPlane = rs.PlaneFromNormal(self.pos, self.mpos.Mesh.NormalAt(self.mpos)) # create a vector from newFrame XAxis downVect = newPlane.XAxis # figure out how much to rotate it. deltaAngle = g.Vector3d.VectorAngle(downVect, g.Vector3d(0.0, 0.0, -1.0), newPlane) # rotate it in the plane downVect.Rotate(deltaAngle, newPlane.ZAxis) # set the length downVect = rs.VectorScale(downVect, self.stepsize) spacePoint = g.Point3d.Add(self.pos, downVect) # find next point newPoint, id = self.mesh.ClosestPoint(spacePoint) if newPoint.Z > self.pos.Z: # if higher self.state = 'off' print 'higher', self.ind #if newPoint == self.pos: # if the water drop stops # self.state = 'off' # print 'stop' #elif self.checkTolerance(newPoint) == True: # if too close # self.state = 'finished' else: self.updatePos(newPoint, id)
def forward(self, magnitude): movement = rs.VectorScale(self.direction, magnitude) prevPos = rs.PointCoordinates(self.point) rs.MoveObject(self.point, movement) currentPos = rs.PointCoordinates(self.point) line = self.drawLine(prevPos, currentPos) return line
def align(self, mag): steer = rs.VectorCreate( (0,0,0) , (0,0,0) ) count = 0 for i in pts: distance = rs.Distance(i.p, self.p) if distance > 0 and distance < 40: steer = rs.VectorAdd(steer, i.v) count += 1 if count>0: steer = rs.VectorScale(steer, 1.0/count) steer = rs.VectorScale(steer, mag) self.a = rs.VectorAdd(self.a, steer)
def drawVectors(pts, vects, scale=3000): gen = [] for p, v in zip(pts, vects): gen.append(rs.AddLine(p, p + rs.VectorScale(v, scale))) rs.AddGroup('Trash') rs.AddObjectsToGroup(gen, 'Trash')
def meshExtrudePolyToByVectPlane(poly, vect, pln): extrudeVect = vect #find far line from vector to be intersected later farvect = rs.VectorScale(extrudeVect, 1000) pts = rs.CurveEditPoints(poly) meshes = [] for i in range(0, len(pts) - 1): p1 = pts[i] p2 = pts[i + 1] line = [p1, p1 + farvect] p1pj = rs.LinePlaneIntersection(line, pln) line = [p2, p2 + farvect] p2pj = rs.LinePlaneIntersection(line, pln) m = addMeshQuad([p1, p1pj, p2pj, p2]) meshes.append(m) pjPolyPts = [] for p in pts: line = [p, p + farvect] xp = rs.LinePlaneIntersection(line, pln) pjPolyPts.append(xp) mesh = rs.JoinMeshes(meshes, True) return mesh, pjPolyPts
def update(self): self.vecAcceleration = rs.VectorCreate(self.acceleration, self.basePoint) self.vecVelocity = rs.VectorAdd(self.vecVelocity, self.vecAcceleration) self.location = rs.PointAdd(self.location, self.vecVelocity) self.acceleration = rs.VectorScale(self.acceleration, 0)
def getExtendedCrv(self, crvList, dist=50, layer_height=2.5, vecMul=.66): segmentCount = int(math.floor(dist / layer_height)) - 1 tmpList = [] fullHeight = [] for i in range(len(crvList)): extendedCrv = rs.ExtendCurveLength(crvList[i], 2, 0, dist) fullHeight.append(extendedCrv) domStart, domEnd = rs.CurveDomain(extendedCrv) trimmedCrv = rs.TrimCurve(extendedCrv, (domStart, 0)) tmpList.append(trimmedCrv) tmp = [] ###Smooth Curves### for i in range(len(tmpList)): bottomPt = rs.CurveEndPoint(tmpList[i]) zVec = rs.VectorAdd((0, 0, 0), (0, 0, dist)) topPt = rs.CopyObject(bottomPt, zVec) line = rs.AddLine(bottomPt, topPt) crvPts = rs.DivideCurve(tmpList[i], segmentCount) LinePts = rs.DivideCurve(line, segmentCount) for i in range(segmentCount): tmpVec = rs.VectorCreate(LinePts[segmentCount - i - 1], crvPts[i]) tmpVec = rs.VectorScale(tmpVec, vecMul) rs.MoveObject(crvPts[i], tmpVec) tmp.append(rs.AddInterpCurve(crvPts)) result = [] for crv in tmp: crvLen = rs.CurveLength(crv) if crvLen < dist: tmpExt = dist - crvLen result.append(rs.ExtendCurveLength(crv, 2, 0, tmpExt)) else: result.append(rs.CopyObject(crv)) return result
def offset_face(mesh, fkey, t): cent = mesh.face_centroid(fkey) vcords = mesh.face_coordinates(fkey, ordered=True) vkeys = mesh.face_vertices(fkey, ordered=True) pts = [] vecs = [] keys = [None] * len(vcords) for i, vcor in enumerate(vcords): vec1 = rs.VectorUnitize(rs.VectorCreate(vcords[i - 2], vcords[i - 1])) vec2 = rs.VectorUnitize(rs.VectorCreate(vcords[i], vcords[i - 1])) vec = rs.VectorAdd(vec1, vec2) vec = rs.VectorUnitize(vec) ang = rs.VectorAngle(vec, vec1) ang = math.radians(ang) l = t / math.sin(ang) vec = rs.VectorScale(vec, l) pt = rs.PointAdd(vcords[i - 1], vec) keys[i - 1] = mesh.add_vertex(x=pt[0], y=pt[1], z=pt[2]) for i, vkey in enumerate(vkeys): mesh.add_face([vkeys[i], keys[i], keys[i - 1], vkeys[i - 1]]) mesh.add_face(keys) del mesh.face[fkey]
def RandomPointInCone(origin, direction, minDistance, maxDistance, maxAngle): vecTwig = rs.VectorUnitize(direction) vecTwig = rs.VectorScale(vecTwig, minDistance + random.random()*(maxDistance-minDistance)) MutationPlane = rs.PlaneFromNormal((0,0,0), vecTwig) vecTwig = rs.VectorRotate(vecTwig, random.random()*maxAngle, MutationPlane[1]) vecTwig = rs.VectorRotate(vecTwig, random.random()*360, direction) return rs.PointAdd(origin, vecTwig)
def CheckRunLengths(runs): lengthComment = '' for i, run in enumerate(runs): dist = rs.Distance(rs.CurveStartPoint(run[0]), rs.CurveStartPoint(run[1])) if dist > 360: lengthComment += 'Run {} requires a landing\n'.format(i + 1) templine = rs.AddLine(rs.CurveStartPoint(run[0]), rs.CurveStartPoint(run[1])) mdPt = rs.CurveMidPoint(templine) vec = rs.VectorCreate(mdPt, rs.CurveStartPoint(run[0])) landingCenter = rs.CopyObject(run[0], vec) vec = rs.VectorScale(rs.VectorUnitize(vec), 30) upperLine = rs.CopyObject(landingCenter, vec) vec = rs.VectorReverse(vec) lowerLine = rs.MoveObject(landingCenter, vec) rs.DeleteObject(templine) run.insert(1, lowerLine) run.insert(2, upperLine) flatList = [] for item in runs: for each in item: flatList.append(each) pairs = [] for i in range(0, len(flatList), 2): pairs.append([flatList[i], flatList[i + 1]]) return pairs, lengthComment