Question

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

input:

  • angle alpha (rotation round fixed x-axis)
  • angle beta (rotation round fixed y-axis)
  • angle gamma (rotation round fixed z-axis)

ouput:

  • rotation axis with angle

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

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top