Jump to content

Angle of 2 points


 Share

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)
        $radToDeg = 180 / $pi
        $y = ATan($Quotient) * $radToDeg
        $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)
        $radToDeg = 180 / $pi
        $y = ATan($Quotient) * $radToDeg
        $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)
        $radToDeg = 180 / $pi
        $y = ATan($Quotient) * $radToDeg
        $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)
        $radToDeg = 180 / $pi
        $y = ATan($Quotient) * $radToDeg
        $y = $y + 90
        $y = $y - 180
        Return $y
    EndIf
EndFunc

 

Link to comment
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.

(Also upper 91 and 90 are badly placed in your drawing)

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
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)

Link to comment
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.

 

Angles.jpg

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
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)

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...