# Angle of 2 points

## Recommended Posts

Can someone post me a function whicb returns an angle after I gave the function two X/Y coordinates.

The angle it should return should be in a specific format, guess this picture will explain it better

Till now I used this function which works in most cases but sometimes it returns in angle which leads to the opposite direction

```Func _CalcAngle(\$PosX, \$PosY, \$targetPosX, \$targetPosY)
If \$PosX < \$targetPosX And \$PosY < \$targetPosY Then
\$gegenkathete = \$PosX - \$targetPosX
\$ankathete = \$PosY - \$targetPosY
\$Quotient = \$ankathete / \$gegenkathete
\$x = ATan(0.5)
\$pi = 4 * ATan(1)
\$y = \$y + 90
\$y = \$y - 180
\$y = \$y * -1
\$y = \$y - 180
\$y = \$y * -1
Return \$y
ElseIf \$PosX < \$targetPosX And \$PosY > \$targetPosY Then
\$gegenkathete = \$PosX - \$targetPosX
\$ankathete = \$PosY - \$targetPosY
\$Quotient = \$ankathete / \$gegenkathete
\$x = ATan(0.5)
\$pi = 4 * ATan(1)
\$y = \$y + 90
\$y = \$y - 180
\$y = \$y * -1
\$y = \$y - 180
\$y = \$y * -1
Return \$y
ElseIf \$PosX > \$targetPosX And \$PosY > \$targetPosY Then
\$gegenkathete = \$PosX - \$targetPosX
\$ankathete = \$PosY - \$targetPosY
\$Quotient = \$ankathete / \$gegenkathete
\$x = ATan(0.5)
\$pi = 4 * ATan(1)
\$y = \$y + 90
\$y = \$y - 180
Return \$y
ElseIf \$PosX > \$targetPosX And \$PosY < \$targetPosY Then
\$gegenkathete = \$PosX - \$targetPosX
\$ankathete = \$PosY - \$targetPosY
\$Quotient = \$ankathete / \$gegenkathete
\$x = ATan(0.5)
\$pi = 4 * ATan(1)
\$y = \$y + 90
\$y = \$y - 180
Return \$y
EndIf
EndFunc```

##### Share on other sites

"Angle between two points" is an unspecified problem.

Rephrase your question with "angle between two lines (or vectors)" and you'll get correct answers.

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

##### Share on other sites

see this,

Visit my repository

##### Share on other sites

This might give you an idea:

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

##### Share on other sites
On 20/03/2017 at 7:48 AM, jchd said:

"Angle between two points" is an unspecified problem.

180 degrees (*int)

Edited by czardas
##### Share on other sites

What I mean is that, given only points A and B there are two very different angles one may consider.

The first is α the angle formed by vectors from the origin O to point A and to point B. The angle α doesn't depend on the length of vectors OA and OB as soon as A and B are distinct from O.
The second angle may be the angle γ between a reference direction (say North for instance) and the line AB.
Note that then B is moved to B' this angle becomes β while at the same time, α remains constant.

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

@jchd = best

## Create an account

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

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