A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: How do I set angle measure depending on x velocity and y velocity?

  1. #1
    j00 r teh pwnz0r3d DarkMagicHacker's Avatar
    Join Date
    Feb 2001
    Location
    Your mom's room.
    Posts
    622

    How do I set angle measure depending on x velocity and y velocity?

    Can someone help me with this???
    You pwn. I pwn. We all pwn for ice pwn.

    Chop Suey! The Greatarst Gaem EVAR!!!!!!!!

  2. #2
    Senior Member
    Join Date
    Mar 2000
    Posts
    177
    It would be helpful if you posted some code or more explanation.

    Perhaps this will start you off:

    angleInRadians = Math.atan2 (y, x);
    angleInDegrees = angleInRadians * 180 / Math.PI;

    This is the basic process of turning x and y coordinates into an angle.

    Hope that helps.
    Last edited by robertpenner; 11-18-2002 at 09:22 PM.
    New Book: Robert Penner's Programming Flash MX
    Dynamic tweening, color, math, vectors and physics with OOP ActionScript
    http://www.robertpenner.com/profmx
    http://www.amazon.com/exec/obidos/AS...bertpennerc-20

  3. #3
    Senior Member
    Join Date
    Jun 2001
    Location
    South Africa
    Posts
    316
    Hi Robert,

    I might be a little confused here but Keith Peters says the following in his tutorial (http://www.bit-101.com/tutorials/3D-rotation.html):
    I'm not going to go into an explanation of the trigonometry involved here. It's actually pretty simple, but I'll leave that for another tutorial. Just know that this works. A very important point you need to know is that "angle" needs to be in radians. This is a different system from the 360 degrees that you might be used to. Since it's a lot easier to think in degrees, you'll need to convert them. The formula for that is:

    rad=degree*Math.PI/180;
    Is that not the opposite of your formula? Please help me to clarify.
    Could you also explain the differences between these: tan, atan, atan2

    Thanks
    BTW - your work is pretty awesome.
    someday i'll be a kick-ass flash developer - you'll see.

  4. #4
    Senior Member
    Join Date
    Jan 2002
    Posts
    368
    yes, it is opposite. because he is converting in the opposite direction.

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

  5. #5
    Senior Member
    Join Date
    Jan 2002
    Posts
    368
    as far as tan.

    take a right triangle. pick one of the non-90 angles. you have three sides. the long side is the hypotenuse. then you have the side opposite your angle and the side adjacent to your angle. if you divide the length of the opposite side by the adjacent, you will get a number. that is the tan of that angle. it doesn't matter how big the triangle is. as long as you have that angle, you will get that number when you divide those two sides.

    so... Math.tan(angle) gives you that number.

    Math.atan(number) goes in the opposite direction. you take a ratio by dividing those two numbers, and it will give you the angle (in radians of course).

    Math.atan2(y, x) handles at least one problem with atan. if you just divide the sides and plug the number in, you will get an angle, but you don't know which quadrant the angle is in. say you have y=1 and x=2. then another example of y=-1 and x=-2. 1/2 is the same as -1/-2. they both give you .5 and atan will give you the same angle. but they are different angles. when you plug in y and x into atan2, it takes that into account and gives you the correct angle.

  6. #6
    Senior Member
    Join Date
    Jun 2001
    Location
    South Africa
    Posts
    316
    Keith, thanks for trying to explain. As you may have guessed, I'm not a Math fundi. I've had a look at Flash Math Creativity reviews - most are positive. I've also had a look at Flash MX Studio which also has a chapter on Trig.

    So who better to ask than the source itself right? Which book would you recommend for someone like myself - amateur Flasher who wants to beef up his skills. Is Flash Math Creativity too advanced? I mean does the book explain basic trig and explain what each calculation does, etc, etc?

    Perhaps you know of a novice to intermediate "Flash+Math" book that may offer some hope.

    Thanks again for your time (which I know is very limited).
    someday i'll be a kick-ass flash developer - you'll see.

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