Can I interpolate rotation from two Quaternions created from Yaw/Pitch/roll?

codymanix picture codymanix · Nov 6, 2009 · Viewed 10.1k times · Source

Quaternions are good for interpolate rotations between them. so far so good.

If I have a networking game, will it suffice to transfer the rotation as vector3f or should I use a quaternion? To make the game smoother I may have to interpolate between the last sent rotation and the current one.

But can I interpolate rotations between two Quaternions which were created from Yaw/Pitch/Roll?

Quaternion a = Quaternion.FromYawPitchRoll(x1,y1,z1);

Quaternion b = Quaternion.FromYawPitchRoll(x2,y2,z2);

a.Interpolate(b, value); // will this work correctly?

Answer

Mads Elvheim picture Mads Elvheim · Nov 6, 2009

Yes you can. The problem with Euler angles is gimbal lock, that some orientations ends up with one less degree of freedom. When you convert from Euler angles to a quaternion, that problem is solved. You can convert almost any 3D-axis representation into quaternion form and back, without any loss of information. Matrices must be isotropic (no scale or shearing), and vectors must be of unit length.

Linear interpolation between quaternions is called slerp. Quadratic interpolation between quaternions is called squad. Since quaternions are just complex numbers with three imaginary parts, the same equations that work on real numbers and vectors applies to quaternions. Just remember to use the correct rules when doing multiplication, addition, log and exponentiation. It can help to imagine that the imaginary parts i,j and k together form an axis vector, while the real part is a scale.