View Issue Details
ID  Project  Category  View Status  Date Submitted  Last Update 

0002606  Path  Feature  public  20160629 13:43  20200106 16:29 
Reporter  sliptonic  Assigned To  
Priority  normal  Severity  minor  Reproducibility  always 
Status  feedback  Resolution  open  
Platform  all  OS  all  
Product Version  0.18  
Target Version  0.19  
Summary  0002606: need an R to IJ conversion function for preprocessors  
Description  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.  
Additional Information  I think this is related to issue 0002605 Path commands should always be stored in relative form but may be imported as absolute.  
Tags  No tags attached.  
FreeCAD Information  

When 0002605 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) 

http://www.linuxcnc.org/docs/html/gcode/gcode.html#_radius_format_arcs 

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) 

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 X29.992999999999999 Y36.941000000000003 Z0 ") command = Path.Command("G02 I11.183 J8.4209999999999994 X7.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============= 

Hey @sliptonic what's the status of this ticket? Thanks. 
Date Modified  Username  Field  Change 

20160629 13:43  sliptonic  New Issue  
20160629 13:44  sliptonic  Category  Bug => Feature 
20160629 19:57  yorik  Relationship added  related to 0002605 
20160629 19:59  yorik  Note Added: 0007161  
20160630 00:09  yorik  Note Added: 0007162  
20160630 00:23  yorik  Note Added: 0007163  
20160702 15:42  sliptonic  Note Added: 0007166  
20170129 21:45  Kunda1  Additional Information Updated  View Revisions 
20180208 15:36  sliptonic  Product Version  0.17 => 0.18 
20180208 15:36  sliptonic  Target Version  0.17 => 0.18 
20190122 05:14  sliptonic  Status  new => feedback 
20190122 05:14  sliptonic  Target Version  0.18 => 0.19 
20200106 16:29  Kunda1  Note Added: 0014001 