.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Spline Length

9 REPLIES 9
Reply
Message 1 of 10
SRSDS
2513 Views, 9 Replies

Spline Length

Hi,

Is there a way to determine the length of a spline?

9 REPLIES 9
Message 2 of 10
hgasty1001
in reply to: SRSDS

Hi,

 

Look here: Curve Length , and also here: Quirky Polylines for more enlightenment.

 

Gaston Nunez

 

 

Message 3 of 10

Hi Gasty, the code at the first link you referenced is not terribly robust. It will fail on curves that have no length (e.g., Rays and XLines), and assumes that the caller is passing the result of the 'as' operator to cast the object to a Curve, but not retaining the reference to the Curve (or having to do that again), and it doesn't leverage extension methods.

 

This extension method will return a bool to indicate if the a length was acquired, or false if not, and will set the result parameter to the curve's length.  You can use this method on any Curve without it throwing an exception, but you should still filter those types that consistently do not produce a result (like Rays and XLines), to avoid the higher cost of having to catch many thrown exceptions.

 

 

public static class CurveExtensions
{
   public static bool TryGetLength( this Curve curve, out double result )
   {
      try
      {
         result = curve.GetDistanceAtParameter( curve.EndParam ) -
            curve.GetDistanceAtParameter( curve.StartParam );
         return true;
      }
      catch( Autodesk.AutoCAD.Runtime.Exception )
      {
         result = 0.0;
         return false;
      }
   }
}

 

 

Message 4 of 10

Hi Tony,

 

You are right, just had the link to spiderman in my references without checking. Nice way to go with that Tony.

 

Regards,

 

Gaston Nunez

Message 5 of 10

Hi,

 

>> curve.GetDistanceAtParameter( curve.StartParam )

May I ask what condition has to exist that this calculation will result in a value n.e. 0.0?

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 6 of 10

Try calling it on an Arc whose start angle is != 0.0

Message 7 of 10

Hi,

 

>> Try calling it on an Arc whose start angle is != 0.0

Well, tried, my result is 0.0 as you can see in the screenshot (that shows the debug-info from an arc with start-angle and end-angle != 0.0)

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 8 of 10

It is the StartParameter that is not always 0.0.  

 

The result of GetDistanceAtParameter() with the curve's start parameter is usually 0.0, but I have seen cases where it isn't, which involved custom objects derived from AcDbCurve, that return a non-zero value, and getting the actual length requires the algorithm shown, so it is designed to ensure that the actual distance is calculated, even if the distance at the start parameter is non-zero, which is an assumption I don't recommend relying on if dealing with custom objects.

 

 

Message 9 of 10

Hi,

 

>> The result of GetDistanceAtParameter() with the curve's start parameter is usually 0.0

That was my question, when this result gives != 0.0.

So the arc you suggested does return 0.0 for you too?

 

>> but I have seen cases where it isn't, which involved custom objects derived from AcDbCurve

In that case the custom objects returns a wrong value. And if it returns a defect length at the startparam I also would not trust any other calculation returned by GetDistanceAtParameter(), so also for the endparam. With other words the length calculation in that case might be wrong anyway and not to be trusted.

 

At least I never have seen that this return not 0.0 and so I'm wondering about that calculation within your function.

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 10 of 10


@Alfred.NESWADBA wrote:

Hi,

 

>> The result of GetDistanceAtParameter() with the curve's start parameter is usually 0.0

That was my question, when this result gives != 0.0.

So the arc you suggested does return 0.0 for you too?

 

- alfred -


No, actually I mistakenly thought you were asking about the value of the StartParameter, which is non-zero for arcs and some other objects.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost