Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a dxf spline curve using fitpoints?

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!

like image 489
AesculusMaximus Avatar asked Feb 09 '23 23:02

AesculusMaximus


1 Answers

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:

Fit points vs control points

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).

like image 118
Maxence Avatar answered Mar 15 '23 17:03

Maxence