|
@@ -608,6 +608,29 @@ class Quaternion {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ random() {
|
|
|
+
|
|
|
+ // Derived from http://planning.cs.uiuc.edu/node198.html
|
|
|
+ // Note, this source uses w, x, y, z ordering,
|
|
|
+ // so we swap the order below.
|
|
|
+
|
|
|
+ const u1 = Math.random();
|
|
|
+ const sqrt1u1 = Math.sqrt( 1 - u1 );
|
|
|
+ const sqrtu1 = Math.sqrt( u1 );
|
|
|
+
|
|
|
+ const u2 = 2 * Math.PI * Math.random();
|
|
|
+
|
|
|
+ const u3 = 2 * Math.PI * Math.random();
|
|
|
+
|
|
|
+ return this.set(
|
|
|
+ sqrt1u1 * Math.cos( u2 ),
|
|
|
+ sqrtu1 * Math.sin( u3 ),
|
|
|
+ sqrtu1 * Math.cos( u3 ),
|
|
|
+ sqrt1u1 * Math.sin( u2 ),
|
|
|
+ );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
equals( quaternion ) {
|
|
|
|
|
|
return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
|