#### View Issue Details

ID Project Category View Status Date Submitted Last Update 0002606 Path [FreeCAD] Feature public 2016-06-29 13:43 2018-02-08 15:36 sliptonic normal minor always new open all all all [FreeCAD] 0.18 [FreeCAD] 0.18 0002606: need an R to IJ conversion function for preprocessors In Gcode, an arc is usually described like 'G2 X10 Y10 I15 J15' where XY are coordinates for the end point. IJ are offsets to the arc center point G2 (or G3) indicate whether the arc turns clockwise (or ccw) around the axis. However, it's valid in gcode to describe an arc withhout the IJ values and instead pass in an R value indicating the Radius. In this case, the controller is responsible for calculating the center point given the start, end, and radius. When importing gcode through a preprocessor script, we should not store the Path commands with the R value but should calculate the IJ values and store those. Rather than implement this in ever preprocessor script, we need an R to IJ calculation function that can be used everywhere. I think this is related to issue #2605 Path commands should always be stored in relative form but may be imported as absolute. No tags attached.

#### Relationships

 related to 0002605 closed yorik Support for G90.1 / G91.1 codes

#### Activities

 2016-06-29 19:59 administrator   ~0007161 When #2605 is done, the Path module will support both relative and absolute IJK. So it won't matter which one is used here (as long as the proper G91.1 code is inserted when needed of course) 2016-06-30 00:09 administrator   ~0007162 http://www.linuxcnc.org/docs/html/gcode/g-code.html#_radius_format_arcs 2016-06-30 00:23 administrator   ~0007163 I think this should do it (untested): # let's say we have 2 vectors, startpoint and endpoint, and radius (the value of R) import math chord = endpoint.sub(startpoint) # we take a vector between the 2 points perp = chord.cross(FreeCAD.Vector(0,0,1)) # we take its perpendicular - we can assume the arc is in the XY plane plength = math.sqrt(radius**2 + (chord.Length/2)**2) # pythagoras formula, to get the length perp needs perp.normalize() perp.scale(plength,plength,plength) # relative center center = chord.scale(0.5,0.5,0.5).add(perp) # we add the perp at the midpoint of the chord to find the center # absolute center abscenter = startpoint.add(center) 2016-07-02 15:42 developer   ~0007166 Doesn't seem to be calculating quite right. Here's a test rig macro and output. =========Macro============= import math import Path def RtoIJ(startpoint, endpoint, radius):     chord = endpoint.sub(startpoint) # we take a vector between the 2 points     perp = chord.cross(FreeCAD.Vector(0,0,1)) # we take its perpendicular - we can assume the arc is in the XY plane     plength = math.sqrt(radius**2 + (chord.Length/2)**2) # pythagoras formula, to get the length perp needs     perp.normalize()     perp.scale(plength,plength,plength)     # relative center     relativecenter = chord.scale(0.5,0.5,0.5).add(perp) # we add the perp at the midpoint of the chord to find the center     print "relative center: " + str(relativecenter)     print "calculated I:" + str(relativecenter.x)     print "calculated J:" + str(relativecenter.y)     # absolute center     abscenter = startpoint.add(relativecenter)     print "absolute center: " + str(abscenter)      lastcommand = Path.Command("G01 X-29.992999999999999 Y36.941000000000003 Z0 ") command = Path.Command("G02 I11.183 J-8.4209999999999994 X-7.835 Y37.212000000000003 Z0") Rad = math.hypot(command.I,command.J) print "Calculated Radius: " + str(Rad) #returns about 14 as expected print "startpoint: " + str(lastcommand.Placement.Base) print "endpoint: " + str(command.Placement.Base) print "original I: " + str(command.I) print "original J: " + str(command.J) RtoIJ(lastcommand.Placement.Base, command.Placement.Base , Rad) =========Macro============= =========output============= Calculated Radius: 13.9990260375 startpoint: Vector (-29.993, 36.941, 0.0) endpoint: Vector (-7.835, 37.212, 0.0) original I: 11.183 original J: -8.421 relative center: Vector (11.297333993057345, -17.716325159279247, 0.0) calculated I:11.2973339931 calculated J:-17.7163251593 absolute center: Vector (-18.695666006942652, 19.224674840720755, 0.0) =========output=============

#### Issue History

Date Modified Username Field Change
2016-06-29 13:43 sliptonic New Issue
2016-06-29 13:44 sliptonic Category Bug => Feature
2016-06-29 19:57 yorik Relationship added related to 0002605
2016-06-29 19:59 yorik Note Added: 0007161
2016-06-30 00:09 yorik Note Added: 0007162
2016-06-30 00:23 yorik Note Added: 0007163
2016-07-02 15:42 sliptonic Note Added: 0007166
2017-01-29 21:45 Kunda1 Additional Information Updated View Revisions
2018-02-08 15:36 sliptonic Product Version 0.17 => 0.18
2018-02-08 15:36 sliptonic Target Version 0.17 => 0.18