Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting quaternion to rotate between two vectors

Tags:

math

geometry

I've got a pair of vectors. How can I create a quaternion that rotates from one to the other?

like image 353
Puppy Avatar asked Apr 19 '12 20:04

Puppy


People also ask

How do you find the quaternion rotation between two vectors?

You can convert to a quaternion by using q=cos(θ/2)+(uxˆi+uyˆj+uzˆk)sin(θ/2), where ux, uy and uz are the components of the rotation axis, θ is the rotation angle and ˆi, ˆj and ˆk are the components of the quaternion.

How do you rotate with quaternion?

For rotation quaternions, the inverse equals the conjugate. So for rotation quaternions, q−1 = q* = ( q0, −q1, −q2, −q3 ). Inverting or conjugating a rotation quaternion has the effect of reversing the axis of rotation, which modifies it to rotate in the opposite direction from the original.

How do you rotate a quaternion by another quaternion?

Use the Quaternion operator * . In Unity, when you multiply two quaternions, it applies the second quaternion (expressed in global axes) to the first quaternion along the local axes produced after the first Quaternion ). So, if you want to do the equivalent of Rotate(q2, Space.


1 Answers

A unit quaternion q = cos(F)+u*sin(F) represents the rotation of vector v by the angle 2*F about axis u.

If your vectors are v and w, then we should normalize them, then calculate the angle between them as 2*F=ArcCos(Dot(v, w)). Rotation axis direction vector u = Normalize(VectorProduct(v, w)). Now we can build required rotation quaternion.

like image 189
MBo Avatar answered Sep 23 '22 22:09

MBo