def makeTeapotJoint(self, _pos): tv = _pos - teapotOrigin # translation vector dupl = rg.Brep.Duplicate(teapot) # duplicate the OG teapot tr = rg.Transform.Translation(tv) # move it to its new position dupl.Transform(tr) dupl.Scale(self.pipeRadius) # scale it , and rotate it dupl.Rotate(random.choice([0, rm.ToRadians(90)]), rg.Vector3d.XAxis, _pos) dupl.Rotate(random.choice([0, rm.ToRadians(90)]), rg.Vector3d.YAxis, _pos) dupl.Rotate(random.choice([0, rm.ToRadians(90)]), rg.Vector3d.ZAxis, _pos) jointsList[self.ID].append(dupl)
def curve_discontinuity(self, crv): """ Returns the params and points at the discontinuities of a curve. """ # get domain of curve tMin = crv.Domain.Min tMax = crv.Domain.Max disc_params = [] disc_pts = [] getNext = True while getNext: # search for discontinuity and gets the t value getNext, t = crv.GetNextDiscontinuity(rg.Continuity.G1_continuous, tMin, tMax) if not rm.IsValidDouble(t): # test whether t value is valid or not, returns 0.00 if not t = 0.00 if t > tMax: t = tMax elif t < tMin: t = tMin disc_params.append(t) disc_pts.append(crv.PointAt(t)) if getNext: tMin = t return disc_params, disc_pts
def follow(self, otherTurtle): """ otherTurtle : other turtle objects """ positionA = self.position() positionB = otherTurtle.position() #Calculate the angle from the two coordinates and make the turtle move forward angle = Vec2DExpansion().findAngle(positionA, positionB) vector = rg.Vector3d(1, 0, 0) vector.Rotate(rm.ToRadians(angle), rg.Vector3d.ZAxis) self.setHeading(vector) self.forward(10)
def set_scale(rivet): scale = rm.UnitScale(sc.doc.ModelUnitSystem.Millimeters, sc.doc.ModelUnitSystem) xf = Rhino.Geometry.Transform.Scale(Rhino.Geometry.Plane.WorldXY, scale, scale, scale) for brep in rivet.breps: brep.Transform(xf) #copy to displaybreps for preview global displaybreps displaybreps = rivet.breps return rivet
def IsNearDupCrv(ref_crv, test_crv, user_tol, divs=5): #ref_crv, test_crv are tuples: [0]=crv,[1]=bb,[2]=len if ref_crv[1].Max.EpsilonEquals(test_crv[1].Max, user_tol): if ref_crv[1].Min.EpsilonEquals(test_crv[1].Min, user_tol): #bounding box within tolerance, test overall length if rm.EpsilonEquals(ref_crv[2], test_crv[2], user_tol): #length within tolerance, divide ref. curve by a # of points pt_cont = clr.StrongBox[System.Array[Rhino.Geometry.Point3d]]() div = ref_crv[0].DivideByCount(divs, True, pt_cont) #check point deviation at each point if div: #pt_cont.Value is list of points on ref_crv for pt in pt_cont.Value: rc, p = test_crv[0].ClosestPoint(pt) if rc: if pt.DistanceTo( test_crv[0].PointAt(p)) > user_tol: #at least one point is too far, jump out return return True
def XAxisUp(self, angle): self._location.Rotate(rm.ToRadians(angle), self._location.XAxis)
def left(self, angle): self._location.Rotate(rm.ToRadians(angle), self._location.ZAxis)
def hankins(polylist, contactAngle=60): """ Provides an islamic star pattern based on the paper of C.S. Kaplan. (http://www.cgl.uwaterloo.ca/~csk/papers/kaplan_gi2005.pdf) This is called "Hankin's Method" since he was the first Western scientist to describe these patterns. For this function to work correctly you need a set of polygons which are touching eachother without any gaps. """ segments, midpts, startpts, endpts, vec1, vec2, sdl1, sdl2, lxlPt, innerLines, outerLines = [], [], [], [], [], [], [], [], [], [], [] for item in polylist: segments.append(item.DuplicateSegments()) for m, seglist in enumerate(segments): tempMid, tempStart, tempEnd, tempVec1, tempVec2, tl1, tl2, lxl = [], [], [], [], [], [], [], [] # 1) points for k, seg in enumerate(seglist): # get the points of the segments # ! IMPORTANT: you have to use .PointAtNormalizedLength tempMid.append(seg.PointAtNormalizedLength(0.5)) tempStart.append(seg.PointAtStart) tempEnd.append(seg.PointAtEnd) # nested lists midpts.append(tempMid) startpts.append(tempStart) endpts.append(tempEnd) # 2) vectors for k, seg in enumerate(seglist): # Vector: Endpt - Startpt # also rotate them tv1 = rg.Vector3d(startpts[m][k] - midpts[m][k]) rg.Vector3d.Rotate(tv1, rm.ToRadians(-contactAngle), rg.Vector3d.ZAxis) tempVec1.append(tv1) tv2 = rg.Vector3d(endpts[m][k] - midpts[m][k]) rg.Vector3d.Rotate(tv2, rm.ToRadians(contactAngle), rg.Vector3d.ZAxis) tempVec2.append(tv2) vec1.append(tempVec1) vec2.append(tempVec2) # 3) SDL lines for k, seg in enumerate(seglist): tl1.append(rg.Line(midpts[m][k], vec1[m][k], sl / 3)) tl2.append(rg.Line(midpts[m][k], vec2[m][k], sl / 3)) sdl1.append(tl1) sdl2.append(tl2) # 4) Line intersections, get points (inner points of a star) for k, seg in enumerate(seglist): lxl.append(ghcomp.LineXLine(sdl1[m][k], sdl2[m][k - 1])[2]) lxlPt.append(lxl) # inner polygons (stars) # some advanced slicing going on; dont worry, its acutally very pythonic for l, crv in enumerate(polylist): # listIn1.append(listIn1.pop(0)) # poor man's list shifting # shift(listIn1, -1) resultInner = [None] * (len(lxlPt[l][:]) + len(midpts[l][:])) resultInner[::2] = lxlPt[l][:] resultInner[1::2] = midpts[l][:] resultInner.append(lxlPt[l][0]) # to close the polyline innerLines.append(rg.Polyline(resultInner).ToNurbsCurve()) # outer polygons for p, poly in enumerate(polylist): tl = [] for v in range(len(segments[p])): resultOuter = [ midpts[p][v], startpts[p][v], midpts[p][v - 1], lxlPt[p][v], midpts[p][v] ] tl.append(rg.Polyline(resultOuter).ToNurbsCurve()) outerLines.append(tl) # for visual clues how this is made global verbose verbose = segments, midpts, startpts, endpts, sdl1, sdl2, lxlPt return innerLines, outerLines
doc.ModelAbsoluteTolerance) triDown.append(cShape[0]) for k in range(nOfST): depthST = random.randrange(2, 5) if ST_ON else 1 # draw the Sierpinski triangles ptsTop[k + 1].Z += self.h drawST(ptsBottom[k], ptsBottom[k + 1], ptsTop[k + 1], depthST) return triDown # ----------------------------------------------------------- slabs = [] facade = [] triST = [] for lvl in range(0, stories): plane = rg.Plane(rg.Point3d(pos.X, pos.Y, lvl * height), rg.Vector3d.ZAxis) plane.Rotate(rm.ToRadians(planeRot), rg.Vector3d.ZAxis) width = floorsize[lvl] floor = Floor(plane, width, height, sidecount) slabs.append(floor.poly) facade.extend(floor.f) _wire = slabs _fac = facade _ST = triST