# Calculate the angle with given coordinates

## Recommended Posts

Hey,

I have a math question:

How do I calculate the angle with given coordinates?

I made a drawing, because I already knew that I couldn't explain:

I hope that says enough

Edited by kip

##### Share on other sites

```\$pt1x = InputBox("Input coordinate pt","Point A X coor", "", "");will be your reference point.
\$pt1y = InputBox("Input coordinate pt","Point A Y coor", "", "")

\$pt2x = InputBox("Input coordinate pt","Point B X coor", "", "")
\$pt2y = InputBox("Input coordinate pt","Point B Y coor", "", "")

\$pt3x = InputBox("Input coordinate pt","Point C X coor", "", "")
\$pt3y = InputBox("Input coordinate pt","Point C Y coor", "", "")

\$dist1x = \$pt1x - \$pt2x
\$dist1y = \$pt1y - \$pt2y
\$x1 = \$dist1x * \$dist1x
\$y1 = \$dist1y *\$dist1y
\$T1 = \$x1 + \$y1
\$Tdist1 = Sqrt(\$T1)

\$dist2x = \$pt1x - \$pt3x
\$dist2y = \$pt1y - \$pt3y
\$x2 = \$dist2x * \$dist2x
\$y2 = \$dist2y *\$dist2y
\$T2 = \$x2 + \$y2
\$Tdist2 = Sqrt(\$T2)

\$xy = \$Tdist1 / \$Tdist2
\$pi = 3.14159265358979
\$Tangle = ACos(\$xy) * \$radToDeg;arcCosine of -1 returns 180°

MsgBox(0, "Angle", "the Angle =" & " " & \$Tangle)```

I think this one...for right triangle only..

Edited by LiLShinta

##### Share on other sites

Hey,

I have a math question:

How do I calculate the angle with given coordinates?

I made a drawing, because I already knew that I couldn't explain:

I hope that says enough

The angle P+Q is

ATAN((D-B )/(C-A))

the angle P is

ATAN((F-B )/(E-A))

so Q is

ATAN((D-B )/(C-A)) - ATAN((F-B )/(E-A))

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

##### Share on other sites

hmm...

yeah.. I dont get that.

I tried several things but I just can't get it to work.

This is my script, but i dont know how to get the angle of the Line:

```#include <GUIConstants.au3>

\$ControlX = 200
\$ControlY = 200

\$AngleWidth = 100

\$Gui = GUICreate("sdsds",400,400)

GUICtrlCreateGraphic(0, 0, 400, 400)
GUICtrlSetGraphic(-1,\$GUI_GR_COLOR, 0x000000)

GUICtrlSetGraphic(-1,\$GUI_GR_ELLIPSE, \$ControlX-(\$AngleWidth/2),\$ControlY-(\$AngleWidth/2), \$AngleWidth,\$AngleWidth)

\$Graph = GUICtrlCreateGraphic(\$ControlX-(\$AngleWidth/2), \$ControlY-(\$AngleWidth/2), \$AngleWidth, \$AngleWidth)

GUICtrlSetGraphic(-1,\$GUI_GR_MOVE, \$AngleWidth/2,\$AngleWidth/2)
GUICtrlSetGraphic(-1,\$GUI_GR_COLOR, 0xff)
GUICtrlSetGraphic(-1,\$GUI_GR_LINE, \$AngleWidth/2,0)
GUICtrlSetGraphic(-1,\$GUI_GR_REFRESH)

\$Label = GUICtrlCreateLabel("",5,5,100,16)

GUISetState()

global \$pi = 4 * ATan(1)

While 1

\$Pos = GUIGetCursorInfo(\$Gui)
\$mX = \$Pos[0]
\$mY = \$Pos[1]

GUICtrlDelete(\$Graph)
\$Graph = GUICtrlCreateGraphic(\$ControlX-(\$AngleWidth/2), \$ControlY-(\$AngleWidth/2), \$AngleWidth, \$AngleWidth)

\$Pyth = Sqrt((\$mX-\$ControlX)^2 + (\$mY-\$ControlY)^2)

\$NewLenght = \$Pyth/(\$AngleWidth/2)

\$LineX = (\$AngleWidth/2)+(\$mX-\$ControlX)/\$NewLenght
\$LineY = (\$AngleWidth/2)+(\$mY-\$ControlY)/\$NewLenght

GUICtrlSetGraphic(-1,\$GUI_GR_MOVE, (\$AngleWidth/2),(\$AngleWidth/2))
GUICtrlSetGraphic(\$Graph,\$GUI_GR_LINE, \$LineX,\$LineY)
GUICtrlSetGraphic(\$Graph,\$GUI_GR_REFRESH)

\$Angle = "?"

GUICtrlSetData(\$Label, \$Angle & "°")

WEnd```

