ericnail Posted September 20, 2010 Share Posted September 20, 2010 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 EndifWith 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 More sharing options...
Moderators Melba23 Posted September 20, 2010 Moderators Share Posted September 20, 2010 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)) EndFuncI presume you have a value for the "orientation" of A, so all you have to do is compare it to the results. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
ericnail Posted September 20, 2010 Author Share Posted September 20, 2010 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 More sharing options...
Moderators Melba23 Posted September 20, 2010 Moderators Share Posted September 20, 2010 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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now