Fix G2/G3 rounding error (#15507)
This commit is contained in:
parent
2cf35267c4
commit
d8aeeb8ff6
@ -285,12 +285,13 @@ void GcodeSuite::G2_G3(const bool clockwise) {
|
|||||||
if (r) {
|
if (r) {
|
||||||
const xy_pos_t p1 = current_position, p2 = destination;
|
const xy_pos_t p1 = current_position, p2 = destination;
|
||||||
if (p1 != p2) {
|
if (p1 != p2) {
|
||||||
const xy_pos_t d = p2 - p1, m = (p1 + p2) * 0.5f; // XY distance and midpoint
|
const xy_pos_t d2 = (p2 - p1) * 0.5f; // XY vector to midpoint of move from current
|
||||||
const float e = clockwise ^ (r < 0) ? -1 : 1, // clockwise -1/1, counterclockwise 1/-1
|
const float e = clockwise ^ (r < 0) ? -1 : 1, // clockwise -1/1, counterclockwise 1/-1
|
||||||
len = d.magnitude(), // Total move length
|
len = d2.magnitude(), // Distance to mid-point of move from current
|
||||||
h = SQRT((r - d * 0.5f) * (r + d * 0.5f)); // Distance to the arc pivot-point
|
h2 = (r - len) * (r + len), // factored to reduce rounding error
|
||||||
const xy_pos_t s = { d.x, -d.y }; // Inverse Slope of the perpendicular bisector
|
h = (h2 >= 0) ? SQRT(h2) : 0.0f; // Distance to the arc pivot-point from midpoint
|
||||||
arc_offset = m + s * RECIPROCAL(len) * e * h - p1; // The calculated offset
|
const xy_pos_t s = { -d2.y, d2.x } / len; // Unit vector along perpendicular bisector
|
||||||
|
arc_offset = d2 + s * e * h; // The calculated offset (mid-point if |r| <= len)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user