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

3

9

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?
Vercelli answered 6/11, 2009 at 0:19 Comment(0)
D
9

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.

Degas answered 6/11, 2009 at 0:46 Comment(5)
You should mention (as @Justicle did) that plain-ol' lerp works just fine for quaternions in many cases.Quillen
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.Vercelli
@Vercelli : 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.Degas
@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.Granite
(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.Granite
S
5

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.

Seigler answered 6/11, 2009 at 0:45 Comment(3)
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 :-)Degas
That is not quite ambigous when used as keyframes. (1,0,0,0)->(0,0,0,0)->(1,0,0,0) represents another movement then (1,0,0,0)->(0,0,0,0)->(-1,0,0,0) although start and end position and even intermediate position are the same.Redintegrate
Nice wikipedia page based on Ken's work mentioned above: en.wikipedia.org/wiki/SlerpSteal
A
4

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.

Avaria answered 6/11, 2009 at 1:0 Comment(4)
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.Degas
"discussion" is a polite word for "rant" :-)Avaria
Yeah, I'm just politely busting your balls ;-) Weekend at last!Degas
After looking at the article, I'm actually more certain that slerp is the best choice: it has "constant velocity" and is "torque-minimal". Plus, I don't really care about "commutativity", so no problem there.Retro

© 2022 - 2024 — McMap. All rights reserved.