Click to See Complete Forum and Search --> : TAN-1

05-25-2002, 01:28 PM
I'm trying to figure out the angle between an object and a pont. on paper, the equation is :


TAN -1 is reversed TAN. How do I do it in Flash?


Little Ben
05-27-2002, 10:31 AM
I think Math.atan(number) gives inverse tan in radians.

To convert radians to degrees:

degrees = (radians/Math.PI) * 180;

05-28-2002, 05:50 AM
Math.tan(Number) gives you the tandgent of a number between -ve PI/2 and +vePI/2.
This only give you a value within 2 quadrants ( so i am lead to belive) i have never used or seen this used in flash, if anyone has an example where this would be usefull please share, as i am trying to re-learn alot of Maths

Math.Atan2(y,x) will give you a angle in radians through the full 4 quadrants (i.e full circle).

Here are the conversion equations i use:


Hope this helps

06-18-2002, 04:51 PM
I just did this earlier today, here is the code:

//trace(dx add ": " add dy)
//trace(angle add " deg.");
if(dx>=0 && dy<=0){angle+=180;}
else if(dx>=0 && dy>=0){angle+=180;}

Okay, pt1_x,pt1_y are the x/y coordinates of the first point, and the second points coordinates are pt2_x,pt2_y. The angle will be from pt1 to pt2, and it will be in according to flashes _rotation property, which means that it is upside down. However, if this is for flash, this is the way you want it.

dx and dy are the differences between them, so Math.atan(dy/dx) returns the proper angle between 90 and -90 degrees. Degrees are necessary in this case, because for some fool reason, the Math function returns radians, but the rotation property is in degrees. My best guess is that flash stole the Math property from javascript.
The two if statements check to see if the angle is in the correct quadrant, and corrects it if it isn't.

Well, it works perfectly for me, but I don't know what exactly your situation is. Tell me if it doesn't work for you though.