@lakuna/umath 1.5.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/dist/algorithms/greatestCommonDivisor.d.ts.map +1 -1
- package/dist/algorithms/greatestCommonDivisor.js +14 -4
- package/dist/algorithms/greatestCommonDivisor.js.map +1 -1
- package/dist/index.d.ts +15 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/linalg/DualQuaternion.d.ts +131 -154
- package/dist/linalg/DualQuaternion.d.ts.map +1 -1
- package/dist/linalg/DualQuaternion.js +188 -203
- package/dist/linalg/DualQuaternion.js.map +1 -1
- package/dist/linalg/Matrix.d.ts +24 -24
- package/dist/linalg/Matrix.d.ts.map +1 -1
- package/dist/linalg/Matrix2.d.ts +74 -88
- package/dist/linalg/Matrix2.d.ts.map +1 -1
- package/dist/linalg/Matrix2.js +114 -124
- package/dist/linalg/Matrix2.js.map +1 -1
- package/dist/linalg/Matrix3.d.ts +118 -139
- package/dist/linalg/Matrix3.d.ts.map +1 -1
- package/dist/linalg/Matrix3.js +169 -201
- package/dist/linalg/Matrix3.js.map +1 -1
- package/dist/linalg/Matrix4.d.ts +217 -257
- package/dist/linalg/Matrix4.d.ts.map +1 -1
- package/dist/linalg/Matrix4.js +310 -374
- package/dist/linalg/Matrix4.js.map +1 -1
- package/dist/linalg/Quaternion.d.ts +120 -151
- package/dist/linalg/Quaternion.d.ts.map +1 -1
- package/dist/linalg/Quaternion.js +187 -204
- package/dist/linalg/Quaternion.js.map +1 -1
- package/dist/linalg/SlowMatrix.d.ts +5 -5
- package/dist/linalg/SlowMatrix.d.ts.map +1 -1
- package/dist/linalg/SlowMatrix.js +63 -89
- package/dist/linalg/SlowMatrix.js.map +1 -1
- package/dist/linalg/SlowSquareMatrix.d.ts +6 -6
- package/dist/linalg/SlowSquareMatrix.d.ts.map +1 -1
- package/dist/linalg/SlowSquareMatrix.js +15 -15
- package/dist/linalg/SlowSquareMatrix.js.map +1 -1
- package/dist/linalg/SlowVector.d.ts +165 -0
- package/dist/linalg/SlowVector.d.ts.map +1 -0
- package/dist/linalg/SlowVector.js +369 -0
- package/dist/linalg/SlowVector.js.map +1 -0
- package/dist/linalg/SquareMatrix.d.ts +8 -8
- package/dist/linalg/SquareMatrix.d.ts.map +1 -1
- package/dist/linalg/Vector.d.ts +84 -84
- package/dist/linalg/Vector.d.ts.map +1 -1
- package/dist/linalg/Vector2.d.ts +115 -137
- package/dist/linalg/Vector2.d.ts.map +1 -1
- package/dist/linalg/Vector2.js +164 -188
- package/dist/linalg/Vector2.js.map +1 -1
- package/dist/linalg/Vector3.d.ts +141 -167
- package/dist/linalg/Vector3.d.ts.map +1 -1
- package/dist/linalg/Vector3.js +200 -237
- package/dist/linalg/Vector3.js.map +1 -1
- package/dist/linalg/Vector4.d.ts +111 -131
- package/dist/linalg/Vector4.d.ts.map +1 -1
- package/dist/linalg/Vector4.js +163 -187
- package/dist/linalg/Vector4.js.map +1 -1
- package/dist/types/AxisAngle.d.ts +2 -2
- package/dist/types/AxisAngle.d.ts.map +1 -1
- package/dist/types/FieldOfView.d.ts +2 -2
- package/dist/types/FieldOfView.d.ts.map +1 -1
- package/dist/utility/BigNumber.d.ts +21 -11
- package/dist/utility/BigNumber.d.ts.map +1 -1
- package/dist/utility/BigNumber.js +42 -31
- package/dist/utility/BigNumber.js.map +1 -1
- package/dist/utility/MatrixSizeError.d.ts +1 -1
- package/dist/utility/MatrixSizeError.d.ts.map +1 -1
- package/dist/utility/MatrixSizeError.js +1 -1
- package/dist/utility/MatrixSizeError.js.map +1 -1
- package/dist/utility/VectorSizeError.d.ts +12 -0
- package/dist/utility/VectorSizeError.d.ts.map +1 -0
- package/dist/utility/VectorSizeError.js +15 -0
- package/dist/utility/VectorSizeError.js.map +1 -0
- package/dist/utility/createAxisAngleLike.d.ts +10 -0
- package/dist/utility/createAxisAngleLike.d.ts.map +1 -0
- package/dist/utility/createAxisAngleLike.js +10 -0
- package/dist/utility/createAxisAngleLike.js.map +1 -0
- package/package.json +11 -11
- package/src/algorithms/greatestCommonDivisor.ts +19 -7
- package/src/index.ts +24 -13
- package/src/linalg/DualQuaternion.ts +224 -292
- package/src/linalg/Matrix.ts +28 -28
- package/src/linalg/Matrix2.ts +138 -180
- package/src/linalg/Matrix3.ts +211 -286
- package/src/linalg/Matrix4.ts +466 -584
- package/src/linalg/Quaternion.ts +221 -294
- package/src/linalg/SlowMatrix.ts +97 -95
- package/src/linalg/SlowSquareMatrix.ts +19 -18
- package/src/linalg/SlowVector.ts +450 -0
- package/src/linalg/SquareMatrix.ts +9 -9
- package/src/linalg/Vector.ts +90 -90
- package/src/linalg/Vector2.ts +181 -266
- package/src/linalg/Vector3.ts +230 -342
- package/src/linalg/Vector4.ts +183 -257
- package/src/types/AxisAngle.ts +3 -3
- package/src/types/FieldOfView.ts +3 -3
- package/src/utility/BigNumber.ts +63 -41
- package/src/utility/MatrixSizeError.ts +1 -1
- package/src/utility/VectorSizeError.ts +14 -0
- package/src/utility/createAxisAngleLike.ts +14 -0
|
@@ -1,16 +1,17 @@
|
|
|
1
|
+
import radiansToDegrees from "../algorithms/radiansToDegrees.js";
|
|
2
|
+
import createAxisAngleLike from "../utility/createAxisAngleLike.js";
|
|
3
|
+
import epsilon from "../utility/epsilon.js";
|
|
1
4
|
import { createMatrix3Like, fromValues as matrix3FromValues } from "./Matrix3.js";
|
|
2
5
|
import Vector3, { createVector3Like, cross as vector3Cross, dot as vector3Dot, fromValues as vector3FromValues, getMagnitude as vector3GetMagnitude, normalize as vector3Normalize } from "./Vector3.js";
|
|
3
6
|
import { add as vector4Add, copy as vector4Copy, dot as vector4Dot, exactEquals as vector4ExactEquals, fromValues as vector4FromValues, getMagnitude as vector4GetMagnitude, getSquaredMagnitude as vector4GetSquaredMagnitude, lerp as vector4Lerp, normalize as vector4Normalize, scale as vector4Scale } from "./Vector4.js";
|
|
4
|
-
import epsilon from "../utility/epsilon.js";
|
|
5
|
-
import radiansToDegrees from "../algorithms/radiansToDegrees.js";
|
|
6
7
|
/**
|
|
7
8
|
* Create a quaternion-like object.
|
|
8
9
|
* @returns A quaternion-like object.
|
|
9
10
|
* @public
|
|
10
11
|
*/
|
|
11
|
-
export const createQuaternionLike = () =>
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
export const createQuaternionLike = () =>
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
14
|
+
new Float32Array(4);
|
|
14
15
|
/**
|
|
15
16
|
* Create a quaternion with the given values.
|
|
16
17
|
* @param x - The first component.
|
|
@@ -132,24 +133,34 @@ export const fromMatrix3 = (matrix, out) => {
|
|
|
132
133
|
if (m4 > m0) {
|
|
133
134
|
i = 1;
|
|
134
135
|
}
|
|
136
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
135
137
|
if (m8 > matrix[(i * 3 + i)]) {
|
|
136
138
|
i = 2;
|
|
137
139
|
}
|
|
140
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
138
141
|
const j = ((i + 1) % 3);
|
|
142
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
139
143
|
const k = ((i + 2) % 3);
|
|
140
|
-
let fRoot = Math.sqrt(
|
|
144
|
+
let fRoot = Math.sqrt(
|
|
145
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
146
|
+
matrix[(i * 3 + i)] -
|
|
147
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
141
148
|
matrix[(j * 3 + j)] -
|
|
149
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
142
150
|
matrix[(k * 3 + k)] +
|
|
143
151
|
1);
|
|
144
152
|
out[i] = fRoot / 2;
|
|
145
153
|
fRoot = 0.5 / fRoot;
|
|
146
154
|
out[3] =
|
|
155
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
147
156
|
(matrix[(j * 3 + k)] - matrix[(k * 3 + j)]) *
|
|
148
157
|
fRoot;
|
|
149
158
|
out[j] =
|
|
159
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
150
160
|
(matrix[(j * 3 + i)] + matrix[(i * 3 + j)]) *
|
|
151
161
|
fRoot;
|
|
152
162
|
out[k] =
|
|
163
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
153
164
|
(matrix[(k * 3 + i)] + matrix[(i * 3 + k)]) *
|
|
154
165
|
fRoot;
|
|
155
166
|
return out;
|
|
@@ -514,7 +525,7 @@ export const exp = (quaternion, out) => {
|
|
|
514
525
|
const x = quaternion[0];
|
|
515
526
|
const y = quaternion[1];
|
|
516
527
|
const z = quaternion[2];
|
|
517
|
-
const r = Math.
|
|
528
|
+
const r = Math.hypot(x, y, z);
|
|
518
529
|
const et = Math.exp(quaternion[3]);
|
|
519
530
|
const s = r > 0 ? (et * Math.sin(r)) / r : 0;
|
|
520
531
|
return fromValues(x * s, y * s, z * s, et * Math.cos(r), out);
|
|
@@ -532,7 +543,7 @@ export const ln = (quaternion, out) => {
|
|
|
532
543
|
const z = quaternion[2];
|
|
533
544
|
const w = quaternion[3];
|
|
534
545
|
const xyz2 = x * x + y * y + z * z;
|
|
535
|
-
const r = Math.sqrt(xyz2);
|
|
546
|
+
const r = Math.sqrt(xyz2);
|
|
536
547
|
const t = r > 0 ? Math.atan2(r, w) / r : 0;
|
|
537
548
|
return fromValues(x * t, y * t, z * t, Math.log(xyz2 + w * w) / 2, out);
|
|
538
549
|
};
|
|
@@ -572,9 +583,9 @@ export const slerp = (a, b, t, out) => {
|
|
|
572
583
|
bz = -bz;
|
|
573
584
|
bw = -bw;
|
|
574
585
|
}
|
|
575
|
-
// eslint-disable-next-line init-declarations
|
|
586
|
+
// eslint-disable-next-line @typescript-eslint/init-declarations
|
|
576
587
|
let scale0;
|
|
577
|
-
// eslint-disable-next-line init-declarations
|
|
588
|
+
// eslint-disable-next-line @typescript-eslint/init-declarations
|
|
578
589
|
let scale1;
|
|
579
590
|
if (1 - cosom > epsilon) {
|
|
580
591
|
const omega = Math.acos(cosom);
|
|
@@ -682,27 +693,79 @@ export const fromRotationTo = (a, b, out) => {
|
|
|
682
693
|
* @public
|
|
683
694
|
*/
|
|
684
695
|
export default class Quaternion extends Float32Array {
|
|
696
|
+
/** The first component of this quaternion. */
|
|
697
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
698
|
+
0;
|
|
699
|
+
/** The second component of this quaternion. */
|
|
700
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
701
|
+
1;
|
|
702
|
+
/** The third component of this quaternion. */
|
|
703
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
704
|
+
2;
|
|
705
|
+
/** The fourth component of this quaternion. */
|
|
706
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
707
|
+
3;
|
|
708
|
+
/** The axis and angle that represent this quaternion. */
|
|
709
|
+
get axisAngle() {
|
|
710
|
+
return getAxisAngle(this, createAxisAngleLike());
|
|
711
|
+
}
|
|
712
|
+
set axisAngle(value) {
|
|
713
|
+
setAxisAngle(value, this);
|
|
714
|
+
}
|
|
715
|
+
/** Get the magnitude (length) of this quaternion. */
|
|
716
|
+
get magnitude() {
|
|
717
|
+
return getMagnitude(this);
|
|
718
|
+
}
|
|
719
|
+
/** Get the squared magnitude (length) of this quaternion. */
|
|
720
|
+
get squaredMagnitude() {
|
|
721
|
+
return getSquaredMagnitude(this);
|
|
722
|
+
}
|
|
685
723
|
/**
|
|
686
|
-
* Create
|
|
687
|
-
* @
|
|
688
|
-
|
|
724
|
+
* Create an identity quaternion.
|
|
725
|
+
* @see {@link https://en.wikipedia.org/wiki/Quaternion | Quaternion}
|
|
726
|
+
*/
|
|
727
|
+
constructor() {
|
|
728
|
+
super(4);
|
|
729
|
+
this[3] = 1;
|
|
730
|
+
}
|
|
731
|
+
/**
|
|
732
|
+
* Create a quaternion with values corresponding to the given orthonormal set of vectors.
|
|
733
|
+
* @param view - The vector representing the viewing direction.
|
|
734
|
+
* @param right - The vector representing the local "right" direction.
|
|
735
|
+
* @param up - The vector representing the local "up" direction.
|
|
689
736
|
* @returns The quaternion.
|
|
690
|
-
* @see {@link https://en.wikipedia.org/wiki/Rotation_matrix | Rotation matrix}
|
|
691
737
|
*/
|
|
692
|
-
static
|
|
693
|
-
return
|
|
738
|
+
static fromAxes(view, right, up) {
|
|
739
|
+
return fromAxes(view, right, up, new Quaternion());
|
|
694
740
|
}
|
|
695
741
|
/**
|
|
696
742
|
* Create a quaternion from equivalent z-y'-x" (intrinsic) Tait-Bryan angles.
|
|
697
743
|
* @param z - The z (roll) angle.
|
|
698
744
|
* @param y - The y (pitch) angle.
|
|
699
745
|
* @param x - The x (yaw) angle.
|
|
700
|
-
* @param out - The quaternion to store the result in.
|
|
701
746
|
* @returns The quaternion.
|
|
702
747
|
* @see {@link https://en.wikipedia.org/wiki/Euler_angles | Euler angles}
|
|
703
748
|
*/
|
|
704
|
-
static fromEuler(z, y, x
|
|
705
|
-
return fromEuler(z, y, x,
|
|
749
|
+
static fromEuler(z, y, x) {
|
|
750
|
+
return fromEuler(z, y, x, new Quaternion());
|
|
751
|
+
}
|
|
752
|
+
/**
|
|
753
|
+
* Create a quaternion from a three-by-three rotation matrix.
|
|
754
|
+
* @param matrix - The matrix.
|
|
755
|
+
* @returns The quaternion.
|
|
756
|
+
* @see {@link https://en.wikipedia.org/wiki/Rotation_matrix | Rotation matrix}
|
|
757
|
+
*/
|
|
758
|
+
static fromMatrix3(matrix) {
|
|
759
|
+
return fromMatrix3(matrix, new Quaternion());
|
|
760
|
+
}
|
|
761
|
+
/**
|
|
762
|
+
* Create a unit quaternion that represents the shortest rotation from one unit vector to another.
|
|
763
|
+
* @param a - The first unit vector.
|
|
764
|
+
* @param b - The second unit vector.
|
|
765
|
+
* @returns The unit quaternion.
|
|
766
|
+
*/
|
|
767
|
+
static fromRotationTo(a, b) {
|
|
768
|
+
return fromRotationTo(a, b, new Quaternion());
|
|
706
769
|
}
|
|
707
770
|
/**
|
|
708
771
|
* Create a quaternion with the given values.
|
|
@@ -710,71 +773,78 @@ export default class Quaternion extends Float32Array {
|
|
|
710
773
|
* @param y - The second component.
|
|
711
774
|
* @param z - The third component.
|
|
712
775
|
* @param w - The fourth component.
|
|
713
|
-
* @param out - The quaternion to store the result in.
|
|
714
776
|
* @returns A new quaternion.
|
|
715
777
|
*/
|
|
716
|
-
static fromValues(x, y, z, w
|
|
717
|
-
return fromValues(x, y, z, w,
|
|
778
|
+
static fromValues(x, y, z, w) {
|
|
779
|
+
return fromValues(x, y, z, w, new Quaternion());
|
|
718
780
|
}
|
|
719
781
|
/**
|
|
720
|
-
*
|
|
721
|
-
* @param
|
|
722
|
-
* @
|
|
723
|
-
|
|
724
|
-
|
|
782
|
+
* Add two quaternions of the same size.
|
|
783
|
+
* @param quaternion - The other quaternion.
|
|
784
|
+
* @returns The sum of the quaternions.
|
|
785
|
+
*/
|
|
786
|
+
add(quaternion) {
|
|
787
|
+
return add(this, quaternion, new Quaternion());
|
|
788
|
+
}
|
|
789
|
+
/**
|
|
790
|
+
* Calculate the fourth component of this unit quaternion from the first three, ignoring the existing fourth component.
|
|
725
791
|
* @returns The quaternion.
|
|
726
792
|
*/
|
|
727
|
-
|
|
728
|
-
return
|
|
793
|
+
calculateW() {
|
|
794
|
+
return calculateW(this, new Quaternion());
|
|
729
795
|
}
|
|
730
796
|
/**
|
|
731
|
-
*
|
|
732
|
-
* @
|
|
733
|
-
* @param b - The second unit vector.
|
|
734
|
-
* @param out - The quaternion to store the result in.
|
|
735
|
-
* @returns The unit quaternion.
|
|
797
|
+
* Copy the values from this quaternion to another one.
|
|
798
|
+
* @returns The copy.
|
|
736
799
|
*/
|
|
737
|
-
|
|
738
|
-
return
|
|
800
|
+
clone() {
|
|
801
|
+
return copy(this, new Quaternion());
|
|
739
802
|
}
|
|
740
803
|
/**
|
|
741
|
-
*
|
|
742
|
-
* @
|
|
804
|
+
* Calculate the conjugate of this quaternion. If the quaternion is normalized, this is the same as the inverse but faster to calculate.
|
|
805
|
+
* @returns The conjugate.
|
|
743
806
|
*/
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
this[3] = 1;
|
|
807
|
+
conjugate() {
|
|
808
|
+
return conjugate(this, new Quaternion());
|
|
747
809
|
}
|
|
748
|
-
/** The first component of this quaternion. */
|
|
749
|
-
0;
|
|
750
|
-
/** The second component of this quaternion. */
|
|
751
|
-
1;
|
|
752
|
-
/** The third component of this quaternion. */
|
|
753
|
-
2;
|
|
754
|
-
/** The fourth component of this quaternion. */
|
|
755
|
-
3;
|
|
756
810
|
/**
|
|
757
|
-
*
|
|
811
|
+
* Copy the values of another quaternion into this one.
|
|
812
|
+
* @param quaternion - The quaternion to copy.
|
|
758
813
|
* @returns This quaternion.
|
|
759
814
|
*/
|
|
760
|
-
|
|
761
|
-
return
|
|
815
|
+
copy(quaternion) {
|
|
816
|
+
return copy(quaternion, this);
|
|
762
817
|
}
|
|
763
818
|
/**
|
|
764
|
-
*
|
|
765
|
-
* @param
|
|
766
|
-
* @returns The
|
|
819
|
+
* Calculate the dot product of this and another quaternion.
|
|
820
|
+
* @param quaternion - The other quaternion.
|
|
821
|
+
* @returns The dot product.
|
|
767
822
|
*/
|
|
768
|
-
|
|
769
|
-
return
|
|
823
|
+
dot(quaternion) {
|
|
824
|
+
return dot(this, quaternion);
|
|
770
825
|
}
|
|
771
826
|
/**
|
|
772
|
-
*
|
|
773
|
-
* @param
|
|
774
|
-
* @returns
|
|
827
|
+
* Determine whether or not this quaternion is roughly equivalent to another.
|
|
828
|
+
* @param quaternion - The other quaternion.
|
|
829
|
+
* @returns Whether or not the quaternions are equivalent.
|
|
775
830
|
*/
|
|
776
|
-
|
|
777
|
-
return
|
|
831
|
+
equals(quaternion) {
|
|
832
|
+
return equals(this, quaternion);
|
|
833
|
+
}
|
|
834
|
+
/**
|
|
835
|
+
* Determine whether or not this quaternion is exactly equivalent to another.
|
|
836
|
+
* @param quaternion - The other quaternion.
|
|
837
|
+
* @returns Whether or not the quaternions are equivalent.
|
|
838
|
+
*/
|
|
839
|
+
exactEquals(quaternion) {
|
|
840
|
+
return exactEquals(this, quaternion);
|
|
841
|
+
}
|
|
842
|
+
/**
|
|
843
|
+
* Calculate the exponential of this unit quaternion.
|
|
844
|
+
* @returns The exponential.
|
|
845
|
+
*/
|
|
846
|
+
exp() {
|
|
847
|
+
return exp(this, new Quaternion());
|
|
778
848
|
}
|
|
779
849
|
/**
|
|
780
850
|
* Get the angular distance between this unit quaternion and another.
|
|
@@ -785,84 +855,57 @@ export default class Quaternion extends Float32Array {
|
|
|
785
855
|
return getAngle(this, quaternion);
|
|
786
856
|
}
|
|
787
857
|
/**
|
|
788
|
-
*
|
|
789
|
-
* @
|
|
790
|
-
* @param out - The quaternion to store the result in.
|
|
791
|
-
* @returns The product.
|
|
792
|
-
*/
|
|
793
|
-
multiply(quaternion, out = new Quaternion()) {
|
|
794
|
-
return multiply(this, quaternion, out);
|
|
795
|
-
}
|
|
796
|
-
/**
|
|
797
|
-
* Rotate this quaternion by the given angle around the X-axis.
|
|
798
|
-
* @param r - The angle in radians.
|
|
799
|
-
* @param out - The quaternion to store the result in.
|
|
800
|
-
* @returns The rotated quaternion.
|
|
858
|
+
* Set this quaternion to the identity.
|
|
859
|
+
* @returns This quaternion.
|
|
801
860
|
*/
|
|
802
|
-
|
|
803
|
-
return
|
|
861
|
+
identity() {
|
|
862
|
+
return identity(this);
|
|
804
863
|
}
|
|
805
864
|
/**
|
|
806
|
-
*
|
|
807
|
-
* @
|
|
808
|
-
* @param out - The quaternion to store the result in.
|
|
809
|
-
* @returns The rotated quaternion.
|
|
865
|
+
* Calculate the inverse of this quaternion. If the quaternion is normalized, the conjugate is the same but faster to calculate.
|
|
866
|
+
* @returns The inverse.
|
|
810
867
|
*/
|
|
811
|
-
|
|
812
|
-
return
|
|
868
|
+
invert() {
|
|
869
|
+
return invert(this, new Quaternion());
|
|
813
870
|
}
|
|
814
871
|
/**
|
|
815
|
-
*
|
|
816
|
-
* @param
|
|
817
|
-
* @param
|
|
818
|
-
* @returns The
|
|
872
|
+
* Perform a linear interpolation between this and another quaternion.
|
|
873
|
+
* @param quaternion - The other quaternion.
|
|
874
|
+
* @param t - The interpolation amount (in `[0,1]`).
|
|
875
|
+
* @returns The interpolated quaternion.
|
|
819
876
|
*/
|
|
820
|
-
|
|
821
|
-
return
|
|
877
|
+
lerp(quaternion, t) {
|
|
878
|
+
return lerp(this, quaternion, t, new Quaternion());
|
|
822
879
|
}
|
|
823
880
|
/**
|
|
824
|
-
* Calculate the
|
|
825
|
-
* @
|
|
826
|
-
* @returns The quaternion.
|
|
881
|
+
* Calculate the natural logarithm of this unit quaternion.
|
|
882
|
+
* @returns The natural logarithm.
|
|
827
883
|
*/
|
|
828
|
-
|
|
829
|
-
return
|
|
884
|
+
ln() {
|
|
885
|
+
return ln(this, new Quaternion());
|
|
830
886
|
}
|
|
831
887
|
/**
|
|
832
|
-
*
|
|
833
|
-
* @param
|
|
834
|
-
* @returns The
|
|
888
|
+
* Multiply this and another quaternion.
|
|
889
|
+
* @param quaternion - The other quaternion.
|
|
890
|
+
* @returns The product.
|
|
835
891
|
*/
|
|
836
|
-
|
|
837
|
-
return
|
|
892
|
+
multiply(quaternion) {
|
|
893
|
+
return multiply(this, quaternion, new Quaternion());
|
|
838
894
|
}
|
|
839
895
|
/**
|
|
840
|
-
*
|
|
841
|
-
* @
|
|
842
|
-
* @returns The natural logarithm.
|
|
896
|
+
* Normalize this quaternion.
|
|
897
|
+
* @returns The normalized quaternion.
|
|
843
898
|
*/
|
|
844
|
-
|
|
845
|
-
return
|
|
899
|
+
normalize() {
|
|
900
|
+
return normalize(this, new Quaternion());
|
|
846
901
|
}
|
|
847
902
|
/**
|
|
848
903
|
* Calculate a power of this unit quaternion.
|
|
849
904
|
* @param scalar - The amount to scale the quaternion by.
|
|
850
|
-
* @param out - The quaternion to store the result in.
|
|
851
905
|
* @returns The power.
|
|
852
906
|
*/
|
|
853
|
-
pow(scalar
|
|
854
|
-
return pow(this, scalar,
|
|
855
|
-
}
|
|
856
|
-
/**
|
|
857
|
-
* Perform a spherical linear interpolation between this and another quaternion.
|
|
858
|
-
* @param quaternion - The other quaternion.
|
|
859
|
-
* @param t - The interpolation amount in `[0,1]`.
|
|
860
|
-
* @param out - The quaternion to store the result in.
|
|
861
|
-
* @returns The interpolated quaternion.
|
|
862
|
-
* @see {@link https://en.wikipedia.org/wiki/Slerp | Slerp}
|
|
863
|
-
*/
|
|
864
|
-
slerp(quaternion, t, out = new Quaternion()) {
|
|
865
|
-
return slerp(this, quaternion, t, out);
|
|
907
|
+
pow(scalar) {
|
|
908
|
+
return pow(this, scalar, new Quaternion());
|
|
866
909
|
}
|
|
867
910
|
/**
|
|
868
911
|
* Set this to a random unit quaternion.
|
|
@@ -872,104 +915,46 @@ export default class Quaternion extends Float32Array {
|
|
|
872
915
|
return random(this);
|
|
873
916
|
}
|
|
874
917
|
/**
|
|
875
|
-
*
|
|
876
|
-
* @param
|
|
877
|
-
* @returns The
|
|
878
|
-
*/
|
|
879
|
-
invert(out = new Quaternion()) {
|
|
880
|
-
return invert(this, out);
|
|
881
|
-
}
|
|
882
|
-
/**
|
|
883
|
-
* Calculate the conjugate of this quaternion. If the quaternion is normalized, this is the same as the inverse but faster to calculate.
|
|
884
|
-
* @param out - The quaternion to store the result in.
|
|
885
|
-
* @returns The conjugate.
|
|
886
|
-
*/
|
|
887
|
-
conjugate(out = new Quaternion()) {
|
|
888
|
-
return conjugate(this, out);
|
|
889
|
-
}
|
|
890
|
-
/**
|
|
891
|
-
* Copy the values from this quaternion to another one.
|
|
892
|
-
* @param out - The quaternion to store the result in.
|
|
893
|
-
* @returns The copy.
|
|
918
|
+
* Rotate this quaternion by the given angle around the X-axis.
|
|
919
|
+
* @param r - The angle in radians.
|
|
920
|
+
* @returns The rotated quaternion.
|
|
894
921
|
*/
|
|
895
|
-
|
|
896
|
-
return
|
|
922
|
+
rotateX(r) {
|
|
923
|
+
return rotateX(this, r, new Quaternion());
|
|
897
924
|
}
|
|
898
925
|
/**
|
|
899
|
-
*
|
|
900
|
-
* @param
|
|
901
|
-
* @returns
|
|
926
|
+
* Rotate this quaternion by the given angle around the Y-axis.
|
|
927
|
+
* @param r - The angle in radians.
|
|
928
|
+
* @returns The rotated quaternion.
|
|
902
929
|
*/
|
|
903
|
-
|
|
904
|
-
return
|
|
930
|
+
rotateY(r) {
|
|
931
|
+
return rotateY(this, r, new Quaternion());
|
|
905
932
|
}
|
|
906
933
|
/**
|
|
907
|
-
*
|
|
908
|
-
* @param
|
|
909
|
-
* @
|
|
910
|
-
* @returns The sum of the quaternions.
|
|
934
|
+
* Rotate this quaternion by the given angle around the Z-axis.
|
|
935
|
+
* @param r - The angle in radians.
|
|
936
|
+
* @returns The rotated quaternion.
|
|
911
937
|
*/
|
|
912
|
-
|
|
913
|
-
return
|
|
938
|
+
rotateZ(r) {
|
|
939
|
+
return rotateZ(this, r, new Quaternion());
|
|
914
940
|
}
|
|
915
941
|
/**
|
|
916
942
|
* Scale this quaternion by a scalar.
|
|
917
943
|
* @param scalar - The scalar.
|
|
918
|
-
* @param out - The quaternion to store the result in.
|
|
919
944
|
* @returns The scaled quaternion.
|
|
920
945
|
*/
|
|
921
|
-
scale(scalar
|
|
922
|
-
return scale(this, scalar,
|
|
923
|
-
}
|
|
924
|
-
/**
|
|
925
|
-
* Calculate the dot product of this and another quaternion.
|
|
926
|
-
* @param quaternion - The other quaternion.
|
|
927
|
-
* @returns The dot product.
|
|
928
|
-
*/
|
|
929
|
-
dot(quaternion) {
|
|
930
|
-
return dot(this, quaternion);
|
|
946
|
+
scale(scalar) {
|
|
947
|
+
return scale(this, scalar, new Quaternion());
|
|
931
948
|
}
|
|
932
949
|
/**
|
|
933
|
-
* Perform a linear interpolation between this and another quaternion.
|
|
950
|
+
* Perform a spherical linear interpolation between this and another quaternion.
|
|
934
951
|
* @param quaternion - The other quaternion.
|
|
935
|
-
* @param t - The interpolation amount
|
|
936
|
-
* @param out - The quaternion to store the result in.
|
|
952
|
+
* @param t - The interpolation amount in `[0,1]`.
|
|
937
953
|
* @returns The interpolated quaternion.
|
|
954
|
+
* @see {@link https://en.wikipedia.org/wiki/Slerp | Slerp}
|
|
938
955
|
*/
|
|
939
|
-
|
|
940
|
-
return
|
|
941
|
-
}
|
|
942
|
-
/** Get the magnitude (length) of this quaternion. */
|
|
943
|
-
get magnitude() {
|
|
944
|
-
return getMagnitude(this);
|
|
945
|
-
}
|
|
946
|
-
/** Get the squared magnitude (length) of this quaternion. */
|
|
947
|
-
get squaredMagnitude() {
|
|
948
|
-
return getSquaredMagnitude(this);
|
|
949
|
-
}
|
|
950
|
-
/**
|
|
951
|
-
* Normalize this quaternion.
|
|
952
|
-
* @param out - The quaternion to store the result in.
|
|
953
|
-
* @returns The normalized quaternion.
|
|
954
|
-
*/
|
|
955
|
-
normalize(out = new Quaternion()) {
|
|
956
|
-
return normalize(this, out);
|
|
957
|
-
}
|
|
958
|
-
/**
|
|
959
|
-
* Determine whether or not this quaternion is roughly equivalent to another.
|
|
960
|
-
* @param quaternion - The other quaternion.
|
|
961
|
-
* @returns Whether or not the quaternions are equivalent.
|
|
962
|
-
*/
|
|
963
|
-
equals(quaternion) {
|
|
964
|
-
return equals(this, quaternion);
|
|
965
|
-
}
|
|
966
|
-
/**
|
|
967
|
-
* Determine whether or not this quaternion is exactly equivalent to another.
|
|
968
|
-
* @param quaternion - The other quaternion.
|
|
969
|
-
* @returns Whether or not the quaternions are equivalent.
|
|
970
|
-
*/
|
|
971
|
-
exactEquals(quaternion) {
|
|
972
|
-
return exactEquals(this, quaternion);
|
|
956
|
+
slerp(quaternion, t) {
|
|
957
|
+
return slerp(this, quaternion, t, new Quaternion());
|
|
973
958
|
}
|
|
974
959
|
/**
|
|
975
960
|
* Perform a spherical linear interpolation with two control points between this and another quaternion.
|
|
@@ -977,20 +962,18 @@ export default class Quaternion extends Float32Array {
|
|
|
977
962
|
* @param b - The second control point.
|
|
978
963
|
* @param quaternion - The other quaternion.
|
|
979
964
|
* @param t - The interpolation amount in `[0,1]`.
|
|
980
|
-
* @param out - The quaternion to store the result in.
|
|
981
965
|
* @returns The interpolated value.
|
|
982
966
|
* @see {@link https://en.wikipedia.org/wiki/Slerp | Slerp}
|
|
983
967
|
*/
|
|
984
|
-
sqlerp(a, b, quaternion, t
|
|
985
|
-
return sqlerp(this, a, b, quaternion, t,
|
|
968
|
+
sqlerp(a, b, quaternion, t) {
|
|
969
|
+
return sqlerp(this, a, b, quaternion, t, new Quaternion());
|
|
986
970
|
}
|
|
987
971
|
/**
|
|
988
972
|
* Convert this quaternion to equivalent z-y'-x" (intrinsic) Tait-Bryan angles.
|
|
989
|
-
* @param out - The vector in which to store the Tait-Bryan angles.
|
|
990
973
|
* @returns The Tait-Bryan angles in degrees in roll (z), pitch (y'), yaw (x") order.
|
|
991
974
|
*/
|
|
992
|
-
toEuler(
|
|
993
|
-
return toEuler(this,
|
|
975
|
+
toEuler() {
|
|
976
|
+
return toEuler(this, new Vector3());
|
|
994
977
|
}
|
|
995
978
|
}
|
|
996
979
|
//# sourceMappingURL=Quaternion.js.map
|