diff --git a/docs/api/math/Quaternion.html b/docs/api/math/Quaternion.html index 88200ecabab9c50bf4e8f22b19b726f9c68692c4..a9c4b114e0f7b096fae86e3a8aeb45fc7e59fe44 100644 --- a/docs/api/math/Quaternion.html +++ b/docs/api/math/Quaternion.html @@ -59,13 +59,17 @@

Methods

+

[method:Float angleTo]( [param:Quaternion q] )

+

+ Returns the angle between this quaternion and quaternion [page:Quaternion q] in radians. +

+

[method:Quaternion clone]()

Creates a new Quaternion with identical [page:.x x], [page:.y y], [page:.z z] and [page:.w w] properties to this one.

-

[method:Quaternion conjugate]()

Returns the rotational conjugate of this quaternion. The conjugate of a quaternion diff --git a/src/math/Quaternion.js b/src/math/Quaternion.js index 0d998926b8a1c562bc9c3735b51216b173015e5d..a437ef1e76da3b26e0190bbb0ea592138a7d8e5b 100644 --- a/src/math/Quaternion.js +++ b/src/math/Quaternion.js @@ -393,6 +393,12 @@ Object.assign( Quaternion.prototype, { }(), + angleTo: function ( q ) { + + return 2 * Math.acos( Math.abs( this.dot( q ) ) ); + + }, + inverse: function () { // quaternion is assumed to have unit length diff --git a/test/unit/src/math/Quaternion.tests.js b/test/unit/src/math/Quaternion.tests.js index 8ad4faabc7589dcf2177c6ea849bc1bdcf7b0ff5..85dddf8278f8e5aa714944c0537ecc25fffcfde3 100644 --- a/test/unit/src/math/Quaternion.tests.js +++ b/test/unit/src/math/Quaternion.tests.js @@ -391,6 +391,20 @@ export default QUnit.module( 'Maths', () => { } ); + QUnit.test( "angleTo", ( assert ) => { + + var a = new Quaternion(); + var b = new Quaternion().setFromEuler( new Euler( 0, Math.PI, 0 ) ); + var c = new Quaternion().setFromEuler( new Euler( 0, Math.PI * 2, 0 ) ); + var d = new Quaternion().setFromEuler( new Euler( 1, 1, 1 ) ); + + assert.ok( a.angleTo( a ) <= eps, "Passed!" ); + assert.ok( ( a.angleTo( b ) - Math.PI ) <= eps, "Passed!" ); + assert.ok( ( a.angleTo( c ) - ( Math.PI * 2 ) ) <= eps, "Passed!" ); + assert.ok( ( a.angleTo( d ) - ( 1.939087528822506 ) ) <= eps, "Passed!" ); + + } ); + QUnit.test( "inverse/conjugate", ( assert ) => { var a = new Quaternion( x, y, z, w );