A Flash Developer Resource Site

1. I'm trying to figure out the angle between an object and a pont. on paper, the equation is :

ANGLE = TAN -1 O/A

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

Thanks!

2. I think Math.atan(number) gives inverse tan in radians.

3. 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

4. I just did this earlier today, here is the code:

dx=pt1_x-pt2_x;
dy=pt1_y-pt2_y;
angle=Math.atan(dy/dx)*180/Math.PI;
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.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 » Home » Movies » Tutorials » Submissions » Board » Links » Reviews » Feedback » Gallery » Fonts » The Lounge » Sound Loops » Sound FX » About FK » Sitemap