# \$GetAngle 2.0

### By BlueThen on May 06, 2008

\$getangle is just what it sounds like, it retrieves the angle of any two points using triangles and trigonometry.

Fixed an error where the angle is sometimes off by 20 degrees.

(April 12, 2009)
Completely recreated the identifier. The previous \$getangle was extremely buggy and slow. It should now be fairly accurate, and a lot faster also. Additionally, I added \$dist. \$dist finds the distance between any 2 given x y points. It has the same syntax as \$getangle (x1,y1,x2,y2).

Feel free to modify/use/whatever with this script. I made it using common trigonometry, so no need to really credit me on the whole thing... (doesn't mean you don't have to though :))

``````;\$GetAngle 2.0
;It'll return the angle of any 2 points.
;Syntax: \$getangle(P1x,P1y,P2x,P2y)
;Dist 1.1
;(April 12) Added \$Dist. Returns the distance betweens two points. \$getangle won't work without this now!
;Syntax: \$dist(P1x,P1y,P2x,P2y)
alias getangle {
%opp = \$dist(\$1, \$2, \$1, \$4)
%hyp = \$dist(\$3, \$4, \$1, \$2)
%adj = \$dist(\$1, \$2, \$3, \$4)
%angle = \$asin(\$calc(%opp / %hyp)).deg
if ((%opp == 0) && (\$3 < 200)) {
%angle = 180
return %angle
}
if ((\$3 > \$1) && (\$4 < \$2)) return %angle
if (%adj == %hyp) && (%hyp == %opp) {
if (\$4 > \$2) %angle = 270
else %angle = 90
return %angle
}
if ((\$4 < \$2) && (\$3 < \$1)) { %angle = \$calc(180- %angle) | return %angle }
if ((\$4 > \$2) && (\$3 > \$1)) { %angle = \$calc(360- %angle) | return %angle }
if ((\$4 > \$2) && (\$3 < \$1)) inc %angle 180
return %angle
}
alias dist return \$calc(((\$3 - \$1)^2+(\$4 - \$2)^2)^0.5)
``````

BlueThen   -  Apr 12, 2009

Recreated it. Now a lot faster, and now you shouldn't be getting any more wrong angles. :) I also added \$dist, which finds the distance between any 2 points. This is required for \$getangle to work. Feel free to use and modify.

sercan386   -  Mar 14, 2009

why so long? it can be turned into an one line script... no need for all those variables

SumWon   -  May 12, 2008

Awesome, you fixed it =D! Thanks again for sharing this!

Jonesy44   -  May 10, 2008

Nice one, never got round to using this ident yet :P

BlueThen   -  May 10, 2008

Updated. I\'ve been getting some complaints saying that it was off by 20 or so degrees every now and then. So after about a hour of looking, I finally found out that the length wasn\'t accurate...

So now it\'s fixed. ;)

Noutrious   -  May 07, 2008

Respecting this not only because of the good coding, but of the mathematical skills too - i couldn\'t figure this out actually.

Jonesy44   -  May 06, 2008

Good stuff, i\'ll no doubt need this for my next picwin .. when i try it haha !
But it\'ll be pretty hard i guess.

Promise ya don\'t steal it, but i think i\'ll need a simple one of newton\'s laws to work it ;D

BlueThen   -  May 06, 2008

Oh, I forgot. This was originally was an experimentation, but someone wanted it.

^Neptune   -  May 06, 2008

This could be really useful for picwin makers. Good job. Try making the variables local (var %variable), it\'s nice to stop the variables bit clogging up. :)

BlueThen   -  May 06, 2008

Aw, someone rated it a 4.

Sorry it\'s not a cool picwin or anything, but it honestly took me hours to find this out.

Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.