Sign in to follow this  
hybridized

euler to quaternion. quaternion * quaternion. quaternion to euler ?????

Recommended Posts

small question before I start to code. does this make sense: !? A hierarchical bone character. The bone orientation is stored in euler angles. To calculate the absolute orientation, i convert the euler orientation to quaterion to multiply "parent orientation * current bone orientation". This does work!!! my question: could I convert the multiplyed quaternion back to euler angles!? I wonna do this because euler rotation is much faster then quaternion rotation. (if the bone rotates a body part of maybe 18 vectors) I really need to optimise it for mobile java me implementation. so: 1. Euler to Quaternion 2. Quaternion = Quaternion * parent Quaternion 3. Quaternion to Euler 4. Euler rotates the body part.... So will it work!? or is there a bad effect reconverting the quaternion to euler for rotation?

Share this post


Link to post
Share on other sites
Quote:
Original post by hybridized
small question before I start to code.

does this make sense: !?

A hierarchical bone character.
The bone orientation is stored in euler angles.
To calculate the absolute orientation, i convert the
euler orientation to quaterion to
multiply "parent orientation * current bone orientation".
This does work!!!

my question: could I convert the multiplyed quaternion back to euler angles!?
I wonna do this because euler rotation is much faster then quaternion rotation.
(if the bone rotates a body part of maybe 18 vectors)
I really need to optimise it for mobile java me implementation.

so:

1. Euler to Quaternion
2. Quaternion = Quaternion * parent Quaternion
3. Quaternion to Euler
4. Euler rotates the body part....

So will it work!? or is there a bad effect reconverting the quaternion to euler for rotation?
Hi,

First of all, cross-posting is discouraged here, so (if you still can) you might delete your General Programming post, as the subject matter is more on topic here.

Anyway, what you're suggesting should work, as long as your quat-to-Euler and Euler-to-quat functions match (e.g. same axis order), and are well-behaved in the presence of singularities and so on. Depending on how the functions are implemented, you may not always get the same set of Euler angles back from the quaternion that you used to construct it, but if the functions are correct the two sets should be equivalent.

Also, why do you say Euler rotations are faster than quaternions in the given context? Just curious.

Share this post


Link to post
Share on other sites
Hi thx for answer.

In my opinion euler rotation is much faster.
If you know an alternative, faster way to rotate vectors via Quaternion
let me know!

my Java code:

Euler rotation: (rotates "Vektor a" to "vektor b" by euler "angle C")

public void rotate(qVektor a, qVektor b, qAngle c){

tmpy=a.r[1];
tmpz=a.r[2];
b.r[1]= (tmpy * this.cos(c.a[0])/180) - (tmpz * this.sin(c.a[0])/180);
b.r[2]= (tmpz * this.cos(c.a[0])/180) + (tmpy * this.sin(c.a[0])/180);

tmpz=b.r[2];
tmpx=a.r[0];
b.r[2]= (tmpz * this.cos(c.a[1])/180) - (tmpx * this.sin(c.a[1])/180);
b.r[0]= (tmpx * this.cos(c.a[1])/180) + (tmpz * this.sin(c.a[1])/180);

tmpx=b.r[0];
tmpy=b.r[1];
b.r[0]= (tmpx * this.cos(c.a[2])/180) - (tmpy * this.sin(c.a[2])/180);
b.r[1]= (tmpy * this.cos(c.a[2])/180) + (tmpx * this.sin(c.a[2])/180);

}

Quaternion rotation: rotates "Vektor v1" to "Vektor v2" by "Quaternion q"
//rvq and rinv are defined global, for speed reasons.

public void rotate(qQuat q, qVektor v1, qVektor v2){

rvq.x = v1.r[0]; rvq.y = v1.r[1]; rvq.z = v1.r[2]; rvq.w = 0;
rinv.x = -q.x; rinv.y = -q.y; rinv.z = -q.z; rinv.w = q.w;

mQuat(q, rvq, rtmp);
mQuat(rtmp, rinv, rendq);

v2.r[0] = rendq.x; v2.r[1] = rendq.y; v2.r[2] = rendq.z;
}

So there are two multiplikations -> mQuat function look like this:

public void mQuat(qQuat a, qQuat b, qQuat c){
c.x = ((a.x * b.w + a.y * b.z) - a.z * b.y) + a.w * b.x;
c.y = -a.x * b.z + a.y * b.w + a.z * b.x + a.w * b.y;
c.z = (a.x * b.y - a.y * b.x) + a.z * b.w + a.w * b.z;
c.w = (-a.x * b.x - a.y * b.y - a.z * b.z) + a.w * b.w;
}

much more operations :)

Share this post


Link to post
Share on other sites
Well, I don't know much about the environment you're working in, but on a PC at least manually rotating vectors via Euler angles and trig would not be the way to go. Generally these sorts of transformations are expressed as matrix-vector multiplications, which in the case of rotations comes out to...9 mults and 6 adds, I think. This beats your Euler-angle example, even without the trig.

Almost always, other representations such as Euler angles and quaternions are converted to matrices before being used to transform vectors. There is some cost involved in the conversion, but this becomes negligable as the number of vectors to be transformed increases.

Again I'm not familiar with the particular environment in which you're working, but I'd be surprised if the method you propose were a win performance-wise.

Oh, and also, nobody actually implements quaternion-vector rotation as in your example. When you work through the math, many operations drop out. What you're left with is essentially a) a quaternion-to-matrix conversion, and b) a matrix-vector multiplication. In practice, the conversion only need be performed once per quaternion, after which each vector can be transformed relatively cheaply.

Share this post


Link to post
Share on other sites
hi!

You're right. Nothing better than matrix vector calculations.
But I'm working on mobile devices with poor cpus, ram and without
3D accelerator.
If I would implement 4x4Matrix stuff nothing would move.
4x4Matrix multiplikations = billions of operations.
So my platform is totally software "draw line and draw triangle".

Screenshot of the current model:
http://dubtissm.cabspace.com/img/code/qMo-4.gif

Anyway, I'd like to draw 3D body parts, orientat relative to the bone quaternion. You wrote: transformed relatively cheaply.

Is it possible as well without 4x4?

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