I understand that the dot (or inner) product of two quaternions is the angle between the rotations (including the axis-rotation). This makes the dot product equal to the angle between two points on the quaternion hypersphere.
I can not, however, find how to actually compute the dot product.
Any help would be appreciated!
current code:
public static float dot(Quaternion left, Quaternion right){
float angle;
//compute
return angle;
}
Defined are Quaternion.w, Quaternion.x, Quaternion.y, and Quaternion.z.
Note: It can be assumed that the quaternions are normalised.
The dot-product (inner product) of two quaternions is their usual vector dot-product: ˙p· ˙q = p0q0 + pxqx + pyqy + pzqz. a vector. A unit quaternion has squared length one.
To rotate a vector v=ix+jy+kz by a quaternion q you compute vq=qvq−1. So if q and q′ are two rotation quaternions, to rotate by q then q′ you calculate (vq)q′=q′qvq−1q′−1=q′qv(q′q)−1=vq′q.
Multiplication of a quaternion, q, by its inverse, q− 1, results in the multiplicative identity [1, (0, 0, 0)]. A unit-length quaternion (also referred to here as a unit quaternion), , is created by dividing each of the four components by the square root of the sum of the squares of those components (Eq. 2.28).
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.
The dot product for quaternions is simply the standard Euclidean dot product in 4D:
dot = left.x * right.x + left.y * right.y + left.z * right.z + left.w * right.w
Then the angle your are looking for is the arccos
of the dot product (note that the dot product is not the angle): acos(dot)
.
However, if you are looking for the relative rotation between two quaternions, say from q1
to q2
, you should compute the relative quaternion q = q1^-1 * q2
and then find the rotation associated withq
.
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