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 renderSubTree(self, startRadius, growthFactor, curveDegree): #start radius is the radius at the tip of the smallest branches #growth Factor is the factor by which the start radius grows #as it moves towards the root, node by node #curveDegree is the degree of the curves of the tree treeID = rs.AddGroup() while True: deepCh = self.deepestChild() startNode = deepCh[0] if startNode == None: #this is the case where the whole tree is rendered #later return the group id of the group #that contains the whole tree from here return treeID curNode = startNode nodeList = [startNode] while (not curNode.parent is None) and (not curNode.isDone): nodeList.append(curNode.parent) curNode = curNode.parent posList = [] i = 0 while i < len(nodeList): posList.append(nodeList[i].pos) i += 1 curveID = rs.AddCurve(posList,curveDegree) curDom = rs.CurveDomain(curveID) node1 = rs.EvaluateCurve(curveID, curDom[0]) node2 = rs.EvaluateCurve(curveID, curDom[1]) tan1 = rs.CurveTangent(curveID, curDom[0]) tan2 = rs.CurveTangent(curveID, curDom[1]) plane1 = rs.PlaneFromNormal(node1, tan1) plane2 = rs.PlaneFromNormal(node2, tan2) radius1 = startRadius radius2 = (growthFactor**len(nodeList))*startRadius circles = [] circles.append(rs.AddCircle(plane1, radius1)) circles.append(rs.AddCircle(plane2, radius2)) branch = rs.AddSweep1(curveID, circles, True) rs.AddObjectToGroup(branch, treeID) rs.DeleteObjects(circles) rs.DeleteObject(curveID) for nd in nodeList: nd.isDone = True
def __generate_form_levels(self, spine_curve): crvdomain = rs.CurveDomain(spine_curve) printedState = "" crosssection_planes = [] crosssection_plane_nums = [] crosssections = [] t_step = (crvdomain[1] - crvdomain[0]) / ( self.object_properties["number_of_lofts"] - 1) t = crvdomain[0] for t in rs.frange(crvdomain[0], crvdomain[1], t_step): if (self.emotion_properties["vertical_AR"][str(int(t + 1))] != None): crvcurvature = rs.CurveCurvature(spine_curve, t) crosssectionplane = None if not crvcurvature: crvPoint = rs.EvaluateCurve(spine_curve, t) crvTangent = rs.CurveTangent(spine_curve, t) crvPerp = (0, 0, 1) crvNormal = rs.VectorCrossProduct(crvTangent, crvPerp) printedState = printedState + str(crvNormal) crosssectionplane = rs.PlaneFromNormal( crvPoint, crvTangent) if (t == 0): crosssectionplane = rs.PlaneFromNormal([0, 0, 0], [0, 0, 1]) else: crvPoint = crvcurvature[0] crvTangent = crvcurvature[1] crvPerp = rs.VectorUnitize(crvcurvature[4]) crvNormal = rs.VectorCrossProduct(crvTangent, crvPerp) printedState = printedState + str(crvNormal) crosssectionplane = rs.PlaneFromNormal( crvPoint, crvTangent, crvNormal) if crosssectionplane: crosssection_planes.append(crosssectionplane) crosssection_plane_nums.append(str(int(t + 1))) if len(crosssection_plane_nums) > 0: last_element = crosssection_plane_nums.pop( len(crosssection_plane_nums) - 1) crosssection_plane_nums.insert(0, last_element) for index in xrange(len(crosssection_plane_nums)): crosssections.append( self.__generate_individual_levels( crosssection_planes[index], crosssection_plane_nums[index])) if not crosssections: return crosssections.append(crosssections.pop(0)) rs.AddLoftSrf(crosssections, closed=False, loft_type=int( round(self.emotion_properties["vertical_wrapping"]))) return crosssection_planes[0]
def InclinePlane(origin, boxlength): """ A function to get a plane for a circle, using its origin """ try: if (type(origin) != list): raise TypeError except TypeError: print("InclinedPlane() argument 'origin' should be a type list") else: if orientation_dist == 'uniform': #initialise a list called norm norm = [] #define a random vector theta_0 = 2 * math.pi * random.uniform(0, 1) theta_1 = math.acos(1 - 2 * random.uniform(0, 1)) vector = [ boxlength * math.cos(theta_0), boxlength * math.sin(theta_0) * math.cos(theta_1), boxlength * math.sin(theta_0) * math.sin(theta_1) ] #a loop to store the difference between the origin and vector for i in range(3): norm.append(vector[i] - origin[i]) #unitize the 3d vector normal = rs.VectorUnitize(norm) #convert the origin to a plane plane = rs.PlaneFromNormal(origin, normal) return plane
def squareSect(crv,width,height): sections=[] divPts=rs.DivideCurve(crv,10) keep=True for i in range(len(divPts)): param=rs.CurveClosestPoint(crv,divPts[i]) tan=rs.CurveTangent(crv,param) plane=rs.PlaneFromNormal(divPts[i],tan) sect=rs.AddRectangle(plane,width,height) cpt=rs.CurveAreaCentroid(sect)[0] vec=rs.VectorCreate(divPts[i],cpt) sect=rs.MoveObject(sect,vec) if i>0: if testAlign(sect,oldSect)==False: sect=align(sect,oldSect,divPts[i],tan) oldSect=sect sections.append(sect) branch=rs.AddLoftSrf(sections,None,None,2,0,0,False) edges=rs.DuplicateEdgeCurves(branch) if width>height: testVal=height else: testVal=width for i in range(len(edges)): testPt=rs.CurveMidPoint(edges[i]) for j in range(len(edges)): param=rs.CurveClosestPoint(edges[j],testPt) pt=rs.EvaluateCurve(edges[j],param) if rs.Distance(pt,testPt)<testVal/6: keep=False rs.DeleteObjects(sections) rs.DeleteObjects(edges) return branch
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 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 WindowLeftDistance(): # Find midpoint of window left line midpoint_windowLeft = rs.CurveMidPoint(window_leftLine[1]) # Find closest point in curve window left parameterLeftLine = rs.CurveClosestPoint(window_leftLine[1], midpoint_windowLeft) # Find curve window left Tangent windowLeft_Tangent = rs.CurveTangent(window_leftLine[1], parameterLeftLine) # find window left normal plane windowLeft_plane = rs.PlaneFromNormal(midpoint_windowLeft, windowLeft_Tangent) # find start and end points of ground line points_ll = [] start_ll = bbox[0] end_ll = bbox[3] points_ll.append(start_ll) points_ll.append(end_ll) #find point on Surface Left line point_SurfLeftLine = rs.LinePlaneIntersection(points_ll, windowLeft_plane) #point_SurfLeftLine = rs.AddPoint(point_SurfLeftLine) Window_leftDistance = rs.Distance(midpoint_windowLeft, point_SurfLeftLine) return Window_leftDistance
def SillHeight(): # Find mid point of sill line midpointSill = rs.CurveMidPoint(window_sillLine[1]) #midpointSill = rs.AddPoint(midpointSill) # Find closest point in curve parameterSill = rs.CurveClosestPoint(window_sillLine[1], midpointSill) # Find curve Tangent sill_Tangent = rs.CurveTangent(window_sillLine[1], parameterSill) # find normal plane sill_plane = rs.PlaneFromNormal(midpointSill, sill_Tangent) # find start and end points of ground line points_gl = [] start_gl = rs.CurveStartPoint(groundLine[1]) end_gl = rs.CurveEndPoint(groundLine[1]) points_gl.append(start_gl) points_gl.append(end_gl) #find point on ground line pointGroundLine = rs.LinePlaneIntersection(points_gl, sill_plane) #pointGroundLine = rs.AddPoint(pointGroundLine) sill_Height = rs.Distance(midpointSill, pointGroundLine) return sill_Height
def DistributeCirclesOnSphere(): sphere_radius = rs.GetReal("Radius of sphere", 10.0, 0.01) if not sphere_radius: return circle_radius = rs.GetReal("Radius of packing circles", 0.05 * sphere_radius, 0.001, 0.5 * sphere_radius) if not circle_radius: return vertical_count = int((math.pi * sphere_radius) / (2 * circle_radius)) rs.EnableRedraw(False) phi = -0.5 * math.pi phi_step = math.pi / vertical_count while phi < 0.5 * math.pi: horizontal_count = int((2 * math.pi * math.cos(phi) * sphere_radius) / (2 * circle_radius)) if horizontal_count == 0: horizontal_count = 1 theta = 0 theta_step = 2 * math.pi / horizontal_count while theta < 2 * math.pi - 1e-8: circle_center = (sphere_radius * math.cos(theta) * math.cos(phi), sphere_radius * math.sin(theta) * math.cos(phi), sphere_radius * math.sin(phi)) circle_normal = rs.PointSubtract(circle_center, (0, 0, 0)) circle_plane = rs.PlaneFromNormal(circle_center, circle_normal) rs.AddCircle(circle_plane, circle_radius) theta += theta_step phi += phi_step rs.EnableRedraw(True)
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 Build_Key(Point, colors, tol): """ Build key for tolerance shading. Create color coded text objects and planes. """ low2 = "-" + str(tol[2]) + '"' + " and lower" low1 = "-" + str(tol[2]) + '"' + " to -" + str(tol[1]) + '"' low0 = "-" + str(tol[1]) + " to -" + str(tol[0]) + '"' good = "-" + str(tol[0]) + " to +" + str(tol[0]) + '"' high0 = "+" + str(tol[0]) + " to +" + str(tol[1]) + '"' high1 = "+" + str(tol[1]) + " to +" + str(tol[2]) + '"' high2 = "+" + str(tol[2]) + " and higher" stringList = [high2, high1, high0, good, low0, low1, low2] objs = [] for i in range(len(stringList)): pt = rs.coerce3dpoint([0, 0, 1.5 * i + 3]) plane = rs.PlaneFromNormal(pt + Point, [0, -1, 0], [1, 0, 0]) txt = rs.AddText(stringList[i], plane) srf = rs.AddPlaneSurface(plane, 1, 1) rs.MoveObject(srf, [-2, 0, 0]) stringColor = "Tol_" + colors[i].ToString().split("[")[1].rstrip("]") mt.OrganizeLayer(stringColor, Objects=[srf, txt], Render=colors[i], Color=colors[i])
def draw(pts): rs.EnableRedraw(0) sleep(0.05) RhinoApp.Wait() for i in range(4): for j in range(4): if recs[i][j]: rs.DeleteObject(recs[i][j]) if tags[i][j]: rs.DeleteObject(tags[i][j]) if pts[i][j]: recs[i][j] = rs.AddRectangle( rs.PlaneFromNormal((i + 0.1, j + 0.1, 0), (0, 0, 1)), 0.8, 0.8) tags[i][j] = rs.AddText(pts[i][j], (i + 0.5, j + 0.5, 0), 0.2 + (0.1 / len(str(pts[i][j]))), 'Arial', 0, 131074) if pts[i][j] <= 4: rs.ObjectColor(tags[i][j], (245, 245, 220)) rs.ObjectColor(recs[i][j], (245, 245, 220)) if 8 <= pts[i][j] <= 16: rs.ObjectColor(tags[i][j], (245, 97, 0)) rs.ObjectColor(recs[i][j], (245, 97, 0)) if 32 <= pts[i][j] <= 64: rs.ObjectColor(tags[i][j], (245, 7, 0)) rs.ObjectColor(recs[i][j], (245, 9, 0)) if pts[i][j] > 64: rs.ObjectColor(tags[i][j], (245, 197, 44)) rs.ObjectColor(recs[i][j], (245, 197, 44)) rs.EnableRedraw(1)
def make_jigs(b, diam, bdiam): jig_base_height = 4. / 12 jig_clearance = .25 / 12 # for s in [b.tof[i] for i in [0,2,5,7]]: for s in b.tof: r = 90 width = 5 * b.deckString.thickness height = s.keel_hab + 2 * b.deckString.width + jig_base_height p = [s.section, 0, 0] rect = x_rectangle_cut_out( p, width, height, b.deckString.thickness + 2 * jig_clearance, height - jig_base_height + jig_clearance + b.deckString.width) rect = [rs.MoveObject(rect, [0, 0, -jig_base_height])] plane = rs.PlaneFromNormal([s.section, 0, 0], [1, 0, 0]) holes = [ rs.MoveObject(rs.AddCircle(plane, diam / 2), [ 0, 1.5 * b.deckString.thickness, s.keel_hab + b.deckString.width ]) ] holes.extend(rs.MirrorObjects(holes, p, ss(p, [1, 0, 0]), copy=True)) bhole = rs.MoveObject(rs.AddCircle(plane, bdiam / 2), [0, 0, 47. / 64 / 12 - jig_base_height]) holes.extend([bhole, rs.CopyObject(bhole, [0, 0, 1.5 / 12])]) rs.RotateObjects(rect + holes, p, 90, [0, 1, 0])
def MakeDoubleLine(cls, width, p0, p1, type=0): """Make a doubleLine by width and two points Parameters: width: Type real, the width p0,p1: Type Point3d type 0=middle, 1=right, 2=left returns: DoubleLine """ line = geo.Line(p0, p1) curveLine = geo.LineCurve(line) plane = rs.PlaneFromNormal(p0, (0, 0, 1), p1 - p0) halfWidth = width / 2.0 if type == 0: offLine0 = curveLine.Offset(plane, halfWidth, sc.doc.ModelAbsoluteTolerance, geo.CurveOffsetCornerStyle.None) offLine1 = curveLine.Offset(plane, -halfWidth, sc.doc.ModelAbsoluteTolerance, geo.CurveOffsetCornerStyle.None) return cls(offLine0[0].Line, offLine1[0].Line) elif type == 1: offLine0 = curveLine.Offset(plane, width, sc.doc.ModelAbsoluteTolerance, geo.CurveOffsetCornerStyle.None) return cls(offLine0[0].Line, line) elif type == 2: offLine1 = curveLine.Offset(plane, -width, sc.doc.ModelAbsoluteTolerance, geo.CurveOffsetCornerStyle.None) return cls(line, offLine1[0].Line)
def pointtocone(origin, direction, mindis, maxdis, maxangle): vectwig = rs.VectorUnitize(direction) vectwig = rs.VectorScale(vectwig, random.uniform(mindis, maxdis)) 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 TransformProfile(object, pt1, pt2): normal = rs.VectorSubtract(pt1, pt2) normal = rs.VectorUnitize(normal) plane = rs.PlaneFromNormal(pt1, normal) transformation = rs.XformRotation1((rs.WorldXYPlane), normal) profiletras = rs.TransformObject(object, transformation, True)
def SentidoNo(cirDir, no, Plano, cirRaio): pOr, eX, eY, eZ = Plano planoAux = rs.PlaneFromNormal(no, eZ) Circulo = rs.AddCircle(planoAux, cirRaio) dir1 = rs.ClosedCurveOrientation(cirDir, eZ) dir2 = rs.ClosedCurveOrientation(Circulo, eZ) if not dir1 == dir2: rs.ReverseCurve(Circulo) return Circulo
def extframe(srf): crv = rs.DuplicateSurfaceBorder(srf, type=1) point = rs.EvaluateCurve(crv, 0) parameter = rs.SurfaceClosestPoint(srf, point) plane = rs.SurfaceFrame(srf, parameter) direction = rs.CurveTangent(crv, 0) newplane = rs.PlaneFromNormal(point, direction, plane.ZAxis) frame = sweepSec(crv, newplane, vec1) if crv: rs.DeleteObjects(crv) return frame
def draw(self): plane = rs.PlaneFromNormal(rs.coerce3dpoint(self.center), self.nv) p1 = rs.coerce3dpoint(self.center + self.sv1 + self.sv2) p2 = rs.coerce3dpoint(self.center - self.sv1 - self.sv2) p3 = rs.coerce3dpoint(self.center + self.sv1 - self.sv2) p4 = rs.coerce3dpoint(self.center - self.sv1 + self.sv2) pts = [p1, p4, p2, p3, p1] draw_rectangle(pts) for pt in pts[0:-1]: sc.doc.Objects.AddPoint(pt)
def CreatingBeam(Crv, Rad): EndPt = rs.CurveEndPoint(Crv) StPt = rs.CurveStartPoint(Crv) DirVec = EndPt - StPt StPl = rs.PlaneFromNormal(StPt, DirVec) EndPl = rs.PlaneFromNormal(EndPt, DirVec) CirEd = rs.AddCircle(EndPl, Rad) CirSt = rs.AddCircle(StPl, Rad) IdsList = [] IdsList.append(CirSt) IdsList.append(CirEd) BeamGeometry = rs.AddLoftSrf(IdsList) return BeamGeometry
def drawEdge(self,nodes): p1 = self.posVec p2 = nodes[self.parentID].posVec self.geom.append(rs.AddLine(p1,p2)) pNormal = rs.VectorSubtract(p2,p1) height = rs.VectorLength(pNormal) plane = rs.PlaneFromNormal(p1,pNormal) radius = self.radius self.geom.append(rs.AddCylinder(plane,height,radius))
def CreatingNodeFun(Pt, Lines, BeamRad, BeamLength): Beams = [] for i in Lines: MidPt = rs.CurveMidPoint(i) DirVe = MidPt - Pt DirVecUni = rs.VectorUnitize(DirVe) TrVec = rs.VectorScale(DirVecUni, BeamLength) PtToMove = rs.AddPoint(pt) EndPt = rs.MoveObject(PtToMove, TrVec) Plane01 = rs.PlaneFromNormal(pt, DirVe) Plane02 = rs.PlaneFromNormal(PtToMove, DirVe) Ids = [] Cir01 = rs.AddCircle(Plane01, BeamRad) Cir02 = rs.AddCircle(Plane02, BeamRad) Ids.append(Cir01) Ids.append(Cir02) Beam = rs.AddLoftSrf(Ids) Beams.append(Beam) return Beams
def planClips(lvl): viewname = lvl["level"] + "_view" tempview = rs.AddNamedView("tempview", "Top") view = rs.AddNamedView(viewname, tempview) elevation = float(lvl["elevation"]) lvlPlane = rs.CreatePlane((0, 0, elevation)) cutPlane = rs.PlaneFromNormal((0, 0, elevation + cutHeight), (0, 0, -1)) planes = [lvlPlane, cutPlane] clips = [rs.AddClippingPlane(x, 1000, 1000, view) for x in planes] group = rs.AddGroup() rs.AddObjectsToGroup(clips, group) rs.DeleteNamedView(tempview)
def rivet_tab(self, pntJ, pntI, prev_point, left_side): radius = self.rivet_diameter / 2.0 + self.tab_padding a, b, c, d, e = edgeGeom.get_arc_rod_points(pntI, pntJ, radius, not left_side) arc = rs.AddArc3Pt(b, d, c) line_ab = rs.AddLine(a, b) line_de = rs.AddLine(d, e) hole = rs.AddCircle(rs.PlaneFromNormal(pntI, self.normal), self.rivet_diameter / 2.0) line_connect = rs.AddLine(prev_point, a) self.geom_temp.extend([line_connect, line_ab, arc, line_de, hole]) return a, e
def isoframe(srf, uv, spacing, vec): points = intervalpts(srf, uv, spacing) sweeps = [] for i in points: point = rs.EvaluateSurface(srf, i[0], i[1]) parameter = rs.SurfaceClosestPoint(srf, point) plane = rs.SurfaceFrame(srf, parameter) crv = rs.ExtractIsoCurve(srf, parameter, flipBool(uv)) direction = rs.CurveTangent(crv, 0) newplane = rs.PlaneFromNormal(point, direction, plane.ZAxis) sweeps.append(sweepSec(crv, newplane, vec)) return sweeps
def main(): to_delete = [] rs.ProjectOsnaps(False) positive_object = rs.GetObject("select positive object", 16) negative_object = rs.GetObject("select negative object", 16) rs.HideObject(negative_object) polysurface, face = GetSubSurface("select tenon surface") to_delete.append(face) normal = rs.VectorUnitize(rs.SurfaceNormal(face, (0.5, 0.5))) plane = rs.PlaneFromNormal(rs.EvaluateSurface(face, 0.5, 0.5), normal) rs.ViewCPlane(plane=plane) rs.ProjectOsnaps(True) tenon_rects = rs.GetObjects(message="select tenon curves", filter=4) tenon_faces = [] for rect in tenon_rects: tenon_faces.append(rs.AddPlanarSrf(rect)[0]) rs.ShowObject(negative_object) rs.ProjectOsnaps(False) height_pt = rs.GetPoint("enter height point") # compule a vector normal to plane of the desired height extrude_vec_a = rs.EvaluateSurface(face, 0.5, 0.5) dist = rs.DistanceToPlane(plane, height_pt) extrude_vec_b = [dist * el for el in normal] extrude_vec_b = rs.VectorAdd(extrude_vec_a, extrude_vec_b) extrude_curve = rs.AddCurve((extrude_vec_a, extrude_vec_b)) to_delete.append(extrude_curve) tenons = [] for tenon_face in tenon_faces: tenon = rs.ExtrudeSurface(tenon_face, extrude_curve) tenons.append(tenon) rs.BooleanUnion([positive_object] + tenons, delete_input=False) rs.BooleanDifference([negative_object], tenons, delete_input=False) to_delete.append(positive_object) to_delete.append(negative_object) rs.DeleteObjects(to_delete) rs.DeleteObjects(tenon_faces) rs.DeleteObjects(tenons)
def nextStepOn(self): newPlane = rs.PlaneFromNormal(self.pos, self.mesh.NormalAt(self.mpos)) # figure out how much to rotate it to put it in the slope deltaAngle = g.Vector3d.VectorAngle( newPlane.XAxis, g.Vector3d(0., 0., -1.), newPlane ) # rotate it in the plane newPlane.Rotate( deltaAngle, newPlane.ZAxis, newPlane.Origin) # set the movement vector downVect = newPlane.XAxis downVect.Unitize() downVect = rs.VectorScale(downVect, self.stepsize) spacePoint = g.Point3d.Add(self.pos, downVect) # find next point newPoint = self.mesh.ClosestPoint(spacePoint) newPoint = self.randomDir(newPoint, newPlane) self.updatePos(newPoint)
def GetPlane(pl): center = [0.0, 0.0, 0.0] for p in pl: center = VPlus(center, p) center = VMultNum(center, 1.0 / len(pl)) normal = [0, 0, 0] for i in range(len(pl)): i1 = i + 1 i0 = i - 1 if i1 >= len(pl): i1 = 0 if i0 < 0: i0 = len(pl) - 1 normal = VPlus( normal, CrossProduct(VMinus(pl[i1], pl[i]), VMinus(pl[i0], pl[i]))) return rs.PlaneFromNormal(center, normal)
def cutAtPlan(level, join): cutPlane = rs.AddPlaneSurface([-1000,-1000,level], 3000, 3000) plane = rs.PlaneFromNormal([-1000,-1000,0], [0,0,1]) planPlane = rs.AddPlaneSurface(plane, 3000, 3000) objs = rs.VisibleObjects() intersectCrvs = [] tempCrv = None for obj in objs: if rs.IsBrep(obj): tempCrv = rs.IntersectBreps(obj, cutPlane) if tempCrv: rs.MatchObjectAttributes(tempCrv, obj) newCrvs = flatten(tempCrv) rs.DeleteObject(cutPlane) rs.DeleteObject(planPlane)