# Mirroring a quaternion against the yz-plane

This topic is 2840 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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?

##### Share on other sites
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.

##### Share on other sites
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.

##### Share on other sites
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.

##### Share on other sites

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.

##### Share on other sites
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?

##### Share on other sites

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.

##### Share on other sites
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...)

##### Share on other sites

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.

##### Share on other sites

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.)

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 11
• 9
• 38
• 16
• ### Forum Statistics

• Total Topics
634128
• Total Posts
3015694
×