• Advertisement

Rotating source vector to destination vector (2D)

Recommended Posts


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 this post

Link to post
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

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement