Ejemplo n.º 1
0
def arc(start_point, mid_point, end_point):
    """Arc by 3 points."""
    spt = rg.Point3d(*start_point)
    mpt = rg.Point3d(*mid_point)
    ept = rg.Point3d(*end_point)
    arc = rg.Arc(spt, mpt, ept)
    return arc
Ejemplo n.º 2
0
 def UpdateDisplay(self):
     for id in self.tempIDs:
         sc.doc.Objects.Delete(id, True)
     
     if self.turned:
         centerPt = self.prevPlane.Origin.Clone()
         centerPt += self.vel
         centerPlane = rg.Plane(centerPt, self.pos, self.prevPlane.Origin)
         circ = rg.Circle(centerPlane, self.size*self.length)
         arc = rg.Arc(circ, math.pi*.5)
         arc = arc.ToNurbsCurve()
         newPlane = self.prevPlane.Clone()
         tempVel = self.prevVel.Clone()
         tempCenter = self.prevPlane.Origin.Clone()
         tempCenter += tempVel
         newPlane.Origin = tempCenter
         circ = rg.Circle(newPlane, self.size)
         circ = circ.ToNurbsCurve()
         sweep = rg.SweepOneRail()
         if arc and circ:
             breps = sweep.PerformSweep(arc, circ)
             for brep in breps:
                 sc.doc.Objects.AddBrep(brep, self.attr)
     else:
         geo = self.system.straightSec.geo.Duplicate()
         xform = rg.Transform.PlaneToPlane(rg.Plane.WorldXY, self.prevPlane)
         geo.Transform(xform)
         sc.doc.Objects.AddBrep(geo, self.attr)
     
     for id in self.ids:
         sc.doc.Objects.Delete(id, True)
Ejemplo n.º 3
0
def from_arc3d(arc):
    """Rhino Arc from ladybug Arc3D."""
    if arc.is_circle:
        return rg.Circle(from_plane(arc.plane), from_point3d(arc.c),
                         arc.radius)
    else:
        pts = (arc.p1, arc.midpoint, arc.p2)
        return rg.Arc(*(from_point3d(pt) for pt in pts))
Ejemplo n.º 4
0
def dailyCurves(suns, origin, radius):
    """Create daily sunpath curves."""
    origin = rg.Point3d(*origin)
    for day, isArc in suns:
        pts = tuple(
            origin.Add(
                origin,
                rg.Vector3d(sun.sunVector.x, sun.sunVector.y, sun.sunVector.z)
                * -radius) for sun in day)
        if isArc:
            yield rg.Arc(*pts)
        else:
            if pts[2].Z > 0:
                yield rg.Circle(*pts)
Ejemplo n.º 5
0
    def CreateAngle(self):
        pt = rg.Point3d(self.length, 0, self.length)
        self.planeEnd = rg.Plane.WorldYZ
        self.planeEnd.Origin = pt

        centerPt = rg.Point3d(self.length, 0, 0)
        origin = rg.Point3d(0, 0, 0)

        centerPlane = rg.Plane(centerPt, origin, pt)
        circ = rg.Circle(centerPlane, self.length)
        arc = rg.Arc(circ, math.pi * .5)
        arc = arc.ToNurbsCurve()
        sweep = rg.SweepOneRail()
        self.geo = sweep.PerformSweep(arc, self.sec)[0]
Ejemplo n.º 6
0
    def CreateUturn(self):
        xDir = rg.Vector3d(-1, 0, 0)
        yDir = rg.Vector3d(0, 1, 0)
        planeEnd = rg.Plane(rg.Point3d(self.length * 2, 0, 0), xDir, yDir)
        self.planeEnds.append(planeEnd)

        pt = rg.Point3d(self.length, 0, self.length)

        centerPt = rg.Point3d(self.length, 0, 0)
        origin = rg.Point3d(0, 0, 0)

        centerPlane = rg.Plane(centerPt, origin, pt)
        circ = rg.Circle(centerPlane, self.length)
        arc = rg.Arc(circ, math.pi)
        arc = arc.ToNurbsCurve()

        sweep = rg.SweepOneRail()
        self.geo = sweep.PerformSweep(arc, self.sec)[0]
