# Rotating source vector to destination vector (2D)

This topic is 791 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am trying to rotate a vector to a goal vector.
My main problem now is that I can't wrap my head on is which way to rotate the vector, so finding the "shortest" way to rotate (clockwise or counter clockwise).

##### Share on other sites

The dot product of the target vector and the normal of the current vector should result in a positive or negative value.  This result will determine whether a counter–clockwise or clockwise rotation should be made.

See attached.

Current direction vector A and its normal, A'
And sample target directions B and C:

##### Share on other sites

Edit, its 2d, what I wrote was 3d.

Edited by ErnieDingo

##### Share on other sites

If you use complex numbers to represent points and vectors, so you think of (x,y) as the number x+y*i, you can think of rotations as unit-length complex numbers, like cos(alpha)+sin(alpha)*i. Applying a rotation is now just complex-number multiplication. In that language, the rotation that maps a current vector to a target vector is simply z = target / current.

This might not be very satisfying because there is no notion of "shortest". The way mathematicians think of rotations, they are not things that happen progressively over time or anything like that, but just mappings that take an input vector and produce an output vector.

If you want to recover a notion of "shortest", perhaps you are interested in limiting how much the current vector can change in one step. This code would do that:

Complex limited_rotation(Complex current, Complex target, Complex max_rotation) {
Complex z = target / current;
// You may want to normalize z here if you can't guarantee that current and target have the same length
if (z.real() > max_rotation.real())
return z;
if (z.imag() > 0)
return max_rotation;
return conj(max_rotation);
}

Edited by alvaro

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 11
• 15
• 21
• 26
• 11