Sign in to follow this  
kuroioranda

Mirroring a quaternion against the yz-plane

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
[quote name='alvaro' timestamp='1302784370' post='4798360']
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.
[/quote]
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 this post


Link to post
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 this post


Link to post
Share on other sites
[quote name='alvaro' timestamp='1302784370' post='4798360']
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.
[/quote]
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 this post


Link to post
Share on other sites
A quaternion (q) is equivalent to rotating by an angle (a) around an axis (n):
[code]
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)
[/code]

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:
[code]
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
[/code]

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:
[code]
q2.s = -q1.s
q2.x = -q1.x
q2.y = -q1.y
q2.z = -q2.z
[/code]
(This can lead to all manner of hilarity when interpolating quaternions...)

Share this post


Link to post
Share on other sites
[quote name='kdmiller3' timestamp='1302810950' post='4798540']
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:[/quote]
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 this post


Link to post
Share on other sites
[quote name='alvaro' timestamp='1302786584' post='4798371']
Or is there a standard order in which rotations are performed when people talk about Euler angles?
[/quote]
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.)

Share this post


Link to post
Share on other sites
[quote name='jyk' timestamp='1302810426' post='4798534']
[quote name='alvaro' timestamp='1302784370' post='4798360']
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.
[/quote]
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.
[/quote]

Yes, Brother Bob already made me realize I did not read the question correctly, but I still think the description of what the OP want is not complete enough. Some non-trivial example (i.e., with non-zero values for all Euler angles) would be nice to see.

Share this post


Link to post
Share on other sites
[quote name='alvaro' timestamp='1302812080' post='4798546']
Yes, Brother Bob already made me realize I did not read the question correctly, but I still think the description of what the OP want is not complete enough.[/quote]
Ah, I see. Well, at least the OP has something he can try now.

Share this post


Link to post
Share on other sites
Wow, thanks a lot for thinking this through so guys! I wasn't expecting this much activity on the thread.

alvaro: the rotation order doesn't matter in this case, as I only want to mirror an orientation. I had a way to mirror that using my euler angles, I just didn't know how to mirror a quaternion orientation.

I'll give the component negation method a go! Thanks guys!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this