Ejemplo n.º 7
0
 def CreateUturn(self):
     pt = rg.Point3d(self.size*4,0,self.size*4)
     
     xDir = rg.Vector3d(-1,0,0)
     yDir = rg.Vector3d(0,1,0)
     self.planeEnd = rg.Plane(rg.Point3d(self.size*8, 0, 0), xDir, yDir)
     
     centerPt = rg.Point3d(self.size*4, 0, 0)
     origin = rg.Point3d(0,0,0)
     
     centerPlane = rg.Plane(centerPt, origin, pt)
     circ = rg.Circle(centerPlane, self.size*4)
     arc = rg.Arc(circ, math.pi)
     arc = arc.ToNurbsCurve()
     
     circ = rg.Circle(origin, self.size)
     circ = circ.ToNurbsCurve()
     sweep = rg.SweepOneRail()
     self.geo = sweep.PerformSweep(arc, circ)[0]
Ejemplo n.º 8
0
    def CreateT(self):
        geo0 = rg.Extrusion.Create(self.sec, -self.length + self.length / 2,
                                   True)
        geo0 = geo0.ToBrep(False)

        sweepCenterPt = rg.Point3d(self.length, 0, 0)
        origin = rg.Point3d(0, 0, 0)
        pt = rg.Point3d(self.length, 0, self.length)
        centerPlane = rg.Plane(sweepCenterPt, origin, pt)

        circ = rg.Circle(centerPlane, self.length)
        arc = rg.Arc(circ, math.pi * .5)
        arc = arc.ToNurbsCurve()
        sweep = rg.SweepOneRail()
        geo1 = sweep.PerformSweep(arc, self.sec)[0]
        geo1 = geo1.CapPlanarHoles(sc.doc.ModelAbsoluteTolerance)

        rotXform = rg.Transform.Rotation(math.radians(180),
                                         rg.Vector3d(0, 0, 1),
                                         rg.Point3d(0, 0, 0))

        pt = rg.Point3d(self.size / 2, 0, self.length / 2)
        planeEnd = rg.Plane.WorldYZ
        planeEnd.Origin = pt
        self.planeEnds.append(planeEnd)

        pt = rg.Point3d(self.size / 2, 0, self.length / 2)
        planeEnd = rg.Plane.WorldYZ
        planeEnd.Origin = pt

        planeEnd.Transform(rotXform)
        self.planeEnds.append(planeEnd)

        planeXform = rg.Transform.PlaneToPlane(rg.Plane.WorldXY, planeEnd)
        tempCirc = self.sec.Duplicate()
        tempCirc.Transform(planeXform)
        geo1 = rg.Extrusion.Create(tempCirc, self.size, True)
        geo1 = geo1.ToBrep(False)

        union = rg.Brep()
        results = union.CreateBooleanUnion([geo0, geo1],
                                           sc.doc.ModelAbsoluteTolerance)
        self.geo = results[0]
Ejemplo n.º 9
0
    def UpdateDisplay(self):
        for id in self.tempIDs:
            sc.doc.Objects.Delete(id, True)

        if self.turned:
            centerPt = self.prevPlane.Origin.Clone()
            centerPt += self.vel
            centerPlane = rg.Plane(centerPt, self.pos, self.prevPlane.Origin)
            circ = rg.Circle(centerPlane, self.size * self.length)
            arc = rg.Arc(circ, math.pi * .5)
            arc = arc.ToNurbsCurve()
            #sc.doc.Objects.AddCurve(arc)
            #self.prevVel.Unitize()

            #arc = rg.Arc(self.prevPlane.Origin, self.prevVel, self.pos)
            #arc = arc.ToNurbsCurve()
            #sc.doc.Objects.AddCurve(arc)
            #tempPlane = rg.Plane(self.prevPlane.Origin, self.prevVel)
            newPlane = self.prevPlane.Clone()
            tempVel = self.prevVel.Clone()
            #tempVel.Reverse()
            tempCenter = self.prevPlane.Origin.Clone()
            tempCenter += tempVel
            newPlane.Origin = tempCenter
            circ = rg.Circle(newPlane, self.size)
            circ = circ.ToNurbsCurve()
            sweep = rg.SweepOneRail()
            if arc and circ:
                breps = sweep.PerformSweep(arc, circ)
                for brep in breps:
                    sc.doc.Objects.AddBrep(brep, self.attr)
        else:
            if len(self.history) > 3:
                circ = rg.Circle(self.plane, self.size)
                cylinder = rg.Cylinder(circ, self.size * self.length)
                cylinder = cylinder.ToBrep(False, False)
                self.pipes.append(cylinder)
                self.pipeIDs.append(sc.doc.Objects.AddBrep(
                    cylinder, self.attr))

        for id in self.ids:
            sc.doc.Objects.Delete(id, True)
Ejemplo n.º 10
0
def from_arc2d(arc, z=0):
    """Rhino Arc from ladybug Arc2D."""
    circle = rg.Circle(from_point2d(arc.c, z), arc.r)
    return rg.Arc(circle, rg.Interval(arc.a1, arc.a2))
