Brep.CreateFromSweep Gives Crooked Result

Surely I’m overlooking something simple here. Given all the very complicated stuff I do with RhinoCommon and Python, I’m not sure why this is whipping me so hard. Below is a code sample and the results I’m getting vs the results I want. The CreateFromSweep is giving crooked results. The Sweep.PerformSweep is not making anything (and empty array is returned).

#! python 2

import Rhino.Geometry as rg
import scriptcontext as sc
import math

radius1 = 0.5
radius2 = 1.3
radius3 = 1

# set to True to test the SweepOneRail() method,
do_sweep = False

section = rg.Circle(0.5).ToNurbsCurve()
section.Rotate(math.radians(90), rg.Plane.WorldXY.YAxis, rg.Point3d.Origin)
section.Translate(rg.Vector3d(0, radius1 + radius2, 0))
sc.doc.Objects.AddCurve(section)

rail = rg.Ellipse(rg.Plane.WorldXY, radius3, radius2).ToNurbsCurve()
sc.doc.Objects.AddCurve(rail)

if do_sweep:
    # PRODUCES NOTHING
    sweeper = rg.SweepOneRail()
    brep = sweeper.PerformSweep(rail, section)[0]
    sc.doc.Objects.AddBrep(brep)
else:
    # PRODUCES AN UNEXPECTED (CROOKED) RESULT
    brep = rg.Brep.CreateFromSweep(rail, section, True, 0.001)[0]
    sc.doc.Objects.AddBrep(brep)

Hi @webdunce,

How about this?

#! python 3
import Rhino
import scriptcontext as sc

def Test():
    radius1 = 0.5
    radius2 = 1.3
    radius3 = 1.0

    # compute rail
    world_xy = Rhino.Geometry.Plane.WorldXY
    ellipse = Rhino.Geometry.Ellipse(world_xy, radius3, radius2)
    rail = ellipse.ToNurbsCurve()

    # compute section
    domain = rail.Domain
    origin = rail.PointAt(domain.Min)
    normal = rail.TangentAt(domain.Min)
    plane = Rhino.Geometry.Plane(origin, normal)
    circle = Rhino.Geometry.Circle(plane, radius1)
    section = circle.ToNurbsCurve()

    # sweep1
    tolerance = sc.doc.ModelAbsoluteTolerance
    results = Rhino.Geometry.Brep.CreateFromSweep(rail, section, True, tolerance)
    if results:
        for rc in results:
            sc.doc.Objects.AddBrep(rc)
        sc.doc.Views.Redraw()

if __name__ == "__main__":
    Test()

– Dale

It works, but I specifically want the cross section at the end of the ellipse and not at the side.

Ok, I can get this to work, but why? How is this different except creating the circle on it’s own plane. Is that it? We can’t move/rotate the circle into place after creating it? (But oddly, iirc, I was always able to get a fine result if I rotated/moved the circle into the side position, but I get this crooked result if I moved it to the end).

#! python 2
import Rhino
import scriptcontext as sc

def Test():
    radius1 = 0.5
    radius2 = 1.3
    radius3 = 1.0

    # compute rail
    world_xy = Rhino.Geometry.Plane.WorldXY
    ellipse = Rhino.Geometry.Ellipse(world_xy, radius3, radius2)
    rail = ellipse.ToNurbsCurve()

    # move rail start
    p = Rhino.Geometry.Point3d(0, radius2, 0)
    success, t = rail.ClosestPoint(p)
    rail.ChangeClosedCurveSeam(t)
    sc.doc.Objects.AddCurve(rail)

    # compute section

    domain = rail.Domain
    origin = Rhino.Geometry.Point3d(0, radius1 + radius2, 0)
    normal = rail.TangentAt(domain.Min)
    plane = Rhino.Geometry.Plane(origin, normal)
    circle = Rhino.Geometry.Circle(plane, radius1)
    section = circle.ToNurbsCurve()
    sc.doc.Objects.AddCurve(section)

    # sweep1
    tolerance = sc.doc.ModelAbsoluteTolerance
    results = Rhino.Geometry.Brep.CreateFromSweep(rail, section, True, tolerance)
    if results:
        for rc in results:
            sc.doc.Objects.AddBrep(rc)
        sc.doc.Views.Redraw()

if __name__ == "__main__":
    Test()

[edit] But, if you don’t know right off, don’t worry about it too much. I just needed it to work. :slight_smile: Thanks!

The start of the rail should be near the first shape curve.

– Dale