Here’s my problem in a nutshell… I’m trying to get an angle based on the position of the mouse in relation to an element on the page, but I’m running into an issue with the Math.tan() function.
Here’s my equation for getting the angle to the X and Y coordinates:
[CODE]
newAngle = Math.round(Math.pow(Math.tan( y / x ), -1) * (180 / 3.141))
I get the tan of y over x (opposite over adjacent), raise to the -1 to get the angle (I know this works in degrees, seems like it would have to with radians),
then multiply it by (180 / 3.141) to convert from radians to degrees. And then I round it.
Seems like it should work fine to me however, if
y = 200
x = 20.5
The result in JavaScript is 167, but if I punch it into my calculator (set on degrees: tan( 200 / 20.5 ) ^ -1) I get 5.815948
So there’s got to be something wrong with my formula. I’d appreciate the help!