Ejemplo n.º 11
0
def getArcCurve(rgCrv0, bTolByRatio=False, fTolRatio=1000.0, fDevTol=1e-9, fMinNewCrvLen=None, fMaxRadius=None):
    """
    Uses a different approach of obtaining the Arc or Circle than Curve.TryGetArc.
    """
    
    sType = rgCrv0.GetType().Name

    if rgCrv0 is None:
        return None, "Geometry not found!  It will be skipped."
    if sType == 'ArcCurve':
        return rgCrv0.DuplicateCurve(), 0.0
    if sType == 'LineCurve':
        return None, "Skipped LineCurve."
    if rgCrv0.IsLinear(1e-9):
        return None, "Skipped linear {}.".format(sType)

    if fMinNewCrvLen is None: fMinNewCrvLen = 10.0*sc.doc.ModelAbsoluteTolerance

    if rgCrv0.IsClosed:
        t0, t1 = rgCrv0.DivideByCount(segmentCount=3, includeEnds=False)[:2]
        rgArcCrv1 = rg.ArcCurve(
            rg.Circle(
                rgCrv0.PointAtStart,
                rgCrv0.PointAt(t0),
                rgCrv0.PointAt(t1),
            )
        )
    else:
        rgArcCrv1 = rg.ArcCurve(
            rg.Arc(
                rgCrv0.PointAtStart,
                rgCrv0.PointAt(
                        rgCrv0.DivideByCount(segmentCount=2, includeEnds=False)[0]),
                rgCrv0.PointAtEnd
            )
        )

    s = ""
    length_crv1 = rgArcCrv1.GetLength()
    if length_crv1 < fMinNewCrvLen:
        s += "Curve is too short"
    
    if fMaxRadius is None:
        modelUnitPerMm = Rhino.RhinoMath.UnitScale(
            Rhino.UnitSystem.Millimeters,
            sc.doc.ModelUnitSystem)
        fMaxRadius = MAX_ACCEPTABLE_SIZE_MM * modelUnitPerMm
    
    if rgArcCrv1.Radius > fMaxRadius:
        if s: s += " and "
        s += "Radius is too large."
    else:
        if s: s += "."
    if s:
        return None, s
    
    rc = rg.Curve.GetDistancesBetweenCurves(
        rgCrv0,
        rgArcCrv1,
        sc.doc.ModelAbsoluteTolerance)
    if not rc[0]:
        return None, "Deviation was not returned from GetDistancesBetweenCurves."
    
    fDev = rc[1]
    
    # Check deviation to tolerance.
    if bTolByRatio:
        fRatio = length_crv1 / fDev
        if fRatio < fTolRatio:
            s  = "Curve was not converted because its (length / deviation) ratio is too small."
            return None, s
    else:
        # Check absolute deviation.
        if fDev > fDevTol:
            return None, fDev
    
    return rgArcCrv1, fDev
Ejemplo n.º 12
0
        # create srf lines as boundary
        surfaceLines = []

        surfaceLines.append(rg.LineCurve(pt1, pt2))
        surfaceLines.append(rg.LineCurve(pt3, pt4))
        # the other boundaries should be arc
        # :: arc(plane, radius, angle)
        # plane's easy
        arcPlane = rg.Plane(ptA, pt2, pt3)
        # compute the angle by feedig the VectorAngle method our points
        # corrected by subtracting the midpoint (axis)
        arcOuterAngle = rg.Vector3d.VectorAngle(pt2 - ptA, pt3 - ptA)
        # an Arc is just a simple structure
        # curve representation of an arc is a Rhino.Geometry.ArcCurve object
        # we create one by passing a Rhino.Geometry.Arc object
        arcOuter = rg.ArcCurve(rg.Arc(arcPlane, radius, arcOuterAngle))
        surfaceLines.append(arcOuter)

        # if stair is 'Wendeltreppe', not 'Spindeltreppe'
        if innerRadius > 0:
            arcInnerAngle = rg.Vector3d.VectorAngle(pt1 - ptA, pt4 - ptA)
            arcInner = rg.ArcCurve(rg.Arc(arcPlane, innerRadius,
                                          arcInnerAngle))
            surfaceLines.append(arcInner)

            # start points for the inner posts
            postPtParam = arcInner.DivideByCount(2, False)
            if i == 0:
                zDistancePost = (arcInner.PointAt(postPtParam[0]).Z) / 2
            ptPostInnerList.append(arcInner.PointAt(postPtParam[0]))