Open krcwrhvgyxzqelljes opened 5 months ago
Yea, there is definitely something wrong. I'll figure it out.
The first two were specified incorrectly, but there were still several bugs that had to be fixed after I corrected them. There is still something weird going on with the second failure that I need to figure out. Also, the ending point of the first shape should always be the starting point of the second shape, sometimes it will work even if the end and start aren't the same point. There's no situation where this would happen with a CNC path because if it did it would mean the machine would have to teleport from one location to another.
I think Shape was probably a bad name for these classes. They're not just shapes, but paths with a beginning and end. The end of the first path needs to be the beginning of the second path. For lines, the start and end points are the first and second parameter. For arcs the start point is defined by the center point, radius, and theta_0. The end point is defined by those variables in addition to the rads param. It represents the length of the arc in radians. Positive if the arc moves counter-clockwise from the start point, or negative if it moves clockwise.
// Fails:
//auto shape1 = Line(clothoid::vec2(50.0, 0.0), clothoid::vec2(-50.0, 0.0)); // this ends at -50, 0
//auto shape2 = Arc(50, 0, M_PI, clothoid::vec2(0.0, 0.0)); // this starts at 50, 0
// corrected paths, works
//auto shape1 = Line(clothoid::vec2(50.0, 0.0), clothoid::vec2(-50.0, 0.0)); // this ends at -50, 0
//auto shape2 = Arc(50, M_PI, -M_PI, clothoid::vec2(0.0, 0.0)); // this starts at -50, 0
// Fails:
//auto shape1 = Arc(50, M_PI, 2*M_PI, clothoid::vec2(0.0, 5.0)); // this ends at -50, 5
//auto shape2 = Arc(50, 0, M_PI, clothoid::vec2(0.0, 0.0)); // this starts at 50, 0
// corrected paths, but still fails unless the t1 param of fit_biclothoid is near 1
auto shape1 = Arc(50.0, M_PI, 2*M_PI, clothoid::vec2(0.0, 5.0)); // this ends at -50, 5
auto shape2 = Arc(50.0, M_PI, -M_PI, clothoid::vec2(0.0, 0.0)); // this starts at -50, 0
// works now
//auto shape1 = Line(clothoid::vec2(0.0, -100.0), clothoid::vec2(0.0, 0.0));
//auto shape2 = Arc(50, M_PI, M_PI, clothoid::vec2(50.0, 0.0));
// works now
//auto shape1 = Line(clothoid::vec2(0.0, -100.0), clothoid::vec2(0.0, 0.0));
//auto shape2 = Arc(50, M_PI, -M_PI, clothoid::vec2(50.0, 0.0));
Oh I forgot that there are also additional constraints to this algorithm which is why that case with the two arcs would fail. The length of the second shape has to be greater than or equal to the length of the first shape, and the curvature of the second shape must be less than or equal to the curvature of the first shape. Anything can still be solved though by manipulating the shapes first.
There should be something between the CNC paths and this library that does these transformations automatically.
From the paper:
The start point of the biclothoid will be on Q1 and
its end point will reside on Q2. The biclothoid has G2-
continuity with both Q1 and Q2 which means that the
tangent angle and the curvature of the biclothoid at its
start point are equal to the tangent angle and curvature
of Q1. The same is true for the end point of the biclothoid
where it joins Q2 with G2-continuity. Without loss of gen-
erality it is assumed that the arc length of Q2 is greater
than or equal to the arc length of Q1 and the curvature of
Q2 is smaller than or equal to the curvature of Q1. These
two assumptions do not add any restrictions to the prob-
lem: if Q1 is longer than Q2, then part of Q1 can be cut
away to make the lengths equal, and if Q2 has a greater
curvature than Q1, the two shapes can be simply swapped.
In the end i was first only printing the line and arc shapes with matplotlib without the clothoid calculations to validate my input.