In

*Thwaite*, I calculated the angle of the vector from the missile silo to the cursor using a partly table-based

atan2 routine that took less than 400 cycles. This involves reflecting the coordinate into the first octant, calculating the slope of the vector (1 division), looking up the slope in a table, and undoing the reflection. I used this angle to determine the approximate direction of the missile (out of 32) so that I could choose the appropriate sprite tile for the direction.

Because I felt like implementing atan2 and not

hypot (length of a vector) that day, I took a

dot product with the corresponding

unit vector (2 multiplications) to determine the length of the path.

Define unit(theta) = (cos(theta), sin(theta)).

Define (a, b) dot (c, d) = a*b + c*d.

Calculate theta = atan2(x, y), based on atan(y/x).

Then hypot(x, y) = unit(theta) dot (x, y).

This is exact if atan2 is exact, and even with the 32-step atan2 that

*Thwaite* uses, it's still within half a percent. (Reasoning: cos(tau/64) = 0.995.) Then I converted that to a reciprocal of flight time in frames

^{-1} (1 division), and scaled the vector to the cursor by that amount (2 multiplications) to form the missile's velocity.

For

*RHDE*, I did the homing missile "cheat": call atan2 on the vector to the target, set the missile's frame based on that angle and its velocity based on that angle's unit vector, and update the atan2-based estimate every few frames. Each player is allowed only a limited number of missiles in flight at once, and updating some of the missiles each frame was deemed close enough.