# Quaternion-Rotation to Degree (Edge-jump)

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

## Recommended Posts

Well met!

This may seem like a rather simple thing, but I can't seem to figure it out or find an answer.

I'm trying to write an exporter for 3ds MAX, but it stores its rotations in quaternions while I need angles.

It does provide you with a function to convert them, which gives you bad angles at the edges.

A simple rotation around the Y axis jumps like this:

...
(quat -0.0222105 -0.706758 -0.0222105 0.706758)
(eulerAngles 90.0001 86.4 90.0001)

(quat 2.30405e-007 -0.707107 2.30405e-007 0.707107)
(eulerAngles 0 90 0)

(quat 0.0230636 -0.706731 0.0230636 0.706731)
(eulerAngles -90 86.2617 -90)
...


After some research I got told that that is the expected behavior. I tried to write my own conversion function and catch the bad angles, but failed. What exactly should I do to get the degrees?

I hope you can help me with this!

Thank you in advance and have a nice day!

Edited by gnomgrol

##### Share on other sites

What exactly should I do to get the degrees?

don't use degrees, and go learn how complex numbers work, then quaternions should make much more sense. and don't let the name scare you, the concepts behind complex numbers is actually very simple if you take the time to understand them. Edited by slicer4ever

##### Share on other sites

You only really need a fairly basic understanding of what a Quaternion is to be able to use them effectively, and for animations, it's totally worthwhile to gain that understanding.

##### Share on other sites

You only really need a fairly basic understanding of what a Quaternion is to be able to use them effectively, and for animations, it's totally worthwhile to gain that understanding.

You only really need a fairly basic understanding of what a Quaternion is to be able to use them effectively, and for animations, it's totally worthwhile to gain that understanding.

I had my animations implemented using Quaternions at first.

I am currently rewriting my whole animation code based on a model suggested by L. Spiro, and so far it works out awesome. The last thing I need to get right are the rotations.

Like she mentioned in her post, Quaternions are really slow compared to matrices. And the track based animation system requires me to know every single part of the world matrix in order to gain speed.

Edited by gnomgrol

##### Share on other sites

You only really need a fairly basic understanding of what a Quaternion is to be able to use them effectively, and for animations, it's totally worthwhile to gain that understanding.

You only really need a fairly basic understanding of what a Quaternion is to be able to use them effectively, and for animations, it's totally worthwhile to gain that understanding.

I had my animations implemented using Quaternions at first.
I am currently rewriting my whole animation code based on a model suggested by L. Spiro, and so far it works out awesome. The last thing I need to get right are the rotations.
Like she mentioned in her post, Quaternions are really slow compared to matrices. And the track based animation system requires me to know every single part of the world matrix in order to gain speed.
(http://www.gamedev.net/topic/659147-optimising-bone-based-animation/#entry5169156)

so why are you pulling euler angles, instead of rotation matrix's out of the exporter? i'd say keep quaternions as your animation format, and simply convert it the rotation matrix upon loading the animation.

##### Share on other sites

Because I need the single rotations for each axis in order for the track-based animation-system to work. (But there might be a way around that)

But if I'd convert it into a rotation-matrix, I'd still get the problem at the edges,  wouldn't I?

Edited by gnomgrol

##### Share on other sites

But if I'd convert it into a rotation-matrix, I'd still get the problem at the edges,  wouldn't I?

Why would you get "problems" at the "egdes" (what edges?) with rotation matrix?

Sounds like you really should re-investigate:
* what is a rotation matrix (how it works / what it represents mathematically)
* what is a quaternion (--||--)
* what is gimbal lock in regards of euler angles ( edit: http://en.wikipedia.org/wiki/Gimbal_lock )

Edited by tanzanite7

##### Share on other sites

But if I'd convert it into a rotation-matrix, I'd still get the problem at the edges,  wouldn't I?

Why would you get "problems" at the "egdes" (what edges?) with rotation matrix?

Sounds like you really should re-investigate:
* what is a rotation matrix (how it works / what it represents mathematically)
* what is a quaternion (--||--)
* what is gimbal lock in regards of euler angles ( edit: http://en.wikipedia.org/wiki/Gimbal_lock )

I stated what the problem is in my first post.

I understand complex numbers and quaternions as well as where the problem is coming from (Which is, as I stated, the singularity in the conversion function).

I don't really care about the one degree beeing lost due to the gimbal lock.

But if I'd convert it into a rotation-matrix, I'd still get the problem at the edges,  wouldn't I?

This was supposed to mean that the conversion problem that occurs when converting to degrees also would occur when converting to a matrix.

Edited by gnomgrol

##### Share on other sites

But if I'd convert it into a rotation-matrix, I'd still get the problem at the edges,  wouldn't I?

This was supposed to mean that the conversion problem that occurs when converting to degrees also would occur when converting to a matrix.

Uh?

There are no conversion problems when converting quaternion to matrix (*) - did you mean from matrix to Euler angles? Then yes, whatever is the perceived problem with quaternion->euler (I am not sure what the problem is - are the values wrong? Why do you care that the values jump around a bit?) would probably crop up again.

Euler angles are usually terrible to work with (expensive, capricious and shall i say - bloody useless. IMMHO, aka YMMV), i would repeat the advice to use a quaternion and/or matrix where appropriate instead.

*) Quaternion transforms fairly easily into a neat equivalent rotation-only matrix (Orthonormal basis. So, just a bunch of unit length orthogonal axis vectors).

Perhaps useful for reference:
http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/index.htm
http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToMatrix/index.htm
http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToEuler/index.htm

##### Share on other sites

If you really know quaternions, as you say, although I'm not convinced, then this may help you:

http://wscg.zcu.cz/wscg2012/short/a29-full.pdf

Dual quaternions are excellent for this, especially if you're rolling your own.

Also, don't use matrices (where you don't have to) until the very last moment just before you shove it into GL

And... where does degrees come into this? Is it something that comes from 3ds max?

Edited by Kaptein