$getangle is just what it sounds like, it retrieves the angle of any two points using triangles and trigonometry.
Updates:
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
;Made by BlueThen
;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)