Hello!
In my project I am working on I am trying to have an airplane sprite rotate as it moves along a parametric path (figure-8). I want it to always face the direction of the path, but I am having one issue with this. My parametric path is defined as:
x = sin(2t),
y = cos(t)
I calculate the angle with:
angle = -1 * (arcsin(dx / sqrt(dx^2 + dy^2) * (180 / pi))
(where dx and dy are the changes in x and y)
However, when the parametric path crosses itself (on the up-slope and down-slope) the angle stays the same for both cases (when it should be facing ~45 degrees up going counter-clockwise and ~-45 degrees down going clockwise). This is because on the down-slope, the dy becomes negative (which would cause the angle to rotate in the negative direction), but the sign gets lost in the square root and the angle becomes positive.
I was thinking about somehow using an arccos angle instead so that the dy would be on the numerator, but I keep getting stuck.
I can’t figure out how to fix this and I was just wondering if anyone (who is better at trig / math than I am :P) can help me.
Thanks!