Example #1
0
 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 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)
Example #3
0
 def XAxisUp(self, angle):
     self._location.Rotate(rm.ToRadians(angle), self._location.XAxis)
Example #4
0
 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
Example #6
0
                                                   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