未验证 提交 b7d23d58 编写于 作者: M Mr.doob 提交者: GitHub

Merge pull request #14422 from Mugen87/dev1

Quaternion: Added .angleTo()
......@@ -59,13 +59,17 @@
<h2>Methods</h2>
<h3>[method:Float angleTo]( [param:Quaternion q] )</h3>
<p>
Returns the angle between this quaternion and quaternion [page:Quaternion q] in radians.
</p>
<h3>[method:Quaternion clone]()</h3>
<p>
Creates a new Quaternion with identical [page:.x x], [page:.y y],
[page:.z z] and [page:.w w] properties to this one.
</p>
<h3>[method:Quaternion conjugate]()</h3>
<p>
Returns the rotational conjugate of this quaternion. The conjugate of a quaternion
......
......@@ -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
......
......@@ -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 );
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册