spline length

spline length

Anonymous
Not applicable
31,408 Views
26 Replies
Message 1 of 27

spline length

Anonymous
Not applicable

Hi

How can i find the Spline length by means of its control points manually? (I do not mean AREA command, I want to calculate it by its control points manually)

In fact how AUTODESK calculate it?

0 Likes
Accepted solutions (1)
31,409 Views
26 Replies
Replies (26)
Message 2 of 27

Kent1Cooper
Consultant
Consultant

The only thing you'd be able to calculate manually from control points [or fit points] would be the sum of the straight-line  distances between them, which of course is not the length of the Spline.  I couldn't say how AutoCAD does it, but I don't think there's anything you could use from ordinarily-available information like entity data.  [May I ask why you want to do this?]

Kent Cooper, AIA
0 Likes
Message 3 of 27

Anonymous
Not applicable

 

B(t).pngThere is a formula as  follows: (https://en.wikipedia.org/wiki/B%C3%A9zier_curve)

This formula and Autocad return same value for 4 control point but for higher control point we have some mistake

 

0 Likes
Message 4 of 27

SEANT61
Advisor
Advisor

AutoCAD uses a Degree 3 spline as default.  If there are only 4 Control points then the spline is equivalent to a Bezier curve.  CPs more than four either need an elevated order (Degree 4, 5, . . . ) to evaluate correctly with that formula, or you have to treat them as B-Splines and/or NURBS.

 

https://en.wikipedia.org/wiki/B-spline


************************************************************
May your cursor always snap to the location intended.
0 Likes
Message 5 of 27

leeminardi
Mentor
Mentor

The default order for splines of more than 4 CVs is 3.  You can modify the order and the weights at CVs of a spline with the SPLINEDIT command. You can also use SPLINEDIT to find the approximate length by converting the spline to a polyline  (SPLINEDIT P ) and specify the precision.  Use LIST to find the length of the resulting polyline.  Experiment with the precision value to determine its sensitivity.

 

lee.minardi
0 Likes
Message 6 of 27

SEANT61
Advisor
Advisor

@leeminardi wrote:

The default order for splines of more than 4 CVs is 3. . . . .

 

 

Did you actually mean "the default order for splines of 4 or more CVs is 4"?  Which is to say "Degree 3", in that Degree is Order - 1.


************************************************************
May your cursor always snap to the location intended.
0 Likes
Message 7 of 27

leeminardi
Mentor
Mentor

Yes, I meant to say degree equals three. Thanks for noticing my misstatement.

lee.minardi
0 Likes
Message 8 of 27

Anonymous
Not applicable

Thanks friends but i cant calculate it by bezier or B-Spline formula

A simple example is given control poni P0=1,1 P1=2,0 P3=3,1 P4+4,0 and P5=5,1 Can you calculate y parameter in X=2?

0 Likes
Message 9 of 27

Corsten.Au
Advisor
Advisor

This would be a complete different approach..

but if CAD is imported in REVIT software ( Autodesk ), 

Revit gives the length of the Spline directly...

 

Spline LengthSpline Length

Corsten
Building Designer
Message 10 of 27

SEANT61
Advisor
Advisor

@Anonymous wrote:

Thanks friends but i cant calculate it by bezier or B-Spline formula

A simple example is given control poni P0=1,1 P1=2,0 P3=3,1 P4+4,0 and P5=5,1 Can you calculate y parameter in X=2?


This may be a misread on my part; this example isn't looking for the length of anything, just needs the y coordinate of a given X. 

In the attached drawing I have a setup to find the point graphically.  In the attached spreadsheet, I solve for the point parametrically - with a calculated parameter t=0.25


************************************************************
May your cursor always snap to the location intended.
0 Likes
Message 11 of 27

Kent1Cooper
Consultant
Consultant

@Corsten.Au wrote:

.... if CAD is imported in REVIT software ( Autodesk ), Revit gives the length of the Spline directly...


 

If all they needed was to get the length of an already-drawn Spline, there's certainly no need to go through importing it into Revit!  Either the LIST or AREA command will report it, and  put the value in the PERIMETER System Variable for use in any processing or calculation desired.  Or it can be extracted with AutoLisp:
(vlax-curve-getDistAtParam spl (vlax-curve-getEndParam spl))

where 'spl' is either  the Spline's entity name or a VLA-object conversion of that.

 

But they don't want to do it that way [re-read Message 1].

Kent Cooper, AIA
0 Likes
Message 12 of 27

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

... A simple example is given control poni P0=1,1 P1=2,0 P3=3,1 P4+4,0 and P5=5,1 Can you calculate y parameter in X=2?


 

So maybe that's something  of an answer to my question in Message 2 [at least it's some kind of reason for wanting to calculate something based on control points], except that it has nothing to do with the Subject line or the original question in Message 1, both being about length, which seems irrelevant to this example.  Though the Bezier-curve formulas are beyond my mathematical experience, I'd still be interested in the "why" of it all....

Kent Cooper, AIA
0 Likes
Message 13 of 27

leeminardi
Mentor
Mentor

@SEANT61 I created a spline using the CV method with the specified control points and got the green curve as opposed to your magenta curve. The magenta curve is a 4th degree (5th order) Bezier spline whereas I believe the green curve is a 3rd degree B-Spline.   Yes?

 

