tyzer

Angle of 2 points

8 posts in this topic

#1 ·  Posted

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

 

Share this post


Link to post
Share on other sites



#2 ·  Posted

angle.jpg

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

"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)

Share this post


Link to post
Share on other sites

#4 ·  Posted

see this,

 


Visit my repository

Share this post


Link to post
Share on other sites

#5 ·  Posted

This might give you an idea:

 

 


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

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

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

On 20/03/2017 at 7:48 AM, jchd said:

"Angle between two points" is an unspecified problem.

180 degrees (*int) :D

Edited by czardas

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

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
1 person likes this

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)

Share this post


Link to post
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