From cd7cf1b712f9f43af3eeb141e041768c8d6a410c Mon Sep 17 00:00:00 2001 From: Oleg Belov Date: Fri, 7 Jan 2022 21:12:37 +0300 Subject: [PATCH] Path: Fix simulator bug workaround while milling curves with small radius. Path Simulator produces out of trace artifacts while milling curves with small radius. In VolSim.cpp the branch for curve radius smaller then tool radius is not implemented yet. In this condition the simulator produces artifacts of higher radius while milling path using G2 or G3. There is an implementation of G2 and G3 in python level. --- src/Mod/Path/PathScripts/PathSimulatorGui.py | 27 ++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/Mod/Path/PathScripts/PathSimulatorGui.py b/src/Mod/Path/PathScripts/PathSimulatorGui.py index 28b478c627..116e230357 100644 --- a/src/Mod/Path/PathScripts/PathSimulatorGui.py +++ b/src/Mod/Path/PathScripts/PathSimulatorGui.py @@ -165,7 +165,8 @@ class PathSimulation: maxlen = self.stock.BoundBox.XLength if maxlen < self.stock.BoundBox.YLength: maxlen = self.stock.BoundBox.YLength - self.voxSim.BeginSimulation(self.stock, 0.01 * self.accuracy * maxlen) + self.resolution = 0.01 * self.accuracy * maxlen + self.voxSim.BeginSimulation(self.stock, self.resolution) ( self.cutMaterial.Mesh, self.cutMaterialIn.Mesh, @@ -343,7 +344,29 @@ class PathSimulation: # for cmd in job.Path.Commands: if cmd.Name in ["G0", "G1", "G2", "G3"]: self.firstDrill = True - self.curpos = self.voxSim.ApplyCommand(self.curpos, cmd) + if cmd.Name in ['G2', 'G3'] and (cmd.k or 0) == 0: + cx = self.curpos.Base.x + (cmd.i or 0) + cy = self.curpos.Base.y + (cmd.j or 0) + a0 = math.atan2( self.curpos.Base.y - cy, self.curpos.Base.x - cx ) + a1 = math.atan2( cmd.y - cy, cmd.x - cx ) + da = a1 - a0 + if cmd.Name == 'G3': + da = da % (2 * math.pi) + else: + da = -((-da) % (2 * math.pi)) + r = math.sqrt( (cmd.i or 0) ** 2 + (cmd.j or 0) ** 2 ) + n = math.ceil( math.sqrt( r / self.resolution * da * da ) ) + da = da / n + dz = (cmd.z - self.curpos.Base.z) / n + cmd.Name = 'G1' + for i in range( n ): + a0 += da + cmd.x = cx + r * math.cos( a0 ) + cmd.y = cy + r * math.sin( a0 ) + cmd.z = self.curpos.Base.z + dz + self.curpos = self.voxSim.ApplyCommand(self.curpos, cmd) + else: + self.curpos = self.voxSim.ApplyCommand(self.curpos, cmd) if not self.disableAnim: self.cutTool.Placement = self.curpos (