views:

455

answers:

3

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?
+2  A: 

You can interpolate between quaternions. I once wrote a quaternion-based keyframe animation generator that generated frames for a rendering systems from a few specific points. I can't share the code because it's classified :-(

There was a paper in the SIGGRAPH proceedings sometime in the 80s about this very topic. The main advantage of quaternions is that there's no singularity like there is with Euler angles.

Ah, here's the reference:

Shoemaker, Ken “Animating Rotation with Quaternion Curves”, SIGGRAPH '85, San Francisco, Jul. 22-26, 1985, vol. 19, No. 3, 1985 ACM 0-89791-166-0/85/007/0245, pp. 245-254.

Berry
Quaternions do not suffer from Gimbal lock, but they do have an ambiguity. [1,i,j,k] and [-1,i,j,k] represent the same orientation. I find it kind of weird that -1 represent 360 degrees of rotation in the complex plane, instead of the usual 180, as for vectors :-)
Mads Elvheim
+2  A: 

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.

Mads Elvheim
You should mention (as @Justicle did) that plain-ol' lerp works just fine for quaternions in many cases.
Jesse Beder
I read that euler rotations are not unambiguous, so you can't interpolate between them. Does converting them to quaternions really make them unambiguous, which seem a bit illogical for me.
codymanix
@codymanix : Perhaps, but it is the case. You can't _use_ euler angles directly either. Since quaternions have an extra degree of freedom, they avoid the whole problem with gimbal lock, no matter what the previous representation was, or what it gets converted to later. Euler angles -> quaternion -> matrix is entirely kosher.
Mads Elvheim
@codymanix: Interpolating euler angles and interpolating quaternions are intuitively very different operations. Interpolating quaternions is what you expect it to be: there is a minimal rotation q between two orientations a and b, such that a*q = b, and we increase the angle of q from zero to its original value as we interpolate, so we take the shortest path from a to b. When you interpolate euler angles you're doing something far weirder. You arbitrarily break q into three axis-aligned rotations (regardless of the orientations of a and b), and interpolate these component rotations instead.
SuperElectric
(cont'd from above) ... interpolating euler angles therefore does not necessarily take the shortest path from orientation a to orientation b, and indeed can take some pretty wild paths, unlike when interpolating quaternions using the SLERP algorithm.
SuperElectric
+1  A: 

Yes and no. Here's a good discussion: http://number-none.com/product/Understanding%20Slerp,%20Then%20Not%20Using%20It/

Note it doesn't really matter how you got the quaternions, the same rules apply.

Edit: I have used the source code presented in the paper on a number of projects and can vouch for it.

Justicle
Not as much a discussion as a person who clearly has made up his mind ;-) If you use quaternions for interpolation, you kind of have to settle with some of the weird properties. I think we can give the author of the question the benefit of the doubt; that he has thought this through. A good read nevertheless.
Mads Elvheim
"discussion" is a polite word for "rant" :-)
Justicle
Yeah, I'm just politely busting your balls ;-) Weekend at last!
Mads Elvheim