I've looked at the B-spline math and I find it a bit tough to follow. Since a B-spline allows local editing, can I assume only the first 4 CVs influence the shape of the spline near the beginning?  At what point must the 5th CV be considered?

lee.minardi
0 Likes
Message 14 of 27

SEANT61
Advisor
Advisor

@leeminardi wrote:

@SEANT61 I created a spline using the CV method with the specified control points and got the green curve as opposed to your magenta curve. The magenta curve is a 4th degree (5th order) Bezier spline whereas I believe the green curve is a 3rd degree B-Spline.   Yes?

 

I've looked at the B-spline math and I find it a bit tough to follow. Since a B-spline allows local editing, can I assume only the first 4 CVs influence the shape of the spline near the beginning?  At what point must the 5th CV be considered?


Yes, I believe you are referring to a B-spline.  Is it the same as the green spline I have in the attached?  And, yes again, everything after Beziers becomes increasingly more complex.  Not something I ready to set up in an XLS, anyway.

 

The local editing you mentioned was the motivation for B-splines, and I believe your notion of where/when CVs are evaluated is correct.  There is not much visual evidence when the evaluation rules switch from one group of CVs to the next.  AutoCAD will show us the point on the curve if the 3d Osnap Knot is enabled.

 

The process becomes even more chaotic when non uniform domains, full multiplicities, rationality are injected.  Just with a slight domain modification see how the blue spline differs from the green.

 

Fortunately, the average programmer does not have to re-invent the 'nurbs evaluation' wheel.  AutoCAD, at least, has the functionality baked into the API.  If someone did want to roll their own, though, I would applaud the effort.

 


************************************************************
May your cursor always snap to the location intended.
0 Likes
Message 15 of 27

SEANT61
Advisor
Advisor

@leeminardi wrote:

. . . .  At what point must the 5th CV be considered?


The way the splines are evaluated is by stepping through the parametric Range, t,  a small increase at a time.  The incremental t value is plugged into the equations which spit out an xyz value.  Much like the spreadsheet setup I posted earlier, at any given t the influence of each of the 4 CVs (in this case) varies.
 
The Range, though, is split into different zones with Knots at the border.  When a Knot value in reached, the influence of the earliest CV of the 4 goes to zero, and no longer play a part, and the next CV (4th from the CV just removed) in line starts to contribute to the equation.  Minimally at first, but increasing as the t values progress.
 
See the attached drawing and chart.  This 8 CV AutoCAD spline has a Knot Vector (Nurbs term) as shown in the diagram.  The Points in the drawing correspond to the Knot values shown in that grouping.  The term Full Multiplicity refers to when a value is repeated Degree number of times.  That indicates to the algorithm to uses the corresponding CV for %100 of the influence.  It is why the AutoCAD curve lands directly on the start and end CV.  As t increases from 0, the next 3 CVs start contributing to the equation.  Notice how the curves on the chart start rising from the initial 0 influence state.
Chart.PNG
At any point along that horizontal (X) of the Chart, a vertical line will intersect several curves, all of the Y values will total 1.0 (%100) .  Notice, also,  that at each knot value, one curve ends while another starts.

 


************************************************************
May your cursor always snap to the location intended.
0 Likes
Message 16 of 27

Anonymous
Not applicable

in fact i need the equation of the spline, i request the y factor in x=2 to check the equation

0 Likes
Message 17 of 27

leeminardi
Mentor
Mentor

As noted in post #3 by @SEANT61, if you created a spline with 5 control points the AutoCAD default would be a 3rd degree (4th order) B-spline. For the points you specified in post #8 the spline should look like the green curve in the image below.  The equation for a B-spline can be found in the link of post #4.  Check it out if you have not yet done so.  The math is more complex than a Bezier spline encouraging the use of recursion (deBoors algorithm) to calculate points on the spline.

bspl1.JPG 

You asked for the value of y when x = 2 (in Euclidean and not parametric space I assume).  Set luprec to 8 and then add a point at the intersection of the line and the original spline using object snap int (intersection).  The B-spline will be accurately evaluated. You should find that the coordinates of the point are: x = 2.00000000, y = 0.39061808.

 

As I noted in post #5 the splinedit command can be used to convert a spline to a polyline. This will give you a series of points along the spline.

 

 

lee.minardi
0 Likes
Message 18 of 27

Anonymous
Not applicable

Thank you and other friends, all of the those formula seem true but when i want to use them the answer and Autocad are not equal.

Do you calculated y=0.39061808 by means of those formula or bring that from Autocad?

0 Likes
Message 19 of 27

SEANT61
Advisor
Advisor
Accepted solution
Here’s a crude setup to investigate the ins and outs of a uniform, degree 3 B-Splines.  This spreadsheet works with the general setup shown in post# 8.  It allows variable point locations (though the point count must remain at 5), as well variations in the target “X” value.
I’ve used a Lookup table to convert that target X to the appropriate parameter value; consequently, the tolerance is quite coarse.
 
 

************************************************************
May your cursor always snap to the location intended.
Message 20 of 27

leeminardi
Mentor
Mentor

@sean61 congrats on getting something that works!  I've been trying to write a custom VBA function for the deBoor algorithm that uses recursion to calculate the coefficients.  I gave up on that and decided to limit the B-spline to degree 3 which enables a simpler computation from the appropriate 4 CVs and then successive sub control polygons.   My subscripts are all screwed up so I put it aside while I tend to more pressing matters. I may give it another shot in the future.  

 

Lee

lee.minardi