Hi All,
I have been banging my head against this simple bit of code for the better part of today and I only seem to find more issues.
What I’m trying to do is to take a closed curve. Generate a shape with two arcs and a line and sweep it along that curve. My code for this is shown here:
import Rhino
import rhinoscriptsyntax as rs
import math
import scriptcontext
def _makeArcFromAngle(plane, cPoint, radius, startAngle, endAngle):
center = plane.PointAt(cPoint[0], cPoint[1])
circ = Rhino.Geometry.Circle(plane, center, radius)
angleInt = Rhino.Geometry.Interval(startAngle, endAngle)
arc = Rhino.Geometry.Arc(circ, angleInt)
return arc
def getMidpointFromCrv(crv):
dom = crv.Domain
return dom.Mid
def buildSharpBoss1(crv, radius):
curve = rs.coercecurve(crv)
if not curve:
return 0
subcurves = curve.DuplicateSegments()
if len(subcurves)>1:
focCurve = subcurves[0]
else:
focCurve = curve
focCrvMidpoint = getMidpointFromCrv(focCurve)
zVector = Rhino.Geometry.Vector3d(0,0,1)
xDir = Rhino.Geometry.Vector3d.CrossProduct(focCurve.TangentAt(focCrvMidpoint),zVector)
plane = Rhino.Geometry.Plane(focCurve.PointAt(focCrvMidpoint), xDir,zVector)
lArc = _makeArcFromAngle(plane, (-radius, radius), radius, 3*math.pi/2, 2*math.pi)
rArc = _makeArcFromAngle(plane, (radius, radius), radius, math.pi, 3*math.pi/2)
profile = Rhino.Geometry.PolyCurve()
profile.Append(lArc)
profile.Append(rArc)
baseLine = Rhino.Geometry.Line(profile.PointAtEnd,profile.PointAtStart)
profile.Append(baseLine)
sweepBrep = Rhino.Geometry.Brep.CreateFromSweep(curve,profile,True,scriptcontext.doc.ModelAbsoluteTolerance)
output = []
for i in sweepBrep:
output.append(scriptcontext.doc.Objects.AddBrep(i))
scriptcontext.doc.Views.Redraw()
return output
if __name__ == "__main__":
for i in rs.SelectedObjects():
if rs.IsCurve:
buildSharpBoss1(i,1)
Using that code with this model:
Sweep Glitch Demo.3dm (841.3 KB)
I get the result shown in this image:
Is this a glitch? I’d expect maybe the sweep would go out of control, but this doesn’t seem to make any sense to me. If I go in and push the profile back out to the document and just hit sweep1 with the default options everything looks great.