Possible bug? Intersection of infinite line and NURBS curve fails

Possible bug? Intersection of infinite line and NURBS curve fails

GRSnyder
Collaborator Collaborator
419 Views
3 Replies
Message 1 of 4

Possible bug? Intersection of infinite line and NURBS curve fails

GRSnyder
Collaborator
Collaborator

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}")

 

0 Likes
420 Views
3 Replies
Replies (3)
Message 2 of 4

kandennti
Mentor
Mentor

Hi @GRSnyder .

 

I was curious so I tried it.

I used Line3D instead of InfiniteLine3D and the intersectWithCurve method worked fine.

 

xAxis = core.Line3D.create(
    core.Point3D.create(0,0,0),
    core.Point3D.create(10,0,0)
)

 


Further testing showed that Line3D also has a length limit and would not process correctly if longer.

 

value = 1500625
xAxis: core.Line3D = core.Line3D.create(
    core.Point3D.create(-value,0,0),
    core.Point3D.create(value,0,0)
)

 

The intersectWithCurve method does not seem to work for InfiniteLine3D, and there seems to be a length limit for Line3D as well.

Message 3 of 4

GRSnyder
Collaborator
Collaborator

@kandennti wrote: The intersectWithCurve method does not seem to work for InfiniteLine3D, and there seems to be a length limit for Line3D as well.

I thought this might be the solution, and now that I've followed your lead, I have not seen any more anomalous results.

 

Still... If InfiniteLine3D doesn't support proper intersection computations, it shouldn't have intersectWithCurve in its API.

Message 4 of 4

kandennti
Mentor
Mentor

@GRSnyder -San.

 

I don't know because I can't go back in time, but I believe the InfiniteLine3D.intersectWithCurve method used to work.

 

Considering the issue here, it seems to me that at some point the internal handling of real numbers was changed.

https://forums.autodesk.com/t5/fusion-360-api-and-scripts/bug-addbythreepoints-method-fails-to-creat... 

0 Likes