I've got a pair of vectors. How can I create a quaternion that rotates from one to the other?
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With