daniel
daniel

Reputation: 35733

3D rotation around fixed axes

I need axis and angle for rotation around 3 fixed axes. What I want:

input:

ouput:

The problem is that I always rotate around the already rotated axes. My code so far:

 var q1 = x3dom.fields.Quaternion.axisAngle(new x3dom.fields.SFVec3f(0, 0, 1), alpha)
 var q2 = x3dom.fields.Quaternion.axisAngle(new x3dom.fields.SFVec3f(1, 0, 0), beta)
 var q3 = x3dom.fields.Quaternion.axisAngle(new x3dom.fields.SFVec3f(0, 1, 0), gamma)

 var qr = q1.multiply(q2);
 qr = qr.multiply(q3);
 var r = qr.toAxisAngle();

 this.curNode.attr('rotation', r[0].x + ' ' + r[0].y + ' ' + r[0].z + ' ' + r[1]);

Video: only one rotation is around the ring (red one) is right. the other two are around the rotated object axes. They should be around the fixed axes

Upvotes: 0

Views: 1563

Answers (2)

Snowww
Snowww

Reputation: 1

The problem is you are rotateing the local node axis, to mantani axis fixed you need to use inverse quaternion for the node, but only for the node, to compute rotation, you need to use original quaternion. Like this:

var q1 = x3dom.fields.Quaternion.axisAngle(new x3dom.fields.SFVec3f(0, 0, 1), alpha)
 var q2 = x3dom.fields.Quaternion.axisAngle(new x3dom.fields.SFVec3f(1, 0, 0), beta)
 var q3 = x3dom.fields.Quaternion.axisAngle(new x3dom.fields.SFVec3f(0, 1, 0), gamma)

 var qr = q1.multiply(q2);
 qr = qr.multiply(q3);
 var r = qr.toAxisAngle();

r  = r.inverse();

 this.curNode.attr('rotation', r[0].x + ' ' + r[0].y + ' ' + r[0].z + ' ' + r[1]);

If you want before recover node value, you must to invert it to compute it, and invert it the result to use it the node again.

Upvotes: 0

Gangnus
Gangnus

Reputation: 24484

I think, it is very well explained on wiki Only instead of normal two turns you have three of them. So, you have to multiply not 2, but three matrices of flat turns. That is all.

Upvotes: 1

Related Questions