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

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

## 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 on other sites
Quote:
 Original post by hybridizedsmall 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 Quaternion2. Quaternion = Quaternion * parent Quaternion3. Quaternion to Euler4. 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 on other sites

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 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 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?

1. 1
2. 2
frob
12
3. 3
4. 4
5. 5
Rutin
10

• 13
• 14
• 65
• 14
• 15
• ### Forum Statistics

• Total Topics
632130
• Total Posts
3004283

×