Stéphane ANCELOT wrote:
I have already done the same kind of thing but from dxf to svg. have a look at http://sancelot.wordpress.com/2007/07/13/enhanced-dxf2svg/
you will find my code : // create curves points from spline definition void spline::compute_path() { int step = 25; double t,t2,t3; double Cm1,C0,C1,C2;
ctrl_pts r,Pm1,p0,p1,p2; computed_path.clear(); for (int i=0;i< control_points.size() - 3;i++) { Pm1 = control_points[i]; p0 = control_points[i+1]; p1 = control_points[i+2]; p2 = control_points[i+3]; for (int s=0;s<=step;s++) { t = double(s) / (double) step; t2 = t * t; t3 = t2 * t; Cm1 = -1.0/6.0 * t3 + 0.5 * t2 - 0.5 * t + 1.0/6.0; C0 = .5 * t3 - t2 +2.0/3.0; C1 = -.5*t3+.5*t2+.5*t+1.0/6.0; C2 = 1.0/6.0*t3; r.x = Cm1*Pm1.x+C0*p0.x + C1*p1.x+C2*p2.x; r.y = Cm1*Pm1.y+C0*p0.y + C1*p1.y+C2*p2.y; r.z = 0; computed_path.push_back(r); } } }
If this approximates NURB curves with Cubic Bezier Curves this will be a very useful routine. How is it licensed?
Aaron Spike