Message 1 of 4
Possible bug? Intersection of infinite line and NURBS curve fails
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
The script below creates an InfiniteLine3D along the X axis and a NurbsCurve3D that crosses the X axis, then tries to find the intersection between them. The ObjectCollection returned by intersectWithCurve is empty and has isValid = False. But as you can see from the control point list, the first and last control points are on opposite sides of the X axis. Ergo, there must be at least one intersection.
This script also drops the NURBS curve into a sketch for inspection. It does indeed cross the X axis and does not seem to be obviously degenerate.
I came across this example while working on a plugin. The failure seems to be very sensitive to small changes in the NURBS curve. Similar NURBS curve intersect just fine.
import adsk.core as core
def run(context):
controlPointLocations = (
(1.0382420785505115, -0.19906879586801662, 0.0),
(1.091221357440538, -0.2028979898241481, 0.0),
(1.2019294749929175, -0.17614526689165622, 0.0),
(1.3591815391529505, -0.08979604064901484, 0.0),
(1.453986254831052, -0.005557307652588498, 0.0),
(1.4993914337017116, 0.04272386384592807, 0.0)
)
knots = (0.0, 0.0, 0.0, 0.0, 0.2946409650556092, 0.6280567830695798, 1.0, 1.0, 1.0, 1.0)
controlPoints = [core.Point3D.create(*cpl) for cpl in controlPointLocations]
nurbsCurve = core.NurbsCurve3D.createNonRational(controlPoints, 3, knots, False)
origin = core.Point3D.create(0, 0, 0)
direction = core.Vector3D.create(1, 0, 0)
xAxis = core.InfiniteLine3D.create(origin, direction)
intersections = xAxis.intersectWithCurve(nurbsCurve)
app = core.Application.get()
component = app.activeProduct.activeComponent
sketch = component.sketches.add(component.xYConstructionPlane)
sketch.sketchCurves.sketchFixedSplines.addByNurbsCurve(nurbsCurve)
ui = app.userInterface
ui.messageBox(f"There are {len(intersections)} intersections and isValid is {intersections.isValid}")