Jump to content

Finding Orientation


ericnail
 Share

Recommended Posts

Finding Orientation.

Okay, So for a math project, I am trying to do this with Autoit:

I am given the coordinates of three locations (A, B, and C) on an XY plane (2D), and I have to find the orientation of A. I am essentially trying to create a calculator via AutoIt where I can input coordinates and find the orientation.

Here's how I'm going to play this out in the presentation:

I am assuming the Coords are GPS Coords, and the Locations (A,B,C) are Vehicles. Vehicle A (Location A) is going to crash into either B or C and the system (Theoretical, My Script) is attempting to find which vehicle, B or C, is going to be struck based on the orientation of Vehicle A.

Here's what I have so far (But i dont know if it's right):

I have to calculate the vectors between locations B and A, and C and A. Then I have to find the angle between those vectors and the X axis, compare the angle's to the orientation of Location A and the closest match will most likely be the Vehicle about to be struck.

i'm trying this:

$alpha = ACos(($Tx-$Mx)/(Sqrt(($Tx-$Mx)^2 + ($Ty-$My)^2)))

If ($Ty-$My) < 0 Then
   $alpha *= -1
Endif

With V1 = T1 - M1 (Ax,Ay = coordinates of the A Location, Bx,By = coordinates of the B Location) and V2 = X-Axis = [1,0]

So Basically, can someone help me find the orientation of these points.

Link to comment
Share on other sites

  • Moderators

ericnail,

This should get you started: ;)

; Insert coords = [X, Y]
Global $aA[2] = [10, 20]
Global $aB[2] = [30, 30]
Global $aC[2] = [20, 10]

; Calculate angles relative to x-axis
$nAB = _CalcAngle($aA, $aB)
ConsoleWrite("Angle A-B = " & $nAB & @CRLF)

$nAC = _CalcAngle($aA, $aC)
ConsoleWrite("Angle A-C = " & $nAC & @CRLF)

Func _CalcAngle($a1, $a2)
    $nRadAngle = ATan(($a2[1] - $a1[1]) / ($a2[0] - $a1[0]))
    Return $nRadAngle * 180 / (4 * ATan(1))
EndFunc

I presume you have a value for the "orientation" of A, so all you have to do is compare it to the results. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

ericnail,

This should get you started: ;)

; Insert coords = [X, Y]
Global $aA[2] = [10, 20]
Global $aB[2] = [30, 30]
Global $aC[2] = [20, 10]

; Calculate angles relative to x-axis
$nAB = _CalcAngle($aA, $aB)
ConsoleWrite("Angle A-B = " & $nAB & @CRLF)

$nAC = _CalcAngle($aA, $aC)
ConsoleWrite("Angle A-C = " & $nAC & @CRLF)

Func _CalcAngle($a1, $a2)
    $nRadAngle = ATan(($a2[1] - $a1[1]) / ($a2[0] - $a1[0]))
    Return $nRadAngle * 180 / (4 * ATan(1))
EndFunc

I presume you have a value for the "orientation" of A, so all you have to do is compare it to the results. :)

M23

WOW!

Thank you!

I have been trying to get it to work for hrs. I was about to give up!

Link to comment
Share on other sites

  • Moderators

ericnail,

My pleasure. ;)

When you reply please use the "Add Reply" button at the top and bottom of the page rather then the "Reply" button in the post itself. That way you do not get the contents of the previous post quoted in your reply and the whole thread becomes easier to read. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...