Direction of arc by direction vector

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
bsharp
Newbie
Posts: 16
Joined: Tue Nov 29, 2005 6:39 am
Location: New York

Direction of arc by direction vector

Post by bsharp » Sat Feb 23, 2008 6:32 pm

I need to determine the clockwise or counterclockwise direction of a circle or “arcâ€

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Sat Feb 23, 2008 11:16 pm

I haven't worked with vectors, but this seems logical, just using the Start and End coordinates:
------------------------
If the Y value goes down (Ending Y Start X), it is clockwise (NE quadrant)
If the Y value goes down and the X value decreases, it is clockwise (SE)
If the Y value goes up and the X value decreases, it is clockwise (SW)
If the Y value goes up and the X value increases, it is clockwise (NW)

ELSE
All of the other combos (4 of them) must be counter clockwise
------------------------
The above references are not using screen coordinates, but are using the center of the circle as the X/Y references for increase/decrease.
Last edited by Bob Hansen on Sun Feb 24, 2008 6:43 pm, edited 1 time in total.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

bsharp
Newbie
Posts: 16
Joined: Tue Nov 29, 2005 6:39 am
Location: New York

Post by bsharp » Sun Feb 24, 2008 7:14 am

Ok I am trying to translate an APT 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â€

bsharp
Newbie
Posts: 16
Joined: Tue Nov 29, 2005 6:39 am
Location: New York

Post by bsharp » Fri Feb 29, 2008 10:52 pm

OK I figured out what the "INDRV" values are. They are an incremental distance projected tangentially from the start of the arc. Now what I need to do is some how calculate when the arc center is left or right of the "INDRV" vector. This would give me the direction of the arc. I am trying to use the VBscript "Atn" function to do this but cannot really figure out how. Also in the MS command reference there is "ArcSin" and "ArcCos". If anybody could post an example of how to get an angle from three points it would definitely help me out.

bsharp
Newbie
Posts: 16
Joined: Tue Nov 29, 2005 6:39 am
Location: New York

GetAngle using vector mathematics For MS

Post by bsharp » Sun Mar 02, 2008 10:51 pm

I have resolved my problem. I found an example at VB-Helper.com and converted it to MS. It could save someone a lot of time.
What it does is takes the cords of three points and converts it to an angle.
Using Vector mathematics.

Code: Select all

Let>Ax=%point1x%
Let>Ay=%point1y%
Let>Bx=%point2x%
Let>By=%point2y%
Let>Cx=%point3x%
Let>Cy=%point3y%


// Get the vectors' coordinates.
Let>BAx=%Ax%-%Bx%
Let>BAy=%Ay%-%By%
Let>BCx=%Cx%-%Bx%
Let>BCy=%Cy%-%By%

// DotProduct
// Calculate the dot product.
Let>DotProduct={((%BAx%*%BCx%)+(%BAy%*%BCy%))}

// CrossProduct
// Calculate the Z coordinate of the cross product.
Let>CrossProduct={((%BAx%*%BCy%)-(%BAy%*%BCx%))}


// Get the basic angle.
Let>adj=%DotProduct%
Let>opp=%CrossProduct%

VBEval>Abs(%adj%),adjab

	IF>{(%adjab%<0>angle=%PI%/2
    Else
	VBEval>Atn(%opp%/%adj%),opdad
	VBEval>Abs(%opdad%),opdadab
    Let>angle=%opdadab%
    EndIf

// See if we are in quadrant 2 or 3.
    IF>%adj%<0>angle=%PI%-%angle%
    EndIf

// See if we are in quadrant 3 or 4.
    IF>%opp%<0>angle=-%angle%
    EndIf

// Return the result.
    Let>angler=%angle%
    Let>angled={(%angler%/%PI%)*180}

[/code]

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts