A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: TAN-1

  1. #1
    Agent de Folie dJide's Avatar
    Join Date
    Jan 2002
    Posts
    361
    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. #2
    Senior Member
    Join Date
    Mar 2000
    Location
    London
    Posts
    961
    I think Math.atan(number) gives inverse tan in radians.

    To convert radians to degrees:

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

  3. #3
    Senior Member
    Join Date
    Apr 2001
    Location
    UK
    Posts
    493
    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:

    Degrees=Radians*(180/Math.PI)
    Radians=Degrees*(Math.PI/180)

    Hope this helps

  4. #4
    Senior Member
    Join Date
    Jun 2002
    Posts
    192
    I just did this earlier today, here is the code:

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

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center