CNC engraving machines use a language called GCode to describe movements of the x,y plane. Here is a small example :
G01 X7.2 Y-0.3 (the position of the start of the arc)
G03 X6.8 Y-0.2 I-0.4 J-3.3 (the end of the arc and it's relative centre point)
This says go to 7.2, -0.3 and draw an anticlockwise arc TO 6.8, -0.2 the arc is centred at (6.8 - 0.4), (-0.2 - (-3.3))
I'm trying to replace the arc (G03 command) with a series of interpolated simple points (G01) commands.
To do this I begin by calculating the :
radius $\sqrt( i^2 + j^2 )$
chord $\sqrt(( x - previous X)^2 + (y - previous Y) ^2 )$
Theta (angle of whole arc) $arcos( 1 - (chord ^ 2) / (2 * (radius ^ 2) )$
The angle at the start of the arc $atan2(previous Y - arc Centre X, previous X - arc Centre Y)$
One suspects the atan2 may be part of the problem as something is PI radians out of place?
Now I can divide up theta into a number of sub angles, then starting from the start angle I can add that sub angle, and recalculate a new point on the arc as follows :
for n times:
co = radius * cos(startangle - some nth of theta)
si = radius * sin(startangle - some nth of theta)
x of new point on arc is (arc centre x + co)
y of new point on arc is (arc centre y + si)
But I get this!
You can see that the arc is calculated correctly but is 180 degrees wrong. That is, it is convex, where it should be concave!
Can anyone just point me at roughly where I've made a mistake? I would show my whole code but my question wouldn't be cogent. I've been at this for 6 hours and I haven't managed to change anything that has fixed this. Perhaps a mathematician will just look at this and know what the issue is?
Thanks for your time.
