Search code examples
actionscript-3mathrotationgeometryalgebra

basic math rotation, wrong results


I'm too dumb to solve basic algebra, would be cool if you could help me out with this

usually I got the rotation and try to get position I want to rotate the object to

var rads : Number = rotation / 180 * Math.PI;
position.x = Math.cos(rads);
position.y = Math.sin(rads);

this time I got the position but I want to get the rotation but everything I tried is false, thanks in advance for your help

EDIT: for those who got the same problem and use actionscript 3 (or anything that also has this function) experiment with Math.atan2() it can save you a lot of trouble - faster and easier


Solution

  • Most languages provide a function called atan2() which takes the rise and run and does all the heavy lifting for you, giving the correct answer in all four quadrants.

    >>> math.atan2(-1, 1)
    -0.7853981633974483
    >>> math.atan2(-1, 1) * 180 / math.pi
    -45.0