4

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!

Roman Melnyk
  • 1,097
  • 1
  • 8
  • 21
AesculusMaximus
  • 195
  • 3
  • 14

2 Answers2

6

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

Maxence
  • 12,868
  • 5
  • 57
  • 69
  • Yes, thanks Maxence - I've kind of come to the same conclusion. I'm currently trying to use a polyline as you suggested - do you know of any examples that I can see? It looks like as well as the polyline entity, I also need vertex entities. – AesculusMaximus Sep 27 '15 at 17:07
  • If you write a DXF with a version > R12, you can use LWPOLYLINE instead of POLYLINE, you will not need additional VERTEX entities. – Maxence Sep 27 '15 at 17:11
  • I downloaded the code referenced. Holy crap is this code unhelpful. Tried to post it here but it hit the stackoverflow character limit. Regardless to say it is full of typos and variables like: AMag, k NP, Mat, Bx, By, Cx, Cy. No explanation for any of these variables is given anywhere. – Dustin Apr 18 '17 at 02:26
2

While I appreciate this is an old question I thought I'd share my experience. I have found that you can write a spline to a DXF file using only fit points and no control points. I've only done this with open splines, and it might (or probably does) vary with version.

SECTION
2
ENTITIES
0
SPLINE
8
Outline
100
AcDbSpline
70
1032
71
3
72
0
73
0
74
6
44
0.000000001
11
33.98654201387437
21
0.0
31
0.0
11
35.68732510673189
21
0.36908328878159574
31
0.0
11
37.37659045005916
21
1.0707740721032477
31
0.0
11
39.04265824154412
21
2.0149195037916585
31
0.0
11
40.67371568762629
21
3.1732042281057
31
0.0
11
42.25786591112497
21
4.5302062466715505
31
0.0

Group code 70 bit value 1024 allows for fitting to points. I found this little nugget of information on an AutoCAD forum post. I haven't come across it referenced any where else. A bit value of 1 is Closed spline, and 8 is Planar. My value of 1032 is obviously planar, fitting to points and not closed.

Group code 74 is the number of fit points.

Group code 44 is the fit point tolerance.

Group codes 11, 21, 31 are the x, y, z coordinates of the fit points.

See reference manual.