Calculate spline length

1
mberube09
1/29/2020 1:49 PM

Hi!

I am relatively new to the CadLib (trying it out as we speak but will buy it for sure for a client of mine), and i'm trying to calculate the length of a spline. Found some algorithms that interpolate the spline with multiple points and i'm trying to convert them to C# but they are quite difficult to understand.

I was wondering thought if there was already something that could help me in the lib, my guess is yes since it's kind of what need to be done to draw the spline, but I tried browsing the library and the forum and couldn't find anything.

Thank you for the help!

Wout
1/29/2020 2:34 PM

It is possible to approximate it only. Are your referring to the SPLINE entity (class DxfSpline)?

- Wout

mberube09
1/29/2020 2:49 PM

Yes exactly the DxfSpline, approximate should be good enough in that case.

Wout
1/30/2020 12:52 AM

Hi,

The spline rendering wasn't quite fit for this scenario yet, but I've changed the implementation a little and added a method DxfSpline.GetApproximationPolyline(double epsilon), where you can specify an absolute value (positive) or a relative value (negative) for the precision.

Note that if you need to take into account scaling by insertions (by an INSERT entity for example), then you probably should do a complete render and intercept the output. See the GetCoordinates example in the Examples directory. You can specify the epsilon through GraphicsConfig.ShapeFlattenEpsilon.

I've updated the CadLib trial version, but not the .NET Core version on NuGet yet.

- Wout

mberube09
1/30/2020 2:27 PM

Wow it looks exactly like what I needed. Thanks very much for the quick update.


Side note: The trial setup keeps being block by windows defender smart screen.

Wout
1/30/2020 3:23 PM

Just a caveat: the code is fairly fresh and it hasn't been tested thoroughly yet.

Polyline3D has a GetLength() method, so you can directly call that.

- Wout

Wout
2/14/2020 1:30 PM

I've just fixed a problem in the spline rendering/length calculation that potentially caused a hangup for some splines. I recommend downloading the latest version.

- Wout

mberube09
2/14/2020 1:47 PM

Thank you very much!

1