I'm working on a flight-simulator type program, and I'm attempting to make elements (e.g. missiles) that lock-onto and track a target. There are plenty of rotation matrix implementations online that deal with rotating a vector to face another vector. Here's the one I've been using from Wikipedia: $$\mathbf R = \mathbf I + (\sin\theta)\mathbf {\hat K} + (1-\cos\theta)\mathbf {\hat K}^2$$ where $\theta$ is the angle between the two vectors and $\mathbf {\hat K}$ is the cross product matrix built from the unit vector $\mathbf {\hat k}$ around which to rotate: $$\mathbf {\hat K} = \begin{bmatrix}0 & -k_z & k_y \\ k_z & 0 & -k_x \\ -k_y & k_x & 0\end{bmatrix}$$ Since I compute $\mathbf k$ using the cross product of my target current heading $\mathbf {\hat v}$ and the target vector $\mathbf {\hat t}$, it's length is already equal to $\sin\theta$. Computing the cross product matrix from before without normalizing $\mathbf k$ gives: $\mathbf K = (\sin\theta)\mathbf {\hat K}$. This simplifies the first formula to: $$\mathbf R = \mathbf I + \mathbf K + \mathbf K^2/(1+\cos\theta)$$ This formula works great in addition to being ridiculously sexy.

Now, here's my issue:

The formulas above work fantastically, but they "yank" the trackers around instantly, which is a little jarring, and not particularly realistic in a flight-sim. To combat this I'm attempting to set a limit on the rotation speed. I currently find $\sin$ and $\cos$ using: $$\sin\theta = \vert \mathbf {\hat v} \times \mathbf {\hat t} \vert$$ $$\cos\theta = \vert \mathbf {\hat v} \cdot \mathbf {\hat t} \vert$$ Then I check to see if $\cos\theta > \cos\theta_{max}$ and if it is, I have to recompute $\cos\theta = \cos\theta_{max}$ as well as $\sin\theta = \sin\theta_{max}$. Additionally, I then have to normalize $\mathbf k$ and use the first rotation equation. It works, but it's certainly not as elegant as the simplified equation.

My question is this:

Am I missing anything that would make this formula simpler (and faster)? Is there an easier way to compute a rotation matrix with a limited rotation speed than this?


For a natural effect, one needs to look at the physics of rotating an object (such as a missile). The rotational inertia law would be $I\ddot{\theta}=\tau$, so the problem of starting from an angle of $0$ to an angle $\theta_0$ is achieved by a quadratic formula $$\theta(t)=\theta_0 f(t),\qquad f(t)=\begin{cases}2t^2 & 0<t<\frac{1}{2} \\ 1-2(1-t)^2& \frac{1}{2}<t<1\end{cases}$$

In practice a similar effect is achieved by $$f(t)=t^2(3-2t).$$ The comment mentions Slerp but that needs to compute three sine values at each step.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.