Creating splines using dxflib
Moderator: andrew
-
peer9802
- Registered Member
- Posts: 1
- Joined: Sat Feb 09, 2008 4:44 am
Creating splines using dxflib
What are the steps for creating a spline using dxflib? More specifically, when do I define the spline's knots in relation to calling the writeSpline() function?
Eric
- andrew
- Site Admin
- Posts: 8785
- Joined: Fri Mar 30, 2007 6:07 am
Here's a bit of pseudo code that should be helpful:
Code: Select all
int numKnots = numControlPoints + splineDegree + 1;
int flags;
if (spine is closed) {
flags = 11;
} else {
flags = 8;
}
// write spline header:
dxf.writeSpline(
*dw,
DL_SplineData(spline degree (2 or 3),
numKnots,
numControlPoints,
flags),
attributes
);
// write spline knots:
int k = spline degree + 1;
DL_KnotData kd;
for (int i=1; i<=numKnots; i++) {
if (i<=k) {
kd = DL_KnotData(0.0);
} else if (i<=numKnots-k) {
kd = DL_KnotData(1.0/(numKnots-2*k+1) * (i-k));
} else {
kd = DL_KnotData(1.0);
}
dxf.writeKnot(*dw, kd);
}
// write spline control points:
for each control point {
dxf.writeControlPoint(*dw, DL_ControlPointData(x, y));
}