# Identify the direction of arc's

1. Feb 24, 2008

### bsharp

I am trying to translate a file from one format to another. The file I am trying to read from gives me the coordinates of arcs like this.

A three arc circle going clockwise:
GOTO / 0.80353, -0.60825, 0.75000, 0.000000, 0.000000, 1.000000
INDIRV/ -0.86603, 0.50000, 0.00000
TLON,GOFWD/ (CIRCLE/ 0.86603, -0.50000, 0.75000,$0.12500),ON,(LINE/ 0.86603, -0.50000, 0.75000,$
0.92853, -0.39175, 0.75000)
INDIRV/ 0.86603, -0.50000, 0.00000
TLON,GOFWD/ (CIRCLE/ 0.86603, -0.50000, 0.75000,$0.12500),ON,(LINE/ 0.86603, -0.50000, 0.75000,$
0.97428, -0.56250, 0.75000)
INDIRV/ -0.50000, -0.86603, 0.00000
TLON,GOFWD/ (CIRCLE/ 0.86603, -0.50000, 0.75000,$0.12500),ON,(LINE/ 0.86603, -0.50000, 0.75000,$
0.80353, -0.60825, 0.75000)
The same three arc circle going counterclockwise:
GOTO / 0.80353, -0.60825, 0.75000, 0.000000, 0.000000, 1.000000
INDIRV/ 0.86603, -0.50000, 0.00000
TLON,GOFWD/ (CIRCLE/ 0.86603, -0.50000, 0.75000,$0.12500),ON,(LINE/ 0.86603, -0.50000, 0.75000,$
0.92853, -0.39175, 0.75000)
INDIRV/ -0.86603, 0.50000, 0.00000
TLON,GOFWD/ (CIRCLE/ 0.86603, -0.50000, 0.75000,$0.12500),ON,(LINE/ 0.86603, -0.50000, 0.75000,$
0.75777, -0.43750, 0.75000)
INDIRV/ -0.50000, -0.86603, 0.00000
TLON,GOFWD/ (CIRCLE/ 0.86603, -0.50000, 0.75000,$0.12500),ON,(LINE/ 0.86603, -0.50000, 0.75000,$
0.80353, -0.60825, 0.75000)

The “GOTO” command is a linear move followed by it’s cords “X,Y,Z”
The “INDRV” is from what I can figure is a direction vector “X,Y,Z”?
The TLON,GOFWD line specifies the arc center cords “X,Y,Z”
The line after specifies the radius “0.12500” and arc center cords
The next line specifies the ending cords “X,Y,Z”.

Some how I need to determine the direction of each arc. I have tried comparing the starting and ending cords but it will not always work.
If the arc is 360 deg the “INDRV” cord will be positive or negative the corresponding arc center cord.
I think I have to calculate the direction from the “INDRV” based on the starting or ending cords some how.
If you look at the last arc in each example the only thing different is the starting cords “the ending cords from the previous arc”. If some one could help me out with this it would be great.

2. Oct 24, 2009

### bsharp

Since not one sole answered this ugly question. And after asking a thirty year mechanical engineer veteran and also a 4 year degree physics major.
This is how I solved it on my own. Once plotted out on a graph it is a lot more obvious. Just calculate the angle from the Direction Vector to the center of the arc. This will basically be two vectors. One being the direction vector start point to arc start point and the second as arc start to arc center. Once you can reliably calculate the angle it will be a negative value for one direction and a positive value for the opposite.

http://www.vb-helper.com/howto_find_angles.html
Basically the sign of the solution will give you the direction.
It also works irregardless of quadrant position in Cartesian space.

3. Dec 15, 2009

### mugaliens

Looks like BasicA... But no, it's VB.

4. Dec 15, 2009

### bsharp

The "three arc circle" code posted above is actualy APT
http://en.wikipedia.org/wiki/APT_%28programming_language%29

I wrote a translator in VB to convert APT code to G code http://en.wikipedia.org/wiki/G-code.
The problem I was having with the arc direction was that in G code the direction is specified in a prefix of ether G03 "cw" or G02 "ccw" and in APT the arc direction is specified by a direction vector's relationship with the arc points. so to translate the "APT" arc direction vector to the "G code" equivalent prefix. I needed to calculate the angle between the direction Vector and the Arc points and the sign of the angle will determine the direction "cw or ccw". With this it is easy in VB to say "If arcsign <0 than gcode = G03" or something like that.
It took a lot of learning and turning of some pretty rusty gears but I got it and now I am proud to say I have a G code post processor that I wrote myself and is faster and more precise than any commercial one out there.