From 1eaa88aa3400aa8ab730da13e8a094122dca6a53 Mon Sep 17 00:00:00 2001 From: Kestin Goforth Date: Thu, 4 Aug 2022 05:03:05 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20arc=20length=20calculation?= =?UTF-8?q?=20for=20G3=20arcs=20(#4606)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/octoprint/util/gcodeInterpreter.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/octoprint/util/gcodeInterpreter.py b/src/octoprint/util/gcodeInterpreter.py index fa217e73f..3437b5c63 100644 --- a/src/octoprint/util/gcodeInterpreter.py +++ b/src/octoprint/util/gcodeInterpreter.py @@ -546,13 +546,17 @@ class gcode: centerArc = Vector3D(oldPos.x + i, oldPos.y + j, oldPos.z) startAngle = math.atan2(oldPos.y - centerArc.y, oldPos.x - centerArc.x) endAngle = math.atan2(pos.y - centerArc.y, pos.x - centerArc.x) + arcAngle = endAngle - startAngle if gcode in ("G2", "G02"): startAngle, endAngle = endAngle, startAngle + arcAngle = -arcAngle if startAngle < 0: startAngle += math.pi * 2 if endAngle < 0: endAngle += math.pi * 2 + if arcAngle < 0: + arcAngle += math.pi * 2 # from now on we only think in counter-clockwise direction @@ -588,9 +592,7 @@ class gcode: e = 0 # calculate 3d arc length - arcLengthXYZ = math.sqrt( - (oldPos.z - pos.z) ** 2 + ((endAngle - startAngle) * r) ** 2 - ) + arcLengthXYZ = math.sqrt((oldPos.z - pos.z) ** 2 + (arcAngle * r) ** 2) # move time in x, y, z, will be 0 if no movement happened moveTimeXYZ = abs(arcLengthXYZ / feedrate)