I'm trying to work out a way to intrepret g-code into an SVG image. I can imagine to work with coordinates easily to draw straight lines, but I am struggling with arcs. I can't figure out how to interpret the I J system as an arc in SVG.
(ORIGIN=BOTTOM LEFT)
(METRIC)
G71
(RELATIVE)
G91
M16
(PART 1)
G00X-74.7Y585.5
M15
G01X-1.0Y0.0
G02X-735.2Y736.2I0.4J735.6
G01X10.0Y0.0
G01X0.0Y75.0
G01X501.2Y0.0
G01X0.0Y-75.0
G01X10.0Y0.0
G03X215.0Y-215.0I214.4J-0.6
G01X0.0Y-10.0
G01X75.0Y0.0
G01X0.0Y-501.2
G01X-75.0Y0.0
G01X0.0Y-10.0
M16
(PARK)
It's my understanding for the code above, it's relative, so I would start at -74,585 followed by moving -1,0 then start an arc that ends -735.2,736.2 away from the start of the arc. The arc centre would be based on the I and J information. As this is relative, is the I and J relative to the start of the arc?
For the centre of the arc, how would this translate to svg arcs? Am I right in thinking that for a SVG bezier curve (Q) the control point is on the 'outside' of the curve, whereas for the g-code the centre would be on the inside?
I can parse the data that I have and generate the following SVG:
<svg viewBox="-820 -35 4283 1441">
<path class="path" d="M-74,585 -75,585" style="stroke:black;stroke-width:5"></path>
<path class="path" d="M-75,585 Q -810 1321 -810 1321" style="fill:none;stroke:black;stroke-width:5"></path>
<path class="path" d="M-810 1321 -800,1321" style="stroke:black;stroke-width:5"></path>
<path class="path" d="M-800,1321 -800,1396" style="stroke:black;stroke-width:5"></path>
<path class="path" d="M-800,1396 -299,1396" style="stroke:black;stroke-width:5"></path>
<path class="path" d="M-299,1396 -299,1321" style="stroke:black;stroke-width:5"></path>
<path class="path" d="M-299,1321 -289,1321" style="stroke:black;stroke-width:5"></path>
<path class="path" d="M-289,1321 Q -74 1106 -74 1106 " style="fill:none;stroke:black;stroke-width:5"></path>
<path class="path" d="M-74 1106 -74,1096" style="stroke:black;stroke-width:5"></path>
<path class="path" d="M-74,1096 1,1096" style="stroke:black;stroke-width:5"></path>
<path class="path" d="M1,1096 1,595" style="stroke:black;stroke-width:5"></path>
<path class="path" d="M1,595 -74,595" style="stroke:black;stroke-width:5"></path>
<path class="path" d="M-74,595 -74,585" style="stroke:black;stroke-width:5"></path>
<path class="path" d="M-74,585 -74,585" style="stroke:red;stroke-width:10"></path>
</svg>
I've not added the script I'm using to generate this (written in PHP) as it's verbose and pulls data from a database so wouldn't really help. The orientation is wrong, but I can fix that up with a transform on the overall SVG. The lines responsible for the arc have the Q in them and it's the control point value that I can't for the life of me mathematically work out based on the I J values for the point in the g-code. Any help or advice would be greatly appreciated.