Cubic Spline Standard API Lines of Code to find y given x

Cubic Spline Standard API Lines of Code to find y given x

tperam
Advocate Advocate
747 Views
4 Replies
Message 1 of 5

Cubic Spline Standard API Lines of Code to find y given x

tperam
Advocate
Advocate

 

Given a set of 5 points (x[0], y[0]), (x[1], y[1]),  up to (x[4],y[4]), what are the standard API lines Code,
preferably in C++ to find y given x using Cubic Spline or other curve fitting?

 

Regards,
Thurai

0 Likes
Accepted solutions (1)
748 Views
4 Replies
Replies (4)
Message 2 of 5

KrisKaplan
Autodesk
Autodesk

Thurai,

 

I would think the most direct route would be to create a non-rational NurbsCurve3D (with NurbsCurve3D.createNonRational). Use 'degree = 3' for cubic. Then create a Plane (with Plane.create) with a point at your fixed x value (e.g. [x, 0, 0]) and a normal perpendicular to y and the plane of the curve (z in this case) (normal=[1, 0, 0]). You could then use Plane.intersectWithCurve to get the intersection points between the spline and the plane.

 

Note that depending on where you get the x values from, that can be zero or multiple intersection points.

 

Also, this is assuming that the points you have define the Bezier control frame of the spline. If you wanted to specify points along the curve, then that would require using a curve fitting algorithm. The transient geometry API does not expose a fit point based nurbs curve creation method. So you would either need to include or write your own. Or you could create a SketchFittedSpline in a sketch and obtain the NurbsCurve3D from it.

 

Kris



Kris Kaplan
Message 3 of 5

tperam
Advocate
Advocate

Hi Kris,
Intersection of a plane with a curve will work. It is a good suggestion.

 

I was thinking of the standard direct approach of solving the cubic equation,

 

y = ai * (x - xi)^3 + bi * (x - xi)^2 + ci(x - xi) + di,

 

and determining the coefficients ai, bi, ci and di, by writing the expressions for them in terms of y', y''

and determine y, by solving a set of linear equations given x.

 

I was thinking that Fusion 360 has this direct functionality as part of the API objects,
as in CurveEvaluator3D and getPointAtParameter or getParameterAtPoint.

 

If there are such objects and there are a few lines of Sample Code Example please let me know.

 

Any way your suggestion of drawing a spline and using intersectionWithCurve by a plane will work as well.

 

Thanks Kris.

 

0 Likes
Message 4 of 5

KrisKaplan
Autodesk
Autodesk
Accepted solution

No. The curve evaluator does not provide something like that. There is evaluation from curve parameters and model space. But these parameters are linear values in 'curve space' (with ranges like [0, 1], [-pi, pi], etc...).

 

You could use the curve evaluations to iterate to the solutions. For example, iterate through parameter space converging on the model space coordinate value desired (ideally using the tangent and curvature to control step direction and speed). Or use the 'closest point on curve' method to walk towards the intersection (repeatedly clamping the x value of the closest point and repeating, but be careful about getting stuck in an equidistant node). But it would be much more efficient and proven to use the plane-curve intersection (for a geometric solution). And if you want a mathematics solution, you could roll your own 'cubic specific' solution like you mentioned, or use perhaps a toll like Mathematica.

 

Kris



Kris Kaplan
0 Likes
Message 5 of 5

tperam
Advocate
Advocate

Thanks Kris.

 

Regards,

Thurai

0 Likes