I'm trying to create a spline curve programmatically in a dxf file. I need to use fit points as the curve needs to pass through the specified points. I understand I also need to use control points. Is there a formula to calculate what these should be? It is a closed spline with four fit points.
Thanks in advance!
I think this is not an easy task. In addition to the control points, you will also need to determine the knots. There is a DXF reader/viewer here (written in C++) which claims to support spline. May be you can find some information by reading the code.
AutoCAD uses NURBS which are approximated curves (the curve pass only by the first and last points). In the user interface, splines are interpolated (the curve pass by the fit points), so there is a translation which is done when reading/writing a DXF file. If you create a closed point with 4 fit points, you will see there is 7 controls points in the DXF file:
Using a polyline to approximate your spline will be easier. Here is a sample of a polyline (L shape starting from 0,0 -> 100, 0 -> 100, 50)
0
LWPOLYLINE
5
D5
330
70
100
AcDbEntity
8
0
100
AcDbPolyline
90
3
70
0
43
0.0
10
0.0
20
0.0
10
100.0
20
0.0
10
100.0
20
50.0
To compute the position of the control points from the fit points, you can consult this page (§24 & §25). In fact you need to reverse the Casteljau's algorithm (for Bezier curves; I don't know how it works for NURBS).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With