Page 1 of 1

Creating splines using dxflib

Posted: Sat Feb 09, 2008 9:00 pm
by peer9802
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?

Posted: Sun Feb 10, 2008 11:34 pm
by andrew
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));
}