Creating splines using dxflib

Use this forum to ask questions about how to do things in dxflib.

Moderator: andrew

Creating splines using dxflib

Postby peer9802 » Sat Feb 09, 2008 9:00 pm

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
peer9802
Registered Member
 
Posts: 1
Joined: Sat Feb 09, 2008 4:44 am

Postby andrew » Sun Feb 10, 2008 11:34 pm

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));
}
User avatar
andrew
Site Admin
 
Posts: 2677
Joined: Fri Mar 30, 2007 6:07 am


Return to dxflib 'How Do I' Questions

Who is online

Users browsing this forum: No registered users and 1 guest