@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
package/src/linalg/Quaternion.ts
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
|
+
import type AxisAngle from "../types/AxisAngle.js";
|
|
2
|
+
|
|
3
|
+
import radiansToDegrees from "../algorithms/radiansToDegrees.js";
|
|
4
|
+
import createAxisAngleLike from "../utility/createAxisAngleLike.js";
|
|
5
|
+
import epsilon from "../utility/epsilon.js";
|
|
1
6
|
import {
|
|
2
|
-
type Matrix3Like,
|
|
3
7
|
createMatrix3Like,
|
|
4
|
-
fromValues as matrix3FromValues
|
|
8
|
+
fromValues as matrix3FromValues,
|
|
9
|
+
type Matrix3Like
|
|
5
10
|
} from "./Matrix3.js";
|
|
6
11
|
import Vector3, {
|
|
7
|
-
type Vector3Like,
|
|
8
12
|
createVector3Like,
|
|
9
13
|
cross as vector3Cross,
|
|
10
14
|
dot as vector3Dot,
|
|
11
15
|
fromValues as vector3FromValues,
|
|
12
16
|
getMagnitude as vector3GetMagnitude,
|
|
17
|
+
type Vector3Like,
|
|
13
18
|
normalize as vector3Normalize
|
|
14
19
|
} from "./Vector3.js";
|
|
15
20
|
import {
|
|
@@ -24,9 +29,6 @@ import {
|
|
|
24
29
|
normalize as vector4Normalize,
|
|
25
30
|
scale as vector4Scale
|
|
26
31
|
} from "./Vector4.js";
|
|
27
|
-
import type AxisAngle from "../types/AxisAngle.js";
|
|
28
|
-
import epsilon from "../utility/epsilon.js";
|
|
29
|
-
import radiansToDegrees from "../algorithms/radiansToDegrees.js";
|
|
30
32
|
|
|
31
33
|
/**
|
|
32
34
|
* A complex number that is commonly used to describe rotations.
|
|
@@ -35,15 +37,19 @@ import radiansToDegrees from "../algorithms/radiansToDegrees.js";
|
|
|
35
37
|
*/
|
|
36
38
|
export interface QuaternionLike extends Record<number, number> {
|
|
37
39
|
/** The first component of this quaternion. */
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
38
41
|
0: number;
|
|
39
42
|
|
|
40
43
|
/** The second component of this quaternion. */
|
|
44
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
41
45
|
1: number;
|
|
42
46
|
|
|
43
47
|
/** The third component of this quaternion. */
|
|
48
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
44
49
|
2: number;
|
|
45
50
|
|
|
46
51
|
/** The fourth component of this quaternion. */
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
47
53
|
3: number;
|
|
48
54
|
}
|
|
49
55
|
|
|
@@ -52,9 +58,9 @@ export interface QuaternionLike extends Record<number, number> {
|
|
|
52
58
|
* @returns A quaternion-like object.
|
|
53
59
|
* @public
|
|
54
60
|
*/
|
|
55
|
-
export const createQuaternionLike = (): Float32Array & QuaternionLike =>
|
|
56
|
-
|
|
57
|
-
|
|
61
|
+
export const createQuaternionLike = (): Float32Array & QuaternionLike =>
|
|
62
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
63
|
+
new Float32Array(4) as Float32Array & QuaternionLike;
|
|
58
64
|
|
|
59
65
|
/**
|
|
60
66
|
* Create a quaternion with the given values.
|
|
@@ -222,28 +228,37 @@ export const fromMatrix3 = <T extends QuaternionLike>(
|
|
|
222
228
|
if (m4 > m0) {
|
|
223
229
|
i = 1;
|
|
224
230
|
}
|
|
231
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
225
232
|
if (m8 > matrix[(i * 3 + i) as 0 | 4]) {
|
|
226
233
|
i = 2;
|
|
227
234
|
}
|
|
228
|
-
|
|
229
|
-
const
|
|
235
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
236
|
+
const j = ((i + 1) % 3) as 0 | 1 | 2;
|
|
237
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
238
|
+
const k = ((i + 2) % 3) as 0 | 1 | 2;
|
|
230
239
|
|
|
231
240
|
let fRoot: number = Math.sqrt(
|
|
241
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
232
242
|
matrix[(i * 3 + i) as 0 | 4 | 7] -
|
|
233
|
-
|
|
234
|
-
matrix[(
|
|
243
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
244
|
+
matrix[(j * 3 + j) as 0 | 4 | 7] -
|
|
245
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
246
|
+
matrix[(k * 3 + k) as 0 | 4 | 7] +
|
|
235
247
|
1
|
|
236
248
|
);
|
|
237
249
|
out[i] = fRoot / 2;
|
|
238
250
|
fRoot = 0.5 / fRoot;
|
|
239
251
|
out[3] =
|
|
240
|
-
|
|
252
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
253
|
+
(matrix[(j * 3 + k) as 1 | 5 | 6] - matrix[(k * 3 + j) as 2 | 3 | 7]) *
|
|
241
254
|
fRoot;
|
|
242
255
|
out[j] =
|
|
243
|
-
|
|
256
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
257
|
+
(matrix[(j * 3 + i) as 2 | 3 | 7] + matrix[(i * 3 + j) as 1 | 5 | 6]) *
|
|
244
258
|
fRoot;
|
|
245
259
|
out[k] =
|
|
246
|
-
|
|
260
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
261
|
+
(matrix[(k * 3 + i) as 1 | 5 | 6] + matrix[(i * 3 + k) as 2 | 3 | 7]) *
|
|
247
262
|
fRoot;
|
|
248
263
|
return out;
|
|
249
264
|
};
|
|
@@ -826,7 +841,7 @@ export const exp = <T extends QuaternionLike>(
|
|
|
826
841
|
const y = quaternion[1];
|
|
827
842
|
const z = quaternion[2];
|
|
828
843
|
|
|
829
|
-
const r = Math.
|
|
844
|
+
const r = Math.hypot(x, y, z);
|
|
830
845
|
const et = Math.exp(quaternion[3]);
|
|
831
846
|
const s = r > 0 ? (et * Math.sin(r)) / r : 0;
|
|
832
847
|
|
|
@@ -850,7 +865,7 @@ export const ln = <T extends QuaternionLike>(
|
|
|
850
865
|
const w = quaternion[3];
|
|
851
866
|
|
|
852
867
|
const xyz2 = x * x + y * y + z * z;
|
|
853
|
-
const r = Math.sqrt(xyz2);
|
|
868
|
+
const r = Math.sqrt(xyz2);
|
|
854
869
|
const t = r > 0 ? Math.atan2(r, w) / r : 0;
|
|
855
870
|
|
|
856
871
|
return fromValues(x * t, y * t, z * t, Math.log(xyz2 + w * w) / 2, out);
|
|
@@ -905,9 +920,9 @@ export const slerp = <T extends QuaternionLike>(
|
|
|
905
920
|
bw = -bw;
|
|
906
921
|
}
|
|
907
922
|
|
|
908
|
-
// eslint-disable-next-line init-declarations
|
|
923
|
+
// eslint-disable-next-line @typescript-eslint/init-declarations
|
|
909
924
|
let scale0;
|
|
910
|
-
// eslint-disable-next-line init-declarations
|
|
925
|
+
// eslint-disable-next-line @typescript-eslint/init-declarations
|
|
911
926
|
let scale1;
|
|
912
927
|
if (1 - cosom > epsilon) {
|
|
913
928
|
const omega = Math.acos(cosom);
|
|
@@ -1074,18 +1089,63 @@ export const fromRotationTo = <T extends QuaternionLike>(
|
|
|
1074
1089
|
* @public
|
|
1075
1090
|
*/
|
|
1076
1091
|
export default class Quaternion extends Float32Array implements QuaternionLike {
|
|
1092
|
+
/** The first component of this quaternion. */
|
|
1093
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1094
|
+
public 0: number;
|
|
1095
|
+
|
|
1096
|
+
/** The second component of this quaternion. */
|
|
1097
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1098
|
+
public 1: number;
|
|
1099
|
+
|
|
1100
|
+
/** The third component of this quaternion. */
|
|
1101
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1102
|
+
public 2: number;
|
|
1103
|
+
|
|
1104
|
+
/** The fourth component of this quaternion. */
|
|
1105
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1106
|
+
public 3: number;
|
|
1107
|
+
|
|
1108
|
+
/** The axis and angle that represent this quaternion. */
|
|
1109
|
+
public get axisAngle(): ReturnType<typeof createAxisAngleLike> {
|
|
1110
|
+
return getAxisAngle(this, createAxisAngleLike());
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
public set axisAngle(value: AxisAngle) {
|
|
1114
|
+
setAxisAngle(value, this);
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
/** Get the magnitude (length) of this quaternion. */
|
|
1118
|
+
public get magnitude(): number {
|
|
1119
|
+
return getMagnitude(this);
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
/** Get the squared magnitude (length) of this quaternion. */
|
|
1123
|
+
public get squaredMagnitude(): number {
|
|
1124
|
+
return getSquaredMagnitude(this);
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1077
1127
|
/**
|
|
1078
|
-
* Create
|
|
1079
|
-
* @
|
|
1080
|
-
|
|
1128
|
+
* Create an identity quaternion.
|
|
1129
|
+
* @see {@link https://en.wikipedia.org/wiki/Quaternion | Quaternion}
|
|
1130
|
+
*/
|
|
1131
|
+
public constructor() {
|
|
1132
|
+
super(4);
|
|
1133
|
+
this[3] = 1;
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
/**
|
|
1137
|
+
* Create a quaternion with values corresponding to the given orthonormal set of vectors.
|
|
1138
|
+
* @param view - The vector representing the viewing direction.
|
|
1139
|
+
* @param right - The vector representing the local "right" direction.
|
|
1140
|
+
* @param up - The vector representing the local "up" direction.
|
|
1081
1141
|
* @returns The quaternion.
|
|
1082
|
-
* @see {@link https://en.wikipedia.org/wiki/Rotation_matrix | Rotation matrix}
|
|
1083
1142
|
*/
|
|
1084
|
-
public static
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1143
|
+
public static fromAxes(
|
|
1144
|
+
view: Vector3Like,
|
|
1145
|
+
right: Vector3Like,
|
|
1146
|
+
up: Vector3Like
|
|
1147
|
+
): Quaternion {
|
|
1148
|
+
return fromAxes(view, right, up, new Quaternion());
|
|
1089
1149
|
}
|
|
1090
1150
|
|
|
1091
1151
|
/**
|
|
@@ -1093,17 +1153,31 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
|
|
|
1093
1153
|
* @param z - The z (roll) angle.
|
|
1094
1154
|
* @param y - The y (pitch) angle.
|
|
1095
1155
|
* @param x - The x (yaw) angle.
|
|
1096
|
-
* @param out - The quaternion to store the result in.
|
|
1097
1156
|
* @returns The quaternion.
|
|
1098
1157
|
* @see {@link https://en.wikipedia.org/wiki/Euler_angles | Euler angles}
|
|
1099
1158
|
*/
|
|
1100
|
-
public static fromEuler
|
|
1101
|
-
z
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1159
|
+
public static fromEuler(z: number, y: number, x: number): Quaternion {
|
|
1160
|
+
return fromEuler(z, y, x, new Quaternion());
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
/**
|
|
1164
|
+
* Create a quaternion from a three-by-three rotation matrix.
|
|
1165
|
+
* @param matrix - The matrix.
|
|
1166
|
+
* @returns The quaternion.
|
|
1167
|
+
* @see {@link https://en.wikipedia.org/wiki/Rotation_matrix | Rotation matrix}
|
|
1168
|
+
*/
|
|
1169
|
+
public static fromMatrix3(matrix: Matrix3Like): Quaternion {
|
|
1170
|
+
return fromMatrix3(matrix, new Quaternion());
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1173
|
+
/**
|
|
1174
|
+
* Create a unit quaternion that represents the shortest rotation from one unit vector to another.
|
|
1175
|
+
* @param a - The first unit vector.
|
|
1176
|
+
* @param b - The second unit vector.
|
|
1177
|
+
* @returns The unit quaternion.
|
|
1178
|
+
*/
|
|
1179
|
+
public static fromRotationTo(a: Vector3Like, b: Vector3Like): Quaternion {
|
|
1180
|
+
return fromRotationTo(a, b, new Quaternion());
|
|
1107
1181
|
}
|
|
1108
1182
|
|
|
1109
1183
|
/**
|
|
@@ -1112,358 +1186,216 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
|
|
|
1112
1186
|
* @param y - The second component.
|
|
1113
1187
|
* @param z - The third component.
|
|
1114
1188
|
* @param w - The fourth component.
|
|
1115
|
-
* @param out - The quaternion to store the result in.
|
|
1116
1189
|
* @returns A new quaternion.
|
|
1117
1190
|
*/
|
|
1118
|
-
public static fromValues
|
|
1191
|
+
public static fromValues(
|
|
1119
1192
|
x: number,
|
|
1120
1193
|
y: number,
|
|
1121
1194
|
z: number,
|
|
1122
|
-
w: number
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
return fromValues(x, y, z, w, out);
|
|
1195
|
+
w: number
|
|
1196
|
+
): Quaternion {
|
|
1197
|
+
return fromValues(x, y, z, w, new Quaternion());
|
|
1126
1198
|
}
|
|
1127
1199
|
|
|
1128
1200
|
/**
|
|
1129
|
-
*
|
|
1130
|
-
* @param
|
|
1131
|
-
* @
|
|
1132
|
-
* @param up - The vector representing the local "up" direction.
|
|
1133
|
-
* @param out - The quaternion to store the result in.
|
|
1134
|
-
* @returns The quaternion.
|
|
1201
|
+
* Add two quaternions of the same size.
|
|
1202
|
+
* @param quaternion - The other quaternion.
|
|
1203
|
+
* @returns The sum of the quaternions.
|
|
1135
1204
|
*/
|
|
1136
|
-
public
|
|
1137
|
-
|
|
1138
|
-
right: Vector3Like,
|
|
1139
|
-
up: Vector3Like,
|
|
1140
|
-
out: T = new Quaternion() as Quaternion & T
|
|
1141
|
-
): T {
|
|
1142
|
-
return fromAxes(view, right, up, out);
|
|
1205
|
+
public add(quaternion: QuaternionLike): Quaternion {
|
|
1206
|
+
return add(this, quaternion, new Quaternion());
|
|
1143
1207
|
}
|
|
1144
1208
|
|
|
1145
1209
|
/**
|
|
1146
|
-
*
|
|
1147
|
-
* @
|
|
1148
|
-
* @param b - The second unit vector.
|
|
1149
|
-
* @param out - The quaternion to store the result in.
|
|
1150
|
-
* @returns The unit quaternion.
|
|
1210
|
+
* Calculate the fourth component of this unit quaternion from the first three, ignoring the existing fourth component.
|
|
1211
|
+
* @returns The quaternion.
|
|
1151
1212
|
*/
|
|
1152
|
-
public
|
|
1153
|
-
|
|
1154
|
-
b: Vector3Like,
|
|
1155
|
-
out: T = new Quaternion() as Quaternion & T
|
|
1156
|
-
): T {
|
|
1157
|
-
return fromRotationTo(a, b, out);
|
|
1213
|
+
public calculateW(): Quaternion {
|
|
1214
|
+
return calculateW(this, new Quaternion());
|
|
1158
1215
|
}
|
|
1159
1216
|
|
|
1160
1217
|
/**
|
|
1161
|
-
*
|
|
1162
|
-
* @
|
|
1218
|
+
* Copy the values from this quaternion to another one.
|
|
1219
|
+
* @returns The copy.
|
|
1163
1220
|
*/
|
|
1164
|
-
public
|
|
1165
|
-
|
|
1166
|
-
this[3] = 1;
|
|
1221
|
+
public clone(): Quaternion {
|
|
1222
|
+
return copy(this, new Quaternion());
|
|
1167
1223
|
}
|
|
1168
1224
|
|
|
1169
|
-
/** The first component of this quaternion. */
|
|
1170
|
-
public 0: number;
|
|
1171
|
-
|
|
1172
|
-
/** The second component of this quaternion. */
|
|
1173
|
-
public 1: number;
|
|
1174
|
-
|
|
1175
|
-
/** The third component of this quaternion. */
|
|
1176
|
-
public 2: number;
|
|
1177
|
-
|
|
1178
|
-
/** The fourth component of this quaternion. */
|
|
1179
|
-
public 3: number;
|
|
1180
|
-
|
|
1181
1225
|
/**
|
|
1182
|
-
*
|
|
1183
|
-
* @returns
|
|
1226
|
+
* Calculate the conjugate of this quaternion. If the quaternion is normalized, this is the same as the inverse but faster to calculate.
|
|
1227
|
+
* @returns The conjugate.
|
|
1184
1228
|
*/
|
|
1185
|
-
public
|
|
1186
|
-
return
|
|
1229
|
+
public conjugate(): Quaternion {
|
|
1230
|
+
return conjugate(this, new Quaternion());
|
|
1187
1231
|
}
|
|
1188
1232
|
|
|
1189
1233
|
/**
|
|
1190
|
-
*
|
|
1191
|
-
* @param
|
|
1192
|
-
* @returns
|
|
1234
|
+
* Copy the values of another quaternion into this one.
|
|
1235
|
+
* @param quaternion - The quaternion to copy.
|
|
1236
|
+
* @returns This quaternion.
|
|
1193
1237
|
*/
|
|
1194
|
-
public
|
|
1195
|
-
return
|
|
1238
|
+
public copy(quaternion: QuaternionLike): this {
|
|
1239
|
+
return copy(quaternion, this);
|
|
1196
1240
|
}
|
|
1197
1241
|
|
|
1198
1242
|
/**
|
|
1199
|
-
*
|
|
1200
|
-
* @param
|
|
1201
|
-
* @returns
|
|
1243
|
+
* Calculate the dot product of this and another quaternion.
|
|
1244
|
+
* @param quaternion - The other quaternion.
|
|
1245
|
+
* @returns The dot product.
|
|
1202
1246
|
*/
|
|
1203
|
-
public
|
|
1204
|
-
return
|
|
1247
|
+
public dot(quaternion: QuaternionLike): number {
|
|
1248
|
+
return dot(this, quaternion);
|
|
1205
1249
|
}
|
|
1206
1250
|
|
|
1207
1251
|
/**
|
|
1208
|
-
*
|
|
1209
|
-
* @param quaternion - The other
|
|
1210
|
-
* @returns
|
|
1252
|
+
* Determine whether or not this quaternion is roughly equivalent to another.
|
|
1253
|
+
* @param quaternion - The other quaternion.
|
|
1254
|
+
* @returns Whether or not the quaternions are equivalent.
|
|
1211
1255
|
*/
|
|
1212
|
-
public
|
|
1213
|
-
return
|
|
1256
|
+
public equals(quaternion: QuaternionLike): boolean {
|
|
1257
|
+
return equals(this, quaternion);
|
|
1214
1258
|
}
|
|
1215
1259
|
|
|
1216
1260
|
/**
|
|
1217
|
-
*
|
|
1261
|
+
* Determine whether or not this quaternion is exactly equivalent to another.
|
|
1218
1262
|
* @param quaternion - The other quaternion.
|
|
1219
|
-
* @
|
|
1220
|
-
* @returns The product.
|
|
1263
|
+
* @returns Whether or not the quaternions are equivalent.
|
|
1221
1264
|
*/
|
|
1222
|
-
public
|
|
1223
|
-
|
|
1224
|
-
out: T = new Quaternion() as Quaternion & T
|
|
1225
|
-
): T {
|
|
1226
|
-
return multiply(this, quaternion, out);
|
|
1265
|
+
public exactEquals(quaternion: QuaternionLike): boolean {
|
|
1266
|
+
return exactEquals(this, quaternion);
|
|
1227
1267
|
}
|
|
1228
1268
|
|
|
1229
1269
|
/**
|
|
1230
|
-
*
|
|
1231
|
-
* @
|
|
1232
|
-
* @param out - The quaternion to store the result in.
|
|
1233
|
-
* @returns The rotated quaternion.
|
|
1270
|
+
* Calculate the exponential of this unit quaternion.
|
|
1271
|
+
* @returns The exponential.
|
|
1234
1272
|
*/
|
|
1235
|
-
public
|
|
1236
|
-
|
|
1237
|
-
out: T = new Quaternion() as Quaternion & T
|
|
1238
|
-
): T {
|
|
1239
|
-
return rotateX(this, r, out);
|
|
1273
|
+
public exp(): Quaternion {
|
|
1274
|
+
return exp(this, new Quaternion());
|
|
1240
1275
|
}
|
|
1241
1276
|
|
|
1242
1277
|
/**
|
|
1243
|
-
*
|
|
1244
|
-
* @param
|
|
1245
|
-
* @
|
|
1246
|
-
* @returns The rotated quaternion.
|
|
1278
|
+
* Get the angular distance between this unit quaternion and another.
|
|
1279
|
+
* @param quaternion - The other unit quaternion.
|
|
1280
|
+
* @returns The angular distance in radians.
|
|
1247
1281
|
*/
|
|
1248
|
-
public
|
|
1249
|
-
|
|
1250
|
-
out: T = new Quaternion() as Quaternion & T
|
|
1251
|
-
): T {
|
|
1252
|
-
return rotateY(this, r, out);
|
|
1282
|
+
public getAngle(quaternion: QuaternionLike): number {
|
|
1283
|
+
return getAngle(this, quaternion);
|
|
1253
1284
|
}
|
|
1254
1285
|
|
|
1255
1286
|
/**
|
|
1256
|
-
*
|
|
1257
|
-
* @
|
|
1258
|
-
* @param out - The quaternion to store the result in.
|
|
1259
|
-
* @returns The rotated quaternion.
|
|
1287
|
+
* Set this quaternion to the identity.
|
|
1288
|
+
* @returns This quaternion.
|
|
1260
1289
|
*/
|
|
1261
|
-
public
|
|
1262
|
-
|
|
1263
|
-
out: T = new Quaternion() as Quaternion & T
|
|
1264
|
-
): T {
|
|
1265
|
-
return rotateZ(this, r, out);
|
|
1290
|
+
public identity(): this {
|
|
1291
|
+
return identity(this);
|
|
1266
1292
|
}
|
|
1267
1293
|
|
|
1268
1294
|
/**
|
|
1269
|
-
* Calculate the
|
|
1270
|
-
* @
|
|
1271
|
-
* @returns The quaternion.
|
|
1295
|
+
* Calculate the inverse of this quaternion. If the quaternion is normalized, the conjugate is the same but faster to calculate.
|
|
1296
|
+
* @returns The inverse.
|
|
1272
1297
|
*/
|
|
1273
|
-
public
|
|
1274
|
-
|
|
1275
|
-
): T {
|
|
1276
|
-
return calculateW(this, out);
|
|
1298
|
+
public invert(): Quaternion {
|
|
1299
|
+
return invert(this, new Quaternion());
|
|
1277
1300
|
}
|
|
1278
1301
|
|
|
1279
1302
|
/**
|
|
1280
|
-
*
|
|
1281
|
-
* @param
|
|
1282
|
-
* @
|
|
1303
|
+
* Perform a linear interpolation between this and another quaternion.
|
|
1304
|
+
* @param quaternion - The other quaternion.
|
|
1305
|
+
* @param t - The interpolation amount (in `[0,1]`).
|
|
1306
|
+
* @returns The interpolated quaternion.
|
|
1283
1307
|
*/
|
|
1284
|
-
public
|
|
1285
|
-
|
|
1286
|
-
): T {
|
|
1287
|
-
return exp(this, out);
|
|
1308
|
+
public lerp(quaternion: QuaternionLike, t: number): Quaternion {
|
|
1309
|
+
return lerp(this, quaternion, t, new Quaternion());
|
|
1288
1310
|
}
|
|
1289
1311
|
|
|
1290
1312
|
/**
|
|
1291
1313
|
* Calculate the natural logarithm of this unit quaternion.
|
|
1292
|
-
* @param out - The quaternion to store the result in.
|
|
1293
1314
|
* @returns The natural logarithm.
|
|
1294
1315
|
*/
|
|
1295
|
-
public ln
|
|
1296
|
-
|
|
1297
|
-
): T {
|
|
1298
|
-
return ln(this, out);
|
|
1299
|
-
}
|
|
1300
|
-
|
|
1301
|
-
/**
|
|
1302
|
-
* Calculate a power of this unit quaternion.
|
|
1303
|
-
* @param scalar - The amount to scale the quaternion by.
|
|
1304
|
-
* @param out - The quaternion to store the result in.
|
|
1305
|
-
* @returns The power.
|
|
1306
|
-
*/
|
|
1307
|
-
public pow<T extends QuaternionLike = Quaternion>(
|
|
1308
|
-
scalar: number,
|
|
1309
|
-
out: T = new Quaternion() as Quaternion & T
|
|
1310
|
-
): T {
|
|
1311
|
-
return pow(this, scalar, out);
|
|
1316
|
+
public ln(): Quaternion {
|
|
1317
|
+
return ln(this, new Quaternion());
|
|
1312
1318
|
}
|
|
1313
1319
|
|
|
1314
1320
|
/**
|
|
1315
|
-
*
|
|
1321
|
+
* Multiply this and another quaternion.
|
|
1316
1322
|
* @param quaternion - The other quaternion.
|
|
1317
|
-
* @
|
|
1318
|
-
* @param out - The quaternion to store the result in.
|
|
1319
|
-
* @returns The interpolated quaternion.
|
|
1320
|
-
* @see {@link https://en.wikipedia.org/wiki/Slerp | Slerp}
|
|
1323
|
+
* @returns The product.
|
|
1321
1324
|
*/
|
|
1322
|
-
public
|
|
1323
|
-
quaternion
|
|
1324
|
-
t: number,
|
|
1325
|
-
out: T = new Quaternion() as Quaternion & T
|
|
1326
|
-
): T {
|
|
1327
|
-
return slerp(this, quaternion, t, out);
|
|
1325
|
+
public multiply(quaternion: QuaternionLike): Quaternion {
|
|
1326
|
+
return multiply(this, quaternion, new Quaternion());
|
|
1328
1327
|
}
|
|
1329
1328
|
|
|
1330
1329
|
/**
|
|
1331
|
-
*
|
|
1332
|
-
* @returns
|
|
1330
|
+
* Normalize this quaternion.
|
|
1331
|
+
* @returns The normalized quaternion.
|
|
1333
1332
|
*/
|
|
1334
|
-
public
|
|
1335
|
-
return
|
|
1333
|
+
public normalize(): Quaternion {
|
|
1334
|
+
return normalize(this, new Quaternion());
|
|
1336
1335
|
}
|
|
1337
1336
|
|
|
1338
1337
|
/**
|
|
1339
|
-
* Calculate
|
|
1340
|
-
* @param
|
|
1341
|
-
* @returns The
|
|
1338
|
+
* Calculate a power of this unit quaternion.
|
|
1339
|
+
* @param scalar - The amount to scale the quaternion by.
|
|
1340
|
+
* @returns The power.
|
|
1342
1341
|
*/
|
|
1343
|
-
public
|
|
1344
|
-
|
|
1345
|
-
): T {
|
|
1346
|
-
return invert(this, out);
|
|
1342
|
+
public pow(scalar: number): Quaternion {
|
|
1343
|
+
return pow(this, scalar, new Quaternion());
|
|
1347
1344
|
}
|
|
1348
1345
|
|
|
1349
1346
|
/**
|
|
1350
|
-
*
|
|
1351
|
-
* @
|
|
1352
|
-
* @returns The conjugate.
|
|
1347
|
+
* Set this to a random unit quaternion.
|
|
1348
|
+
* @returns A random unit quaternion.
|
|
1353
1349
|
*/
|
|
1354
|
-
public
|
|
1355
|
-
|
|
1356
|
-
): T {
|
|
1357
|
-
return conjugate(this, out);
|
|
1350
|
+
public random(): this {
|
|
1351
|
+
return random(this);
|
|
1358
1352
|
}
|
|
1359
1353
|
|
|
1360
1354
|
/**
|
|
1361
|
-
*
|
|
1362
|
-
* @param
|
|
1363
|
-
* @returns The
|
|
1355
|
+
* Rotate this quaternion by the given angle around the X-axis.
|
|
1356
|
+
* @param r - The angle in radians.
|
|
1357
|
+
* @returns The rotated quaternion.
|
|
1364
1358
|
*/
|
|
1365
|
-
public
|
|
1366
|
-
|
|
1367
|
-
): T {
|
|
1368
|
-
return copy(this, out);
|
|
1359
|
+
public rotateX(r: number): Quaternion {
|
|
1360
|
+
return rotateX(this, r, new Quaternion());
|
|
1369
1361
|
}
|
|
1370
1362
|
|
|
1371
1363
|
/**
|
|
1372
|
-
*
|
|
1373
|
-
* @param
|
|
1374
|
-
* @returns
|
|
1364
|
+
* Rotate this quaternion by the given angle around the Y-axis.
|
|
1365
|
+
* @param r - The angle in radians.
|
|
1366
|
+
* @returns The rotated quaternion.
|
|
1375
1367
|
*/
|
|
1376
|
-
public
|
|
1377
|
-
return
|
|
1368
|
+
public rotateY(r: number): Quaternion {
|
|
1369
|
+
return rotateY(this, r, new Quaternion());
|
|
1378
1370
|
}
|
|
1379
1371
|
|
|
1380
1372
|
/**
|
|
1381
|
-
*
|
|
1382
|
-
* @param
|
|
1383
|
-
* @
|
|
1384
|
-
* @returns The sum of the quaternions.
|
|
1373
|
+
* Rotate this quaternion by the given angle around the Z-axis.
|
|
1374
|
+
* @param r - The angle in radians.
|
|
1375
|
+
* @returns The rotated quaternion.
|
|
1385
1376
|
*/
|
|
1386
|
-
public
|
|
1387
|
-
|
|
1388
|
-
out: T = new Quaternion() as Quaternion & T
|
|
1389
|
-
): T {
|
|
1390
|
-
return add(this, quaternion, out);
|
|
1377
|
+
public rotateZ(r: number): Quaternion {
|
|
1378
|
+
return rotateZ(this, r, new Quaternion());
|
|
1391
1379
|
}
|
|
1392
1380
|
|
|
1393
1381
|
/**
|
|
1394
1382
|
* Scale this quaternion by a scalar.
|
|
1395
1383
|
* @param scalar - The scalar.
|
|
1396
|
-
* @param out - The quaternion to store the result in.
|
|
1397
1384
|
* @returns The scaled quaternion.
|
|
1398
1385
|
*/
|
|
1399
|
-
public scale
|
|
1400
|
-
scalar
|
|
1401
|
-
out: T = new Quaternion() as Quaternion & T
|
|
1402
|
-
): T {
|
|
1403
|
-
return scale(this, scalar, out);
|
|
1386
|
+
public scale(scalar: number): Quaternion {
|
|
1387
|
+
return scale(this, scalar, new Quaternion());
|
|
1404
1388
|
}
|
|
1405
1389
|
|
|
1406
1390
|
/**
|
|
1407
|
-
*
|
|
1408
|
-
* @param quaternion - The other quaternion.
|
|
1409
|
-
* @returns The dot product.
|
|
1410
|
-
*/
|
|
1411
|
-
public dot(quaternion: QuaternionLike): number {
|
|
1412
|
-
return dot(this, quaternion);
|
|
1413
|
-
}
|
|
1414
|
-
|
|
1415
|
-
/**
|
|
1416
|
-
* Perform a linear interpolation between this and another quaternion.
|
|
1391
|
+
* Perform a spherical linear interpolation between this and another quaternion.
|
|
1417
1392
|
* @param quaternion - The other quaternion.
|
|
1418
|
-
* @param t - The interpolation amount
|
|
1419
|
-
* @param out - The quaternion to store the result in.
|
|
1393
|
+
* @param t - The interpolation amount in `[0,1]`.
|
|
1420
1394
|
* @returns The interpolated quaternion.
|
|
1395
|
+
* @see {@link https://en.wikipedia.org/wiki/Slerp | Slerp}
|
|
1421
1396
|
*/
|
|
1422
|
-
public
|
|
1423
|
-
quaternion
|
|
1424
|
-
t: number,
|
|
1425
|
-
out: T = new Quaternion() as Quaternion & T
|
|
1426
|
-
): T {
|
|
1427
|
-
return lerp(this, quaternion, t, out);
|
|
1428
|
-
}
|
|
1429
|
-
|
|
1430
|
-
/** Get the magnitude (length) of this quaternion. */
|
|
1431
|
-
public get magnitude(): number {
|
|
1432
|
-
return getMagnitude(this);
|
|
1433
|
-
}
|
|
1434
|
-
|
|
1435
|
-
/** Get the squared magnitude (length) of this quaternion. */
|
|
1436
|
-
public get squaredMagnitude(): number {
|
|
1437
|
-
return getSquaredMagnitude(this);
|
|
1438
|
-
}
|
|
1439
|
-
|
|
1440
|
-
/**
|
|
1441
|
-
* Normalize this quaternion.
|
|
1442
|
-
* @param out - The quaternion to store the result in.
|
|
1443
|
-
* @returns The normalized quaternion.
|
|
1444
|
-
*/
|
|
1445
|
-
public normalize<T extends QuaternionLike = Quaternion>(
|
|
1446
|
-
out: T = new Quaternion() as Quaternion & T
|
|
1447
|
-
): T {
|
|
1448
|
-
return normalize(this, out);
|
|
1449
|
-
}
|
|
1450
|
-
|
|
1451
|
-
/**
|
|
1452
|
-
* Determine whether or not this quaternion is roughly equivalent to another.
|
|
1453
|
-
* @param quaternion - The other quaternion.
|
|
1454
|
-
* @returns Whether or not the quaternions are equivalent.
|
|
1455
|
-
*/
|
|
1456
|
-
public equals(quaternion: QuaternionLike): boolean {
|
|
1457
|
-
return equals(this, quaternion);
|
|
1458
|
-
}
|
|
1459
|
-
|
|
1460
|
-
/**
|
|
1461
|
-
* Determine whether or not this quaternion is exactly equivalent to another.
|
|
1462
|
-
* @param quaternion - The other quaternion.
|
|
1463
|
-
* @returns Whether or not the quaternions are equivalent.
|
|
1464
|
-
*/
|
|
1465
|
-
public exactEquals(quaternion: QuaternionLike): boolean {
|
|
1466
|
-
return exactEquals(this, quaternion);
|
|
1397
|
+
public slerp(quaternion: QuaternionLike, t: number): Quaternion {
|
|
1398
|
+
return slerp(this, quaternion, t, new Quaternion());
|
|
1467
1399
|
}
|
|
1468
1400
|
|
|
1469
1401
|
/**
|
|
@@ -1472,28 +1404,23 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
|
|
|
1472
1404
|
* @param b - The second control point.
|
|
1473
1405
|
* @param quaternion - The other quaternion.
|
|
1474
1406
|
* @param t - The interpolation amount in `[0,1]`.
|
|
1475
|
-
* @param out - The quaternion to store the result in.
|
|
1476
1407
|
* @returns The interpolated value.
|
|
1477
1408
|
* @see {@link https://en.wikipedia.org/wiki/Slerp | Slerp}
|
|
1478
1409
|
*/
|
|
1479
|
-
public sqlerp
|
|
1410
|
+
public sqlerp(
|
|
1480
1411
|
a: QuaternionLike,
|
|
1481
1412
|
b: QuaternionLike,
|
|
1482
1413
|
quaternion: QuaternionLike,
|
|
1483
|
-
t: number
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
return sqlerp(this, a, b, quaternion, t, out);
|
|
1414
|
+
t: number
|
|
1415
|
+
): Quaternion {
|
|
1416
|
+
return sqlerp(this, a, b, quaternion, t, new Quaternion());
|
|
1487
1417
|
}
|
|
1488
1418
|
|
|
1489
1419
|
/**
|
|
1490
1420
|
* Convert this quaternion to equivalent z-y'-x" (intrinsic) Tait-Bryan angles.
|
|
1491
|
-
* @param out - The vector in which to store the Tait-Bryan angles.
|
|
1492
1421
|
* @returns The Tait-Bryan angles in degrees in roll (z), pitch (y'), yaw (x") order.
|
|
1493
1422
|
*/
|
|
1494
|
-
public toEuler
|
|
1495
|
-
|
|
1496
|
-
): T {
|
|
1497
|
-
return toEuler(this, out);
|
|
1423
|
+
public toEuler(): Vector3 {
|
|
1424
|
+
return toEuler(this, new Vector3());
|
|
1498
1425
|
}
|
|
1499
1426
|
}
|