Mirroring a quaternion against the yz-plane

Started by
11 comments, last by kuroioranda 13 years ago
I've switched my animation system over from using Euler angles to quaternions for representing bone rotations. It all works pretty well, except for the animation mirroring. I'm not sure how to mirror a quaternion about a plane, which is what I was doing with the old system (by simply flipping the sign on all x rotations).

Could anybody point out how this is can be done when using quaternions?
Advertisement
Quaternions represent rotations, and flipping the x coordinate is not a rotation. You may want to stick to using matrices if you need transformations that don't preserve the orientation.
I've never tried this myself, but you might try this:

- Negate the element corresponding to the axis you want to mirror along (e.g. if you're flipping across the yz plane, negate q.x)

- Negate the 'w' element

Again, I haven't actually tried this, so I can't guarantee it'll work or that it's correct.
jyk, I can guarantee that it won't work. Every unit-length quaternion represents a rotation (i.e., an orientation-preserving transformation). Whatever manipulations you try to perform on the quaternion are not going to change that fact.

jyk, I can guarantee that it won't work. Every unit-length quaternion represents a rotation (i.e., an orientation-preserving transformation). Whatever manipulations you try to perform on the quaternion are not going to change that fact.

I think you misunderstood it the same way I think I initially did, and I was about to say the same thing as you just did. As I understand it, he don't want to mirror the object through the Z-plane (which indeed is not possible by rotation), but mirror the rotation. Sort of like negating the Euler angle corresponding to rotation in the XY-plane. After all, he said it worked in his previous system, but just want the corresponding operation with quaternions.
Oh... I see. I need to think about it then. I would think the precise order in which the three axis rotation were done in his old system might matter. Or is there a standard order in which rotations are performed when people talk about Euler angles?

jyk, I can guarantee that it won't work. Every unit-length quaternion represents a rotation (i.e., an orientation-preserving transformation). Whatever manipulations you try to perform on the quaternion are not going to change that fact.

I'm not sure what you mean, but I think we must be talking about different things. The goal is not to change the fact that the quaternion represents a rotation, but rather to change the rotation that the quaternion represents, which can indeed be done by manipulating the elements of the quaternion (in a correct manner, of course).

As I said earlier, I'm not sure of the correctness of the method I proposed, but it does sound like we might not be talking about the same thing here.
A quaternion (q) is equivalent to rotating by an angle (a) around an axis (n):

q.s = cos(a / 2)
q.x = n.x * sin(a / 2)
q.y = n.y * sin(a / 2)
q.z = n.z * sin(a / 2)


If you want to mirror your rotation along the x axis, I think you just negate the angle and the x component of the normal:

q2.s = cos(-a / 2) = q1.s
q2.x = -n.x * sin(-a / 2) = q1.x
q2.y = n.y * sin(-a / 2) = -q1.y
q2.z = n.z * sin(-a / 2) = -q1.z


One project I worked on years ago switched from a game engine with a left-handed coordinate system to a game engine with a right-handed coordinate system so we had to do this kind of thing a lot. It's been a long time, though, so I could easily be wrong.

Incidentally, each rotation has two different quaternions that represent it:

q2.s = -q1.s
q2.x = -q1.x
q2.y = -q1.y
q2.z = -q2.z

(This can lead to all manner of hilarity when interpolating quaternions...)

If you want to mirror your rotation along the x axis, I think you just negate the angle and the x component of the normal:

Which is exactly what I proposed earlier, more or less.

For what it's worth, I just tried out the method I described, and it seemed to work; the rotation was indeed mirrored perfectly across the plane.

@The OP: You might at least give the method I and kdmiller3 proposed a try, and see if it does what you want.

@alvaro: I'm pretty sure we must be talking about different things. Although I still hesitate to guarantee the correctness of the method in question, all indications are that it does in fact work as expected. If you're certain that the method is incorrect, then I'd guess you're probably talking about something different than what we're talking about.

Or is there a standard order in which rotations are performed when people talk about Euler angles?

While some orders are more common than others, there doesn't seem to be a single "standard" order to Euler angles as far as I can tell. Maya, for example, lets you apply the X, Y, and Z rotations several different ways. (That's one of the troublesome aspects of Euler angles.)

This topic is closed to new replies.

Advertisement