For my RTS game's physics engine, I'm trying to find out a clever way to make a unit face the direction it's moving in. Given a Vector2d direction of movement (its normalized velocity), how can I calculate the unit's rotation? If possible, I'd rather not use inverse trig functions because I only have a lookup table for Sine.
You shouldn't use a rotation angles if you can avoid it.* They are a bad representation of directions. If you choose to use them, you will need an inverse trig function.
Instead of storing
theta, store the pair
(cos(theta), sin(theta)). You can combine rotations and directions using the multiplication rules of complex numbers, i.e.
(a,b) * (c,d) = (ac - bd, ad + bc)
The 2D rotation matrix is easily constructed, because cos and sin of the angle are immediately available. Be sure to re-normalize the directions sufficiently often or they will inadvertently scale your points.
Finally, the angle between two vectors can be compared to a reference angle
theta_0 using the dot product between the two direction vectors, as when the smaller angle between A and B is less than
cos(theta_0) < dot(A,B).
* Except for input/output to humans or as a compact way to store a direction if every byte counts.