I am needing to get the shortest rotation path between two quaternions.
Quaternion a ;
Quaternion b ;
var c = a * Quaternion.Inverse(b );
c is usually the shortest path, but there are instances where it is the significantly longer rotation.
Is there an easy way to guarantee that c is always the absolute shortest rotation between a and b ?
I think the Slerp operation is what you want:
In computer graphics, slerp is shorthand for spherical linear interpolation, introduced by Ken Shoemake in the context of quaternion interpolation for the purpose of animating 3D rotation. It refers to constant-speed motion along a unit-radius great circle arc, given the ends and an interpolation parameter between 0 and 1.
Slerp has a geometric formula independent of quaternions, and independent of the dimension of the space in which the arc is embedded. This formula, a symmetric weighted sum cr...
The reason I think this is that article mentions “great circle arc,” which is of course what airliners do to get the shortest distance between distant airports.
can you maybe check if the rotation of c is over 180/pie and if so just flip it?
Kurt-Dekker:
I think the Slerp operation is what you want:
https://en.wikipedia.org/wiki/Slerp
The reason I think this is that article mentions “great circle arc,” which is of course what airliners do to get the shortest distance between distant airports.
Hey Kurt good find, I was able to extract what I needed out of this. Here is the fix for anyone else running into this -
{
if (Quaternion.Dot(a, b) < 0)
{
return a * Quaternion.Inverse(Multiply(b, -1));
}
else return a * Quaternion.Inverse(b);
}
public static Quaternion Multiply(Quaternion input, float scalar)
{
return new Quaternion(input.x * scalar, input.y * scalar, input.z * scalar, input.w * scalar);
}```
8 Likes
I think you are imagining that c is a float representing the angle between two vectors. In the example c is a Quaternion representing the rotation to get from one orientation to another.
sorta but not really, just look if that rotation(c) is looking over 180 degrees from “0” rotation…?
I guess quaternion doesn’t work anything like that eh?
lucky there’s all of those functions, haha.
This is exactly what I was looking for today. Thanks for sharing Guadinman!