Splines to Gcode from dxf file

More
4 years 10 months ago #230287 by Grotius
Replied by Grotius on topic Splines to Gcode from dxf file
The testcase :
Code:
void SPLINE_FEED(double x1, double y1, double x2, double y2, double x3, double y3) {     double x0 = 0;     double y0 = 0;     pvec_v.push_back({0,0,0});     for(int i=1; i<=100; i++) {      double t = i / 100.;         double t3 = t*t*t;         double t2 = 3*t*t*(1-t);         double t1 = 3*t*(1-t)*(1-t);         double t0 = (1-t)*(1-t)*(1-t);         double x = x0*t0 + x1*t1 + x2*t2 + x3*t3;         double y = y0*t0 + y1*t1 + y2*t2 + y3*t3;         double z = 0;         pvec_v.push_back({x,y,z});  //black     } } void cubic_bezier_curve(double x1, double y1, double x2, double y2, double x3, double y3){     double x0 = 0;     double y0 = 0;     pvec_s.push_back({0,0,0});     for(int i=1; i<=100; i++) {      double t = i / 100.;         double x=pow((1-t),3)*x0 + 3*t*pow((1-t),2)*x1 + 3* t*t *(1-t)*x2 + t*t*t*x3;         double y=pow((1-t),3)*y0 + 3*t*pow((1-t),2)*y1 + 3* t*t *(1-t)*y2 + t*t*t*y3;         double z = 0;         pvec_s.push_back({x,y,z}); //blue     } }

Result :

I gave them a offset of 1mm in y to show them both.
 
 

Please Log in or Create an account to join the conversation.

More
4 years 10 months ago - 4 years 10 months ago #230290 by Grotius
Replied by Grotius on topic Splines to Gcode from dxf file
But even the cubic splines (red+green) algo's can be improved by making it a "true spline"

The so called "true spline" solution i found ~2~3 years ago while playing with the splines.

The defenition of a "true spline" is a spline wich is identical in both 2 states. The first stage is a forward sweep, the second
stage is a backward sweep. The differential result from time 0-1 is a "true spline".

This type of spline is never used on the stock marked for sure !




 
Last edit: 4 years 10 months ago by Grotius.

Please Log in or Create an account to join the conversation.

More
4 years 10 months ago - 4 years 10 months ago #230325 by Matt Hat
Replied by Matt Hat on topic Splines to Gcode from dxf file
Thanks for being busy on that. Yes it is the Bezier form of a spline. Spline means its a piesewise polynomial that is smooth; thats all. The first argument is the start point, current position P0. The endpt P2 for quadratic feed and P3 for cubic feed. The arguments inbetween are not waypoint/nodes/knots; it is one controlpoint for quadratic and 2 for cubic spline. Task is to figure out the position of the control points to match 'black to 'green curve; fix the boundary constraints.
Then potentially add some code to linuxcnc to scale contributions t2 and t3 accordingly, or pass G5 I,J,P,Q arguments through an additional calculation step.
Last edit: 4 years 10 months ago by Matt Hat.

Please Log in or Create an account to join the conversation.

More
4 years 10 months ago #230331 by Grotius
Replied by Grotius on topic Splines to Gcode from dxf file
Task is to figure out the position of the control points to match 'black to 'green curve;
Ahh.
I found this convert example
But i am stuck at (16)  b=2 c=2. I don't get where they get the b and c values from.
And where they fill in the cubic spline control points.

Please Log in or Create an account to join the conversation.

More
4 years 10 months ago #230333 by Grotius
Replied by Grotius on topic Splines to Gcode from dxf file
It looks like the lcnc master, file : gcodemodule.cc has not the spline code inside anymore.
So it's what any suggested, the code should be somewhere else.
 

Please Log in or Create an account to join the conversation.

More
4 years 10 months ago - 4 years 9 months ago #230365 by Matt Hat
Replied by Matt Hat on topic Splines to Gcode from dxf file
I gave it a further try to resolve the inconsistencies observed. I did commit addition files to
github.com/Matttab/spline-examples


including a translation to GNU octave of SPLINE_FEED for 4 input arguments generating a 2nd order polynomial and for SPLINE_FEED using 6 input arguments generating the most commonly used 3rd order polynomial.

I agree with previous posts - it is a Bezier type of spline going from startpoint at P0=(x0,y0) to the endpoint P3=(x3,y3). The interior points P1 and P2 are not way points, but so-called control points, defining the actual shape of the curve.
File Attachment:

An example fit of one cubic spline segment to 4 way points and the subsequent high-resolution interpolation is given on github.

The required control points can be calculated from the derivatives of your spline at the start and end of each segment. For any G5 move, the first Point x1,y1 will define the initial slope. This should match the slope of any precedent straight line G1 move, or any precedent G5 slope at end point. The second Point x2,y2 will define the end slope. This should match the slope of any subsequent straight line G1 move, or any subsequent G5 slope at start point.

For any repeated and smoothly attached spline segment G5(P,Q), the initial slope will already be defined by the previous G5 P and Q arguments. This is why I,J are only required for the first segment in a multi-segment spline.

As far as I understand it, I,J, P, and Q are actually absolute coordinates. However, I,J relative to x0,y0 define the initial slope and P,Q, relative to x3,y3 define the end slope - that's the relative interpretation.
Last edit: 4 years 9 months ago by Matt Hat. Reason: Corrigenda of code

Please Log in or Create an account to join the conversation.

Time to create page: 0.275 seconds
Powered by Kunena Forum