Here's a handy function you can implement in your project to calculate the inverse of a rotation represented by an Euler
:
THREE.Euler.prototype.inverse = function () {
var q = new THREE.Quaternion();
return function inverse() {
return this.setFromQuaternion( q.setFromEuler( this ).invert() );
};
}();
This function first converts the Euler representation to a quaternion representation, then inverts the quaternion, and finally converts it back to Euler.
It's important to note that Euler representations are not unique, so their inverses are also non-unique.
If you have two unit vectors a
and b
, and you need to find the rotation that transforms a
into b
, you can use the following:
var q = new THREE.Quaternion().setFromUnitVectors( a, b );
Both a
and b
must be normalized (have a length of 1), which can be achieved using the Vector3.normalize()
method.
Version used: three.js r.84