Maxwellkid
- 69
- 0
why is there a lack of accuracy in this subsitution?
\frac{sin\phi}{cos\phi} = tan\phi
\frac{sin\phi}{cos\phi} = tan\phi
Maxwellkid said:why is there a lack of accuracy in this subsitution?
Tac-Tics said:This reminds me of a problem I had back when I was interested in programming games. Given an object at position (x, y) with a velocity (dx, dy), what is the angle the object is moving at with relation to the x-axis?
What you find out is that arc tangent isn't quite what you need. Because tangent is periodic with a period of pi, the arc tangent function won't distinguish between the correct direction and the direction exactly opposite it.
Because of this, most computer languages implement a function called atan2. By taking dx and dy as two separate parameters (as opposed to taking their ration, dy/dx as the parameter), atan2 can distinguish between the two cases and can provide you the correct angle of motion for your object.