And I dont know how to use Sin, Cos, Tan, etc

\$Label should show the angle (0°-360°)

Edited by kip

##### Share on other sites

Got it!

```#include <GUIConstants.au3>

\$ControlX = 200
\$ControlY = 200

\$AngleWidth = 48

\$Gui = GUICreate("sdsds",400,400)

GUICtrlCreateGraphic(0, 0, 400, 400)
GUICtrlSetGraphic(-1,\$GUI_GR_COLOR, 0x000000)

GUICtrlSetGraphic(-1,\$GUI_GR_ELLIPSE, \$ControlX-(\$AngleWidth/2),\$ControlY-(\$AngleWidth/2), \$AngleWidth,\$AngleWidth)

\$Graph = GUICtrlCreateGraphic(\$ControlX-(\$AngleWidth/2), \$ControlY-(\$AngleWidth/2), \$AngleWidth, \$AngleWidth)

GUICtrlSetGraphic(-1,\$GUI_GR_MOVE, \$AngleWidth/2,\$AngleWidth/2)
GUICtrlSetGraphic(-1,\$GUI_GR_LINE, \$AngleWidth/2,0)
GUICtrlSetGraphic(-1,\$GUI_GR_REFRESH)

\$Label = GUICtrlCreateLabel("",5,5,100,16)

GUISetState()

global \$pi = 4 * ATan(1)

\$Previous = 0

While 1

\$Pos = GUIGetCursorInfo(\$Gui)
\$mX = \$Pos[0]
\$mY = \$Pos[1]

\$Pyth = Sqrt((\$mX-\$ControlX)^2 + (\$mY-\$ControlY)^2)

\$NewLenght = \$Pyth/(\$AngleWidth/2)

\$LineX = (\$AngleWidth/2)+(\$mX-\$ControlX)/\$NewLenght
\$LineY = (\$AngleWidth/2)+(\$mY-\$ControlY)/\$NewLenght

\$WidthLine = \$mX-\$ControlX
\$HeightLine = \$ControlY-\$mY

\$Round = Abs(Round(\$ATan,0))

\$MidX = \$mX-\$ControlX
\$MidY = \$mY-\$ControlY

If \$MidX >= 0 Then; 0 - 180

If \$MidY <= 0 Then; 0 - 90
\$Angle = 90-\$Round
Else; 90 - 180
\$Angle = 90+\$Round
EndIf

Else; 180 - 360

If \$MidY >= 0 Then; 180 - 270
\$Angle = 180+(90-\$Round)
Else; 270 - 360
\$Angle = 270+\$Round
EndIf

EndIf

If \$Angle <> \$Previous Then
GUICtrlSetData(\$Label, \$Angle & "°")

GUICtrlDelete(\$Graph)
\$Graph = GUICtrlCreateGraphic(\$ControlX-(\$AngleWidth/2), \$ControlY-(\$AngleWidth/2), \$AngleWidth, \$AngleWidth)

GUICtrlSetGraphic(\$Graph,\$GUI_GR_MOVE, (\$AngleWidth/2),(\$AngleWidth/2))
GUICtrlSetGraphic(\$Graph,\$GUI_GR_LINE, \$LineX,\$LineY)
GUICtrlSetGraphic(\$Graph,\$GUI_GR_REFRESH)
\$Previous = \$Angle
EndIf

WEnd```
Edited by kip

## Create an account

Register a new account

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...