@lakuna/umath 1.3.9 → 1.4.2
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/README.md +1 -1
- package/dist/algorithms/approx.d.ts +9 -0
- package/dist/algorithms/approx.d.ts.map +1 -0
- package/dist/algorithms/approx.js +12 -0
- package/dist/algorithms/approx.js.map +1 -0
- package/dist/algorithms/approxRelative.d.ts +9 -0
- package/dist/algorithms/approxRelative.d.ts.map +1 -0
- package/dist/algorithms/approxRelative.js +12 -0
- package/dist/algorithms/approxRelative.js.map +1 -0
- package/dist/algorithms/combinations.d.ts +2 -1
- package/dist/algorithms/combinations.d.ts.map +1 -1
- package/dist/algorithms/combinations.js +2 -1
- package/dist/algorithms/combinations.js.map +1 -1
- package/dist/algorithms/degreesToRadians.d.ts +3 -2
- package/dist/algorithms/degreesToRadians.d.ts.map +1 -1
- package/dist/algorithms/degreesToRadians.js +5 -3
- package/dist/algorithms/degreesToRadians.js.map +1 -1
- package/dist/algorithms/factorial.d.ts +2 -1
- package/dist/algorithms/factorial.d.ts.map +1 -1
- package/dist/algorithms/factorial.js +2 -1
- package/dist/algorithms/factorial.js.map +1 -1
- package/dist/algorithms/fibonacci.d.ts +2 -1
- package/dist/algorithms/fibonacci.d.ts.map +1 -1
- package/dist/algorithms/fibonacci.js +6 -2
- package/dist/algorithms/fibonacci.js.map +1 -1
- package/dist/algorithms/greatestCommonDivisor.d.ts +4 -2
- package/dist/algorithms/greatestCommonDivisor.d.ts.map +1 -1
- package/dist/algorithms/greatestCommonDivisor.js +5 -2
- package/dist/algorithms/greatestCommonDivisor.js.map +1 -1
- package/dist/algorithms/hypergeometricPmf.d.ts +3 -2
- package/dist/algorithms/hypergeometricPmf.d.ts.map +1 -1
- package/dist/algorithms/hypergeometricPmf.js +3 -2
- package/dist/algorithms/hypergeometricPmf.js.map +1 -1
- package/dist/algorithms/isPrime.d.ts +2 -1
- package/dist/algorithms/isPrime.d.ts.map +1 -1
- package/dist/algorithms/isPrime.js +2 -1
- package/dist/algorithms/isPrime.js.map +1 -1
- package/dist/algorithms/permutations.d.ts +2 -1
- package/dist/algorithms/permutations.d.ts.map +1 -1
- package/dist/algorithms/permutations.js +2 -1
- package/dist/algorithms/permutations.js.map +1 -1
- package/dist/algorithms/primeFactorization.d.ts +2 -1
- package/dist/algorithms/primeFactorization.d.ts.map +1 -1
- package/dist/algorithms/primeFactorization.js +2 -1
- package/dist/algorithms/primeFactorization.js.map +1 -1
- package/dist/algorithms/radiansToDegrees.d.ts +3 -2
- package/dist/algorithms/radiansToDegrees.d.ts.map +1 -1
- package/dist/algorithms/radiansToDegrees.js +5 -3
- package/dist/algorithms/radiansToDegrees.js.map +1 -1
- package/dist/algorithms/summation.d.ts +2 -1
- package/dist/algorithms/summation.d.ts.map +1 -1
- package/dist/algorithms/summation.js +2 -1
- package/dist/algorithms/summation.js.map +1 -1
- package/dist/linalg/DualQuaternion.d.ts +102 -32
- package/dist/linalg/DualQuaternion.d.ts.map +1 -1
- package/dist/linalg/DualQuaternion.js +243 -272
- package/dist/linalg/DualQuaternion.js.map +1 -1
- package/dist/linalg/Matrix.d.ts +14 -10
- package/dist/linalg/Matrix.d.ts.map +1 -1
- package/dist/linalg/Matrix2.d.ts +74 -51
- package/dist/linalg/Matrix2.d.ts.map +1 -1
- package/dist/linalg/Matrix2.js +95 -171
- package/dist/linalg/Matrix2.js.map +1 -1
- package/dist/linalg/Matrix3.d.ts +122 -72
- package/dist/linalg/Matrix3.d.ts.map +1 -1
- package/dist/linalg/Matrix3.js +186 -355
- package/dist/linalg/Matrix3.js.map +1 -1
- package/dist/linalg/Matrix4.d.ts +266 -149
- package/dist/linalg/Matrix4.d.ts.map +1 -1
- package/dist/linalg/Matrix4.js +512 -852
- package/dist/linalg/Matrix4.js.map +1 -1
- package/dist/linalg/Quaternion.d.ts +252 -34
- package/dist/linalg/Quaternion.d.ts.map +1 -1
- package/dist/linalg/Quaternion.js +436 -166
- package/dist/linalg/Quaternion.js.map +1 -1
- package/dist/linalg/SlowMatrix.d.ts +10 -9
- package/dist/linalg/SlowMatrix.d.ts.map +1 -1
- package/dist/linalg/SlowMatrix.js +10 -9
- package/dist/linalg/SlowMatrix.js.map +1 -1
- package/dist/linalg/SlowSquareMatrix.d.ts +10 -9
- package/dist/linalg/SlowSquareMatrix.d.ts.map +1 -1
- package/dist/linalg/SlowSquareMatrix.js +10 -9
- package/dist/linalg/SlowSquareMatrix.js.map +1 -1
- package/dist/linalg/SquareMatrix.d.ts +6 -5
- package/dist/linalg/SquareMatrix.d.ts.map +1 -1
- package/dist/linalg/Vector.d.ts +8 -4
- package/dist/linalg/Vector.d.ts.map +1 -1
- package/dist/linalg/Vector2.d.ts +82 -31
- package/dist/linalg/Vector2.d.ts.map +1 -1
- package/dist/linalg/Vector2.js +112 -154
- package/dist/linalg/Vector2.js.map +1 -1
- package/dist/linalg/Vector3.d.ts +93 -41
- package/dist/linalg/Vector3.d.ts.map +1 -1
- package/dist/linalg/Vector3.js +171 -282
- package/dist/linalg/Vector3.js.map +1 -1
- package/dist/linalg/Vector4.d.ts +71 -21
- package/dist/linalg/Vector4.d.ts.map +1 -1
- package/dist/linalg/Vector4.js +121 -195
- package/dist/linalg/Vector4.js.map +1 -1
- package/dist/types/AxisAngle.d.ts +4 -1
- package/dist/types/AxisAngle.d.ts.map +1 -1
- package/dist/types/FieldOfView.d.ts +4 -1
- package/dist/types/FieldOfView.d.ts.map +1 -1
- package/dist/utility/BigNumber.d.ts +4 -1
- package/dist/utility/BigNumber.d.ts.map +1 -1
- package/dist/utility/BigNumber.js +4 -1
- package/dist/utility/BigNumber.js.map +1 -1
- package/dist/utility/MagnitudeError.d.ts +4 -1
- package/dist/utility/MagnitudeError.d.ts.map +1 -1
- package/dist/utility/MagnitudeError.js +4 -1
- package/dist/utility/MagnitudeError.js.map +1 -1
- package/dist/utility/MatrixSizeError.d.ts +4 -1
- package/dist/utility/MatrixSizeError.d.ts.map +1 -1
- package/dist/utility/MatrixSizeError.js +4 -1
- package/dist/utility/MatrixSizeError.js.map +1 -1
- package/dist/utility/PartialMatrixError.d.ts +4 -1
- package/dist/utility/PartialMatrixError.d.ts.map +1 -1
- package/dist/utility/PartialMatrixError.js +4 -1
- package/dist/utility/PartialMatrixError.js.map +1 -1
- package/dist/utility/SingularMatrixError.d.ts +2 -1
- package/dist/utility/SingularMatrixError.d.ts.map +1 -1
- package/dist/utility/SingularMatrixError.js +2 -1
- package/dist/utility/SingularMatrixError.js.map +1 -1
- package/dist/utility/epsilon.d.ts +4 -1
- package/dist/utility/epsilon.d.ts.map +1 -1
- package/dist/utility/epsilon.js +4 -1
- package/dist/utility/epsilon.js.map +1 -1
- package/package.json +11 -11
- package/src/algorithms/approx.ts +12 -0
- package/src/algorithms/approxRelative.ts +12 -0
- package/src/algorithms/combinations.ts +2 -1
- package/src/algorithms/degreesToRadians.ts +6 -3
- package/src/algorithms/factorial.ts +3 -1
- package/src/algorithms/fibonacci.ts +7 -2
- package/src/algorithms/greatestCommonDivisor.ts +9 -4
- package/src/algorithms/hypergeometricPmf.ts +3 -2
- package/src/algorithms/isPrime.ts +2 -1
- package/src/algorithms/permutations.ts +2 -1
- package/src/algorithms/primeFactorization.ts +2 -1
- package/src/algorithms/radiansToDegrees.ts +6 -3
- package/src/algorithms/summation.ts +2 -1
- package/src/linalg/DualQuaternion.ts +424 -289
- package/src/linalg/Matrix.ts +14 -10
- package/src/linalg/Matrix2.ts +141 -188
- package/src/linalg/Matrix3.ts +400 -375
- package/src/linalg/Matrix4.ts +1083 -905
- package/src/linalg/Quaternion.ts +706 -188
- package/src/linalg/SlowMatrix.ts +10 -9
- package/src/linalg/SlowSquareMatrix.ts +10 -9
- package/src/linalg/SquareMatrix.ts +6 -5
- package/src/linalg/Vector.ts +8 -4
- package/src/linalg/Vector2.ts +146 -173
- package/src/linalg/Vector3.ts +293 -326
- package/src/linalg/Vector4.ts +227 -215
- package/src/types/AxisAngle.ts +4 -1
- package/src/types/FieldOfView.ts +4 -1
- package/src/utility/BigNumber.ts +6 -3
- package/src/utility/MagnitudeError.ts +4 -1
- package/src/utility/MatrixSizeError.ts +4 -1
- package/src/utility/PartialMatrixError.ts +4 -1
- package/src/utility/SingularMatrixError.ts +2 -1
- package/src/utility/epsilon.ts +4 -1
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import Quaternion, {
|
|
3
|
-
import Vector3, { createVector3Like } from "./Vector3.js";
|
|
4
|
-
import { dot, getMagnitude, getSquaredMagnitude
|
|
1
|
+
import { getScaling as matrix4GetScaling } from "./Matrix4.js";
|
|
2
|
+
import Quaternion, { rotateX as quaternionRotateX, rotateY as quaternionRotateY, rotateZ as quaternionRotateZ } from "./Quaternion.js";
|
|
3
|
+
import Vector3, { createVector3Like, fromValues as vector3FromValues } from "./Vector3.js";
|
|
4
|
+
import { copy as vector4Copy, dot as vector4Dot, fromValues as vector4FromValues, getMagnitude as vector4GetMagnitude, getSquaredMagnitude as vector4GetSquaredMagnitude } from "./Vector4.js";
|
|
5
|
+
import approxRelative from "../algorithms/approxRelative.js";
|
|
5
6
|
import epsilon from "../utility/epsilon.js";
|
|
6
7
|
/**
|
|
7
8
|
* Create a dual quaternion-like object.
|
|
8
9
|
* @returns A dual quaternion-like object.
|
|
10
|
+
* @public
|
|
9
11
|
*/
|
|
10
12
|
export const createDualQuaternionLike = () => {
|
|
11
13
|
return new Float32Array(8);
|
|
@@ -22,6 +24,7 @@ export const createDualQuaternionLike = () => {
|
|
|
22
24
|
* @param w2 - The fourth dual component.
|
|
23
25
|
* @param out - The dual quaternion to store the result in.
|
|
24
26
|
* @returns A new dual quaternion.
|
|
27
|
+
* @public
|
|
25
28
|
*/
|
|
26
29
|
export const fromValues = (x1, y1, z1, w1, x2, y2, z2, w2, out) => {
|
|
27
30
|
out[0] = x1;
|
|
@@ -39,123 +42,145 @@ export const fromValues = (x1, y1, z1, w1, x2, y2, z2, w2, out) => {
|
|
|
39
42
|
* @param dualQuaternion - The dual quaternion to copy.
|
|
40
43
|
* @param out - The dual quaternion to store the result in.
|
|
41
44
|
* @returns The copy.
|
|
45
|
+
* @public
|
|
42
46
|
*/
|
|
43
|
-
export const copy = (dualQuaternion, out) =>
|
|
44
|
-
out[0] = dualQuaternion[0];
|
|
45
|
-
out[1] = dualQuaternion[1];
|
|
46
|
-
out[2] = dualQuaternion[2];
|
|
47
|
-
out[3] = dualQuaternion[3];
|
|
48
|
-
out[4] = dualQuaternion[4];
|
|
49
|
-
out[5] = dualQuaternion[5];
|
|
50
|
-
out[6] = dualQuaternion[6];
|
|
51
|
-
out[7] = dualQuaternion[7];
|
|
52
|
-
return out;
|
|
53
|
-
};
|
|
47
|
+
export const copy = (dualQuaternion, out) => fromValues(dualQuaternion[0], dualQuaternion[1], dualQuaternion[2], dualQuaternion[3], dualQuaternion[4], dualQuaternion[5], dualQuaternion[6], dualQuaternion[7], out);
|
|
54
48
|
/**
|
|
55
|
-
* Create a dual quaternion from the given
|
|
56
|
-
* @param quaternion - The quaternion.
|
|
57
|
-
* @param translation - The translation.
|
|
49
|
+
* Create a dual quaternion from the given rotation and translation.
|
|
50
|
+
* @param quaternion - The rotation quaternion.
|
|
51
|
+
* @param translation - The translation vector.
|
|
58
52
|
* @param out - The dual quaternion to store the result in.
|
|
59
53
|
* @returns The dual quaternion.
|
|
54
|
+
* @public
|
|
60
55
|
*/
|
|
61
56
|
export const fromRotationTranslation = (quaternion, translation, out) => {
|
|
62
57
|
const x = quaternion[0];
|
|
63
58
|
const y = quaternion[1];
|
|
64
59
|
const z = quaternion[2];
|
|
65
60
|
const w = quaternion[3];
|
|
66
|
-
const ax = translation[0]
|
|
67
|
-
const ay = translation[1]
|
|
68
|
-
const az = translation[2]
|
|
69
|
-
|
|
70
|
-
out[1] = y;
|
|
71
|
-
out[2] = z;
|
|
72
|
-
out[3] = w;
|
|
73
|
-
out[4] = ax * w + ay * z - az * y;
|
|
74
|
-
out[5] = ay * w + az * x - ax * z;
|
|
75
|
-
out[6] = az * w + ax * y - ay * x;
|
|
76
|
-
out[7] = -ax * x - ay * y - az * z;
|
|
77
|
-
return out;
|
|
61
|
+
const ax = translation[0] / 2;
|
|
62
|
+
const ay = translation[1] / 2;
|
|
63
|
+
const az = translation[2] / 2;
|
|
64
|
+
return fromValues(x, y, z, w, ax * w + ay * z - az * y, ay * w + az * x - ax * z, az * w + ax * y - ay * x, -ax * x - ay * y - az * z, out);
|
|
78
65
|
};
|
|
79
66
|
/**
|
|
80
67
|
* Create a dual quaternion from the given translation.
|
|
81
|
-
* @param translation - The translation.
|
|
68
|
+
* @param translation - The translation vector.
|
|
82
69
|
* @param out - The dual quaternion to store the result in.
|
|
83
70
|
* @returns The dual quaternion.
|
|
71
|
+
* @public
|
|
84
72
|
*/
|
|
85
|
-
export const fromTranslation = (translation, out) =>
|
|
86
|
-
out[0] = 0;
|
|
87
|
-
out[1] = 0;
|
|
88
|
-
out[2] = 0;
|
|
89
|
-
out[3] = 1;
|
|
90
|
-
out[4] = translation[0] * 0.5;
|
|
91
|
-
out[5] = translation[1] * 0.5;
|
|
92
|
-
out[6] = translation[2] * 0.5;
|
|
93
|
-
out[7] = 0;
|
|
94
|
-
return out;
|
|
95
|
-
};
|
|
73
|
+
export const fromTranslation = (translation, out) => fromValues(0, 0, 0, 1, translation[0] / 2, translation[1] / 2, translation[2] / 2, 0, out);
|
|
96
74
|
/**
|
|
97
|
-
* Create a dual quaternion from the given
|
|
98
|
-
* @param quaternion - The quaternion.
|
|
75
|
+
* Create a dual quaternion from the given rotation.
|
|
76
|
+
* @param quaternion - The rotation quaternion.
|
|
99
77
|
* @param out - The dual quaternion to store the result in.
|
|
100
78
|
* @returns The dual quaternion.
|
|
79
|
+
* @public
|
|
101
80
|
*/
|
|
102
|
-
export const fromRotation = (quaternion, out) =>
|
|
103
|
-
out[0] = quaternion[0];
|
|
104
|
-
out[1] = quaternion[1];
|
|
105
|
-
out[2] = quaternion[2];
|
|
106
|
-
out[3] = quaternion[3];
|
|
107
|
-
out[4] = 0;
|
|
108
|
-
out[5] = 0;
|
|
109
|
-
out[6] = 0;
|
|
110
|
-
out[7] = 0;
|
|
111
|
-
return out;
|
|
112
|
-
};
|
|
81
|
+
export const fromRotation = (quaternion, out) => fromValues(quaternion[0], quaternion[1], quaternion[2], quaternion[3], 0, 0, 0, 0, out);
|
|
113
82
|
// Used to store intermediary values for some functions.
|
|
114
|
-
const
|
|
115
|
-
const translation = createVector3Like();
|
|
83
|
+
const iv3 = createVector3Like();
|
|
116
84
|
/**
|
|
117
|
-
* Create a dual quaternion from the given four-by-four matrix.
|
|
85
|
+
* Create a dual quaternion from the given four-by-four matrix. Equivalent to (but faster than) `fromRotationTranslation(getRotation(matrix, createQuaternionLike()), getTranslation(matrix, createVector3Like()), out)`.
|
|
118
86
|
* @param matrix - The matrix.
|
|
119
87
|
* @param out - The dual quaternion to store the result in.
|
|
120
88
|
* @returns The dual quaternion.
|
|
89
|
+
* @public
|
|
121
90
|
*/
|
|
122
91
|
export const fromMatrix4 = (matrix, out) => {
|
|
123
|
-
|
|
92
|
+
matrix4GetScaling(matrix, iv3);
|
|
93
|
+
const is1 = 1 / iv3[0];
|
|
94
|
+
const is2 = 1 / iv3[1];
|
|
95
|
+
const is3 = 1 / iv3[2];
|
|
96
|
+
const sm11 = matrix[0] * is1;
|
|
97
|
+
const sm12 = matrix[1] * is2;
|
|
98
|
+
const sm13 = matrix[2] * is3;
|
|
99
|
+
const sm21 = matrix[4] * is1;
|
|
100
|
+
const sm22 = matrix[5] * is2;
|
|
101
|
+
const sm23 = matrix[6] * is3;
|
|
102
|
+
const sm31 = matrix[8] * is1;
|
|
103
|
+
const sm32 = matrix[9] * is2;
|
|
104
|
+
const sm33 = matrix[10] * is3;
|
|
105
|
+
const trace = sm11 + sm22 + sm33;
|
|
106
|
+
// eslint-disable-next-line init-declarations
|
|
107
|
+
let x;
|
|
108
|
+
// eslint-disable-next-line init-declarations
|
|
109
|
+
let y;
|
|
110
|
+
// eslint-disable-next-line init-declarations
|
|
111
|
+
let z;
|
|
112
|
+
// eslint-disable-next-line init-declarations
|
|
113
|
+
let w;
|
|
114
|
+
if (trace > 0) {
|
|
115
|
+
const s = Math.sqrt(trace + 1) * 2;
|
|
116
|
+
x = (sm23 - sm32) / s;
|
|
117
|
+
y = (sm31 - sm13) / s;
|
|
118
|
+
z = (sm12 - sm21) / s;
|
|
119
|
+
w = 0.25 * s;
|
|
120
|
+
}
|
|
121
|
+
else if (sm11 > sm22 && sm11 > sm33) {
|
|
122
|
+
const s = Math.sqrt(1 + sm11 - sm22 - sm33) * 2;
|
|
123
|
+
x = 0.25 * s;
|
|
124
|
+
y = (sm12 + sm21) / s;
|
|
125
|
+
z = (sm31 + sm13) / s;
|
|
126
|
+
w = (sm23 - sm32) / s;
|
|
127
|
+
}
|
|
128
|
+
else if (sm22 > sm33) {
|
|
129
|
+
const s = Math.sqrt(1 + sm22 - sm11 - sm33) * 2;
|
|
130
|
+
x = (sm12 + sm21) / s;
|
|
131
|
+
y = 0.25 * s;
|
|
132
|
+
z = (sm23 + sm32) / s;
|
|
133
|
+
w = (sm31 - sm13) / s;
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
const s = Math.sqrt(1 + sm33 - sm11 - sm22) * 2;
|
|
137
|
+
x = (sm31 + sm13) / s;
|
|
138
|
+
y = (sm23 + sm32) / s;
|
|
139
|
+
z = 0.25 * s;
|
|
140
|
+
w = (sm12 - sm21) / s;
|
|
141
|
+
}
|
|
142
|
+
const ax = matrix[12] / 2;
|
|
143
|
+
const ay = matrix[13] / 2;
|
|
144
|
+
const az = matrix[14] / 2;
|
|
145
|
+
return fromValues(x, y, z, w, ax * w + ay * z - az * y, ay * w + az * x - ax * z, az * w + ax * y - ay * x, -ax * x - ay * y - az * z, out);
|
|
124
146
|
};
|
|
125
147
|
/**
|
|
126
148
|
* Set a dual quaternion to the identity dual quaternion.
|
|
127
149
|
* @param out - The dual quaternion to store the result in.
|
|
128
150
|
* @returns The identity dual quaternion.
|
|
151
|
+
* @public
|
|
129
152
|
*/
|
|
130
|
-
export const identity = (out) =>
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
return out;
|
|
140
|
-
};
|
|
153
|
+
export const identity = (out) => fromValues(0, 0, 0, 1, 0, 0, 0, 0, out);
|
|
154
|
+
/**
|
|
155
|
+
* Get the real part of a dual quaternion.
|
|
156
|
+
* @param dualQuaternion - The dual quaternion.
|
|
157
|
+
* @param out - The quaternion to store the result in.
|
|
158
|
+
* @returns The real part.
|
|
159
|
+
* @public
|
|
160
|
+
*/
|
|
161
|
+
export const getReal = vector4Copy;
|
|
141
162
|
/**
|
|
142
163
|
* Get the dual part of a dual quaternion.
|
|
143
164
|
* @param dualQuaternion - The dual quaternion.
|
|
144
165
|
* @param out - The quaternion to store the result in.
|
|
145
166
|
* @returns The dual part.
|
|
167
|
+
* @public
|
|
146
168
|
*/
|
|
147
|
-
export const getDual = (dualQuaternion, out) =>
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
169
|
+
export const getDual = (dualQuaternion, out) => vector4FromValues(dualQuaternion[4], dualQuaternion[5], dualQuaternion[6], dualQuaternion[7], out);
|
|
170
|
+
/**
|
|
171
|
+
* Set the real part of a dual quaternion.
|
|
172
|
+
* @param quaternion - The quaternion to set as the real part.
|
|
173
|
+
* @param out - The dual quaternion to store the result in.
|
|
174
|
+
* @returns The dual quaternion.
|
|
175
|
+
* @public
|
|
176
|
+
*/
|
|
177
|
+
export const setReal = vector4Copy;
|
|
154
178
|
/**
|
|
155
179
|
* Set the dual part of a dual quaternion.
|
|
156
180
|
* @param quaternion - The quaternion to set as the dual part.
|
|
157
181
|
* @param out - The dual quaternion to store the result in.
|
|
158
182
|
* @returns The dual quaternion.
|
|
183
|
+
* @public
|
|
159
184
|
*/
|
|
160
185
|
export const setDual = (quaternion, out) => {
|
|
161
186
|
out[4] = quaternion[0];
|
|
@@ -168,7 +193,8 @@ export const setDual = (quaternion, out) => {
|
|
|
168
193
|
* Get the translation of a normalized dual quaternion.
|
|
169
194
|
* @param dualQuaternion - The dual quaternion.
|
|
170
195
|
* @param out - The vector to store the result in.
|
|
171
|
-
* @returns The translation.
|
|
196
|
+
* @returns The translation vector.
|
|
197
|
+
* @public
|
|
172
198
|
*/
|
|
173
199
|
export const getTranslation = (dualQuaternion, out) => {
|
|
174
200
|
const ax = dualQuaternion[4];
|
|
@@ -179,10 +205,7 @@ export const getTranslation = (dualQuaternion, out) => {
|
|
|
179
205
|
const by = -dualQuaternion[1];
|
|
180
206
|
const bz = -dualQuaternion[2];
|
|
181
207
|
const bw = dualQuaternion[3];
|
|
182
|
-
|
|
183
|
-
out[1] = (ay * bw + aw * by + az * bx - ax * bz) * 2;
|
|
184
|
-
out[2] = (az * bw + aw * bz + ax * by - ay * bx) * 2;
|
|
185
|
-
return out;
|
|
208
|
+
return vector3FromValues((ax * bw + aw * bx + ay * bz - az * by) * 2, (ay * bw + aw * by + az * bx - ax * bz) * 2, (az * bw + aw * bz + ax * by - ay * bx) * 2, out);
|
|
186
209
|
};
|
|
187
210
|
/**
|
|
188
211
|
* Translate a dual quaternion by the given vector.
|
|
@@ -190,28 +213,21 @@ export const getTranslation = (dualQuaternion, out) => {
|
|
|
190
213
|
* @param vector - The vector.
|
|
191
214
|
* @param out - The dual quaternion to store the result in.
|
|
192
215
|
* @returns The translated dual quaternion.
|
|
216
|
+
* @public
|
|
193
217
|
*/
|
|
194
218
|
export const translate = (dualQuaternion, vector, out) => {
|
|
195
219
|
const ax1 = dualQuaternion[0];
|
|
196
220
|
const ay1 = dualQuaternion[1];
|
|
197
221
|
const az1 = dualQuaternion[2];
|
|
198
222
|
const aw1 = dualQuaternion[3];
|
|
199
|
-
const bx1 = vector[0]
|
|
200
|
-
const by1 = vector[1]
|
|
201
|
-
const bz1 = vector[2]
|
|
223
|
+
const bx1 = vector[0] / 2;
|
|
224
|
+
const by1 = vector[1] / 2;
|
|
225
|
+
const bz1 = vector[2] / 2;
|
|
202
226
|
const ax2 = dualQuaternion[4];
|
|
203
227
|
const ay2 = dualQuaternion[5];
|
|
204
228
|
const az2 = dualQuaternion[6];
|
|
205
229
|
const aw2 = dualQuaternion[7];
|
|
206
|
-
|
|
207
|
-
out[1] = ay1;
|
|
208
|
-
out[2] = az1;
|
|
209
|
-
out[3] = aw1;
|
|
210
|
-
out[4] = aw1 * bx1 + ay1 * bz1 - az1 * by1 + ax2;
|
|
211
|
-
out[5] = aw1 * by1 + az1 * bx1 - ax1 * bz1 + ay2;
|
|
212
|
-
out[6] = aw1 * bz1 + ax1 * by1 - ay1 * bx1 + az2;
|
|
213
|
-
out[7] = -ax1 * bx1 - ay1 * by1 - az1 * bz1 + aw2;
|
|
214
|
-
return out;
|
|
230
|
+
return fromValues(ax1, ay1, az1, aw1, aw1 * bx1 + ay1 * bz1 - az1 * by1 + ax2, aw1 * by1 + az1 * bx1 - ax1 * bz1 + ay2, aw1 * bz1 + ax1 * by1 - ay1 * bx1 + az2, -ax1 * bx1 - ay1 * by1 - az1 * bz1 + aw2, out);
|
|
215
231
|
};
|
|
216
232
|
/**
|
|
217
233
|
* Rotate a dual quaternion around the X-axis.
|
|
@@ -219,6 +235,7 @@ export const translate = (dualQuaternion, vector, out) => {
|
|
|
219
235
|
* @param radians - The angle to rotate by in radians.
|
|
220
236
|
* @param out - The dual quaternion to store the result in.
|
|
221
237
|
* @returns The rotated dual quaternion.
|
|
238
|
+
* @public
|
|
222
239
|
*/
|
|
223
240
|
export const rotateX = (dualQuaternion, radians, out) => {
|
|
224
241
|
let bx = -dualQuaternion[0];
|
|
@@ -250,6 +267,7 @@ export const rotateX = (dualQuaternion, radians, out) => {
|
|
|
250
267
|
* @param radians - The angle to rotate by in radians.
|
|
251
268
|
* @param out - The dual quaternion to store the result in.
|
|
252
269
|
* @returns The rotated dual quaternion.
|
|
270
|
+
* @public
|
|
253
271
|
*/
|
|
254
272
|
export const rotateY = (dualQuaternion, radians, out) => {
|
|
255
273
|
let bx = -dualQuaternion[0];
|
|
@@ -281,6 +299,7 @@ export const rotateY = (dualQuaternion, radians, out) => {
|
|
|
281
299
|
* @param radians - The angle to rotate by in radians.
|
|
282
300
|
* @param out - The dual quaternion to store the result in.
|
|
283
301
|
* @returns The rotated dual quaternion.
|
|
302
|
+
* @public
|
|
284
303
|
*/
|
|
285
304
|
export const rotateZ = (dualQuaternion, radians, out) => {
|
|
286
305
|
let bx = -dualQuaternion[0];
|
|
@@ -307,11 +326,12 @@ export const rotateZ = (dualQuaternion, radians, out) => {
|
|
|
307
326
|
return out;
|
|
308
327
|
};
|
|
309
328
|
/**
|
|
310
|
-
*
|
|
311
|
-
* @param dualQuaternion - The dual quaternion.
|
|
312
|
-
* @param quaternion - The quaternion.
|
|
329
|
+
* Rotate a dual quaternion by a quaternion (using the quaternion as the multiplicand).
|
|
330
|
+
* @param dualQuaternion - The dual quaternion to rotate.
|
|
331
|
+
* @param quaternion - The quaternion to rotate by.
|
|
313
332
|
* @param out - The dual quaternion to store the result in.
|
|
314
333
|
* @returns The rotated dual quaternion.
|
|
334
|
+
* @public
|
|
315
335
|
*/
|
|
316
336
|
export const rotateByQuaternionAppend = (dualQuaternion, quaternion, out) => {
|
|
317
337
|
const qx = quaternion[0];
|
|
@@ -337,11 +357,12 @@ export const rotateByQuaternionAppend = (dualQuaternion, quaternion, out) => {
|
|
|
337
357
|
return out;
|
|
338
358
|
};
|
|
339
359
|
/**
|
|
340
|
-
*
|
|
341
|
-
* @param quaternion - The quaternion.
|
|
342
|
-
* @param dualQuaternion - The dual quaternion.
|
|
360
|
+
* Rotate a dual quaternion by a quaternion (using the quaternion as the multiplier).
|
|
361
|
+
* @param quaternion - The quaternion to rotate by.
|
|
362
|
+
* @param dualQuaternion - The dual quaternion to rotate.
|
|
343
363
|
* @param out - The dual quaternion to store the result in.
|
|
344
364
|
* @returns The rotated dual quaternion.
|
|
365
|
+
* @public
|
|
345
366
|
*/
|
|
346
367
|
export const rotateByQuaternionPrepend = (quaternion, dualQuaternion, out) => {
|
|
347
368
|
const qx = quaternion[0];
|
|
@@ -373,16 +394,18 @@ export const rotateByQuaternionPrepend = (quaternion, dualQuaternion, out) => {
|
|
|
373
394
|
* @param radians - The angle of the rotation in radians.
|
|
374
395
|
* @param out - The dual quaternion to store the result in.
|
|
375
396
|
* @returns A normalized dual quaternion.
|
|
397
|
+
* @public
|
|
376
398
|
*/
|
|
377
399
|
export const rotateAroundAxis = (dualQuaternion, axis, radians, out) => {
|
|
378
|
-
|
|
400
|
+
// Negligible rotation.
|
|
401
|
+
if (Math.abs(radians) < epsilon) {
|
|
379
402
|
return copy(dualQuaternion, out);
|
|
380
403
|
}
|
|
381
404
|
const ax = axis[0];
|
|
382
405
|
const ay = axis[1];
|
|
383
406
|
const az = axis[2];
|
|
384
|
-
const axisLength = Math.sqrt(ax * ax + ay * ay + az * az);
|
|
385
|
-
const r = radians
|
|
407
|
+
const axisLength = Math.sqrt(ax * ax + ay * ay + az * az); // `Math.hypot` is slower.
|
|
408
|
+
const r = radians / 2;
|
|
386
409
|
const s = Math.sin(r);
|
|
387
410
|
const bx = (s * ax) / axisLength;
|
|
388
411
|
const by = (s * ay) / axisLength;
|
|
@@ -412,24 +435,16 @@ export const rotateAroundAxis = (dualQuaternion, axis, radians, out) => {
|
|
|
412
435
|
* @param b - The addend.
|
|
413
436
|
* @param out - The dual quaternion to store the result in.
|
|
414
437
|
* @returns The sum.
|
|
438
|
+
* @public
|
|
415
439
|
*/
|
|
416
|
-
export const add = (a, b, out) =>
|
|
417
|
-
out[0] = a[0] + b[0];
|
|
418
|
-
out[1] = a[1] + b[1];
|
|
419
|
-
out[2] = a[2] + b[2];
|
|
420
|
-
out[3] = a[3] + b[3];
|
|
421
|
-
out[4] = a[4] + b[4];
|
|
422
|
-
out[5] = a[5] + b[5];
|
|
423
|
-
out[6] = a[6] + b[6];
|
|
424
|
-
out[7] = a[7] + b[7];
|
|
425
|
-
return out;
|
|
426
|
-
};
|
|
440
|
+
export const add = (a, b, out) => fromValues(a[0] + b[0], a[1] + b[1], a[2] + b[2], a[3] + b[3], a[4] + b[4], a[5] + b[5], a[6] + b[6], a[7] + b[7], out);
|
|
427
441
|
/**
|
|
428
442
|
* Multiply two dual quaternions.
|
|
429
443
|
* @param a - The multiplier.
|
|
430
444
|
* @param b - The multiplicand.
|
|
431
445
|
* @param out - The dual quaternion to store the result in.
|
|
432
446
|
* @returns The product.
|
|
447
|
+
* @public
|
|
433
448
|
*/
|
|
434
449
|
export const multiply = (a, b, out) => {
|
|
435
450
|
const ax0 = a[0];
|
|
@@ -448,203 +463,159 @@ export const multiply = (a, b, out) => {
|
|
|
448
463
|
const by1 = b[5];
|
|
449
464
|
const bz1 = b[6];
|
|
450
465
|
const bw1 = b[7];
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
ax1 * by0 -
|
|
481
|
-
ay1 * bx0;
|
|
482
|
-
out[7] =
|
|
483
|
-
aw0 * bw1 -
|
|
484
|
-
ax0 * bx1 -
|
|
485
|
-
ay0 * by1 -
|
|
486
|
-
az0 * bz1 +
|
|
487
|
-
aw1 * bw0 -
|
|
488
|
-
ax1 * bx0 -
|
|
489
|
-
ay1 * by0 -
|
|
490
|
-
az1 * bz0;
|
|
491
|
-
return out;
|
|
466
|
+
return fromValues(ax0 * bw0 + aw0 * bx0 + ay0 * bz0 - az0 * by0, ay0 * bw0 + aw0 * by0 + az0 * bx0 - ax0 * bz0, az0 * bw0 + aw0 * bz0 + ax0 * by0 - ay0 * bx0, aw0 * bw0 - ax0 * bx0 - ay0 * by0 - az0 * bz0, ax0 * bw1 +
|
|
467
|
+
aw0 * bx1 +
|
|
468
|
+
ay0 * bz1 -
|
|
469
|
+
az0 * by1 +
|
|
470
|
+
ax1 * bw0 +
|
|
471
|
+
aw1 * bx0 +
|
|
472
|
+
ay1 * bz0 -
|
|
473
|
+
az1 * by0, ay0 * bw1 +
|
|
474
|
+
aw0 * by1 +
|
|
475
|
+
az0 * bx1 -
|
|
476
|
+
ax0 * bz1 +
|
|
477
|
+
ay1 * bw0 +
|
|
478
|
+
aw1 * by0 +
|
|
479
|
+
az1 * bx0 -
|
|
480
|
+
ax1 * bz0, az0 * bw1 +
|
|
481
|
+
aw0 * bz1 +
|
|
482
|
+
ax0 * by1 -
|
|
483
|
+
ay0 * bx1 +
|
|
484
|
+
az1 * bw0 +
|
|
485
|
+
aw1 * bz0 +
|
|
486
|
+
ax1 * by0 -
|
|
487
|
+
ay1 * bx0, aw0 * bw1 -
|
|
488
|
+
ax0 * bx1 -
|
|
489
|
+
ay0 * by1 -
|
|
490
|
+
az0 * bz1 +
|
|
491
|
+
aw1 * bw0 -
|
|
492
|
+
ax1 * bx0 -
|
|
493
|
+
ay1 * by0 -
|
|
494
|
+
az1 * bz0, out);
|
|
492
495
|
};
|
|
493
496
|
/**
|
|
494
497
|
* Multiply a dual quaternion by a scalar.
|
|
495
|
-
* @param dualQuaternion - The multiplicand.
|
|
496
|
-
* @param scalar - The multiplier.
|
|
498
|
+
* @param dualQuaternion - The multiplicand (dual quaternion).
|
|
499
|
+
* @param scalar - The multiplier (scalar) to scale the dual quaternion by.
|
|
497
500
|
* @param out - The dual quaternion to store the result in.
|
|
498
|
-
* @returns The
|
|
501
|
+
* @returns The product.
|
|
502
|
+
* @public
|
|
499
503
|
*/
|
|
500
|
-
export const scale = (dualQuaternion, scalar, out) =>
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
};
|
|
504
|
+
export const scale = (dualQuaternion, scalar, out) => fromValues(dualQuaternion[0] * scalar, dualQuaternion[1] * scalar, dualQuaternion[2] * scalar, dualQuaternion[3] * scalar, dualQuaternion[4] * scalar, dualQuaternion[5] * scalar, dualQuaternion[6] * scalar, dualQuaternion[7] * scalar, out);
|
|
505
|
+
/**
|
|
506
|
+
* Calculate the dot product of two dual quaternions.
|
|
507
|
+
* @param a - The multiplier.
|
|
508
|
+
* @param b - The multiplicand.
|
|
509
|
+
* @returns The dot product.
|
|
510
|
+
* @see {@link https://en.wikipedia.org/wiki/Dot_product | Dot product}
|
|
511
|
+
* @public
|
|
512
|
+
*/
|
|
513
|
+
export const dot = vector4Dot;
|
|
511
514
|
/**
|
|
512
515
|
* Perform a linear interpolation between two dual quaternions.
|
|
513
516
|
* @param a - The first dual quaternion.
|
|
514
517
|
* @param b - The second dual quaternion.
|
|
515
518
|
* @param t - The interpolation amount in `[0,1]`.
|
|
516
|
-
* @param out - The dual quaternion to store the result in.
|
|
519
|
+
* @param out - The dual quaternion to store the result in. Will not always be normalized (most noticeable when `t === 0.5`).
|
|
517
520
|
* @returns The interpolated value.
|
|
521
|
+
* @public
|
|
518
522
|
*/
|
|
519
523
|
export const lerp = (a, b, t, out) => {
|
|
520
524
|
const mt = 1 - t;
|
|
521
|
-
const it = dot(a, b) <
|
|
522
|
-
|
|
523
|
-
out[1] = a[1] * mt + b[1] * it;
|
|
524
|
-
out[2] = a[2] * mt + b[2] * it;
|
|
525
|
-
out[3] = a[3] * mt + b[3] * it;
|
|
526
|
-
out[4] = a[4] * mt + b[4] * it;
|
|
527
|
-
out[5] = a[5] * mt + b[5] * it;
|
|
528
|
-
out[6] = a[6] * mt + b[6] * it;
|
|
529
|
-
out[7] = a[7] * mt + b[7] * it;
|
|
530
|
-
return out;
|
|
525
|
+
const it = dot(a, b) < 0 ? -t : t;
|
|
526
|
+
return fromValues(a[0] * mt + b[0] * it, a[1] * mt + b[1] * it, a[2] * mt + b[2] * it, a[3] * mt + b[3] * it, a[4] * mt + b[4] * it, a[5] * mt + b[5] * it, a[6] * mt + b[6] * it, a[7] * mt + b[7] * it, out);
|
|
531
527
|
};
|
|
528
|
+
/**
|
|
529
|
+
* Calculate the magnitude (length) of a dual quaternion.
|
|
530
|
+
* @param dualQuaternion - The dual quaternion.
|
|
531
|
+
* @returns The magnitude.
|
|
532
|
+
* @public
|
|
533
|
+
*/
|
|
534
|
+
export const getMagnitude = vector4GetMagnitude;
|
|
535
|
+
/**
|
|
536
|
+
* Calculate the squared magnitude (length) of a dual quaternion.
|
|
537
|
+
* @param dualQuaternion - The dual quaternion.
|
|
538
|
+
* @returns The squared magnitude.
|
|
539
|
+
* @public
|
|
540
|
+
*/
|
|
541
|
+
export const getSquaredMagnitude = vector4GetSquaredMagnitude;
|
|
532
542
|
/**
|
|
533
543
|
* Calculate the inverse of a dual quaternion. If the dual quaternion is normalized, the conjugate is equivalent and faster to calculate.
|
|
534
544
|
* @param dualQuaternion - The dual quaternion.
|
|
535
545
|
* @param out - The dual quaternion to store the result in.
|
|
536
546
|
* @returns The inverse.
|
|
547
|
+
* @public
|
|
537
548
|
*/
|
|
538
549
|
export const invert = (dualQuaternion, out) => {
|
|
539
550
|
const sqm = getSquaredMagnitude(dualQuaternion);
|
|
540
|
-
|
|
541
|
-
out[1] = -dualQuaternion[1] / sqm;
|
|
542
|
-
out[2] = -dualQuaternion[2] / sqm;
|
|
543
|
-
out[3] = dualQuaternion[3] / sqm;
|
|
544
|
-
out[4] = -dualQuaternion[4] / sqm;
|
|
545
|
-
out[5] = -dualQuaternion[5] / sqm;
|
|
546
|
-
out[6] = -dualQuaternion[6] / sqm;
|
|
547
|
-
out[7] = dualQuaternion[7] / sqm;
|
|
548
|
-
return out;
|
|
551
|
+
return fromValues(-dualQuaternion[0] / sqm, -dualQuaternion[1] / sqm, -dualQuaternion[2] / sqm, dualQuaternion[3] / sqm, -dualQuaternion[4] / sqm, -dualQuaternion[5] / sqm, -dualQuaternion[6] / sqm, dualQuaternion[7] / sqm, out);
|
|
549
552
|
};
|
|
550
553
|
/**
|
|
551
554
|
* Calculate the conjugate of a dual quaternion. If the dual quaternion is normalized, this is equivalent to its inverse and faster to calculate.
|
|
552
555
|
* @param dualQuaternion - The dual quaternion.
|
|
553
556
|
* @param out - The dual quaternion to store the result in.
|
|
554
557
|
* @returns The conjugate.
|
|
558
|
+
* @public
|
|
555
559
|
*/
|
|
556
|
-
export const conjugate = (dualQuaternion, out) =>
|
|
557
|
-
out[0] = -dualQuaternion[0];
|
|
558
|
-
out[1] = -dualQuaternion[1];
|
|
559
|
-
out[2] = -dualQuaternion[2];
|
|
560
|
-
out[3] = dualQuaternion[3];
|
|
561
|
-
out[4] = -dualQuaternion[4];
|
|
562
|
-
out[5] = -dualQuaternion[5];
|
|
563
|
-
out[6] = -dualQuaternion[6];
|
|
564
|
-
out[7] = dualQuaternion[7];
|
|
565
|
-
return out;
|
|
566
|
-
};
|
|
560
|
+
export const conjugate = (dualQuaternion, out) => fromValues(-dualQuaternion[0], -dualQuaternion[1], -dualQuaternion[2], dualQuaternion[3], -dualQuaternion[4], -dualQuaternion[5], -dualQuaternion[6], dualQuaternion[7], out);
|
|
567
561
|
/**
|
|
568
562
|
* Normalize a dual quaternion.
|
|
569
563
|
* @param dualQuaternion - The dual quaternion.
|
|
570
564
|
* @param out - The dual quaternion to store the result in.
|
|
571
565
|
* @returns The normalized dual quaternion.
|
|
566
|
+
* @public
|
|
572
567
|
*/
|
|
573
568
|
export const normalize = (dualQuaternion, out) => {
|
|
574
569
|
let magnitude = getSquaredMagnitude(dualQuaternion);
|
|
575
|
-
if (magnitude
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
out[3] = a3;
|
|
590
|
-
out[4] = (b0 - a0 * aDotB) / magnitude;
|
|
591
|
-
out[5] = (b1 - a1 * aDotB) / magnitude;
|
|
592
|
-
out[6] = (b2 - a2 * aDotB) / magnitude;
|
|
593
|
-
out[7] = (b3 - a3 * aDotB) / magnitude;
|
|
594
|
-
}
|
|
595
|
-
return out;
|
|
570
|
+
if (magnitude <= 0) {
|
|
571
|
+
return out;
|
|
572
|
+
}
|
|
573
|
+
magnitude = Math.sqrt(magnitude);
|
|
574
|
+
const a0 = dualQuaternion[0] / magnitude;
|
|
575
|
+
const a1 = dualQuaternion[1] / magnitude;
|
|
576
|
+
const a2 = dualQuaternion[2] / magnitude;
|
|
577
|
+
const a3 = dualQuaternion[3] / magnitude;
|
|
578
|
+
const b0 = dualQuaternion[4];
|
|
579
|
+
const b1 = dualQuaternion[5];
|
|
580
|
+
const b2 = dualQuaternion[6];
|
|
581
|
+
const b3 = dualQuaternion[7];
|
|
582
|
+
const aDotB = a0 * b0 + a1 * b1 + a2 * b2 + a3 * b3;
|
|
583
|
+
return fromValues(a0, a1, a2, a3, (b0 - a0 * aDotB) / magnitude, (b1 - a1 * aDotB) / magnitude, (b2 - a2 * aDotB) / magnitude, (b3 - a3 * aDotB) / magnitude, out);
|
|
596
584
|
};
|
|
597
585
|
/**
|
|
598
586
|
* Determine whether or not two dual quaternions are exactly equivalent.
|
|
599
587
|
* @param a - The first dual quaternion.
|
|
600
588
|
* @param b - The second dual quaternion.
|
|
601
589
|
* @returns Whether or not the dual quaternions are equivalent.
|
|
590
|
+
* @public
|
|
602
591
|
*/
|
|
603
|
-
export const exactEquals = (a, b) =>
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
a[7] === b[7]);
|
|
612
|
-
};
|
|
592
|
+
export const exactEquals = (a, b) => a[0] === b[0] &&
|
|
593
|
+
a[1] === b[1] &&
|
|
594
|
+
a[2] === b[2] &&
|
|
595
|
+
a[3] === b[3] &&
|
|
596
|
+
a[4] === b[4] &&
|
|
597
|
+
a[5] === b[5] &&
|
|
598
|
+
a[6] === b[6] &&
|
|
599
|
+
a[7] === b[7];
|
|
613
600
|
/**
|
|
614
601
|
* Determine whether or not two dual quaternions are roughly equivalent.
|
|
615
602
|
* @param a - The first dual quaternion.
|
|
616
603
|
* @param b - The second dual quaternion.
|
|
617
604
|
* @returns Whether or not the dual quaternions are equivalent.
|
|
605
|
+
* @public
|
|
618
606
|
*/
|
|
619
|
-
export const equals = (a, b) =>
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
const a7 = a[7];
|
|
628
|
-
const b0 = b[0];
|
|
629
|
-
const b1 = b[1];
|
|
630
|
-
const b2 = b[2];
|
|
631
|
-
const b3 = b[3];
|
|
632
|
-
const b4 = b[4];
|
|
633
|
-
const b5 = b[5];
|
|
634
|
-
const b6 = b[6];
|
|
635
|
-
const b7 = b[7];
|
|
636
|
-
return (Math.abs(a0 - b0) <= epsilon * Math.max(1, Math.abs(a0), Math.abs(b0)) &&
|
|
637
|
-
Math.abs(a1 - b1) <= epsilon * Math.max(1, Math.abs(a1), Math.abs(b1)) &&
|
|
638
|
-
Math.abs(a2 - b2) <= epsilon * Math.max(1, Math.abs(a2), Math.abs(b2)) &&
|
|
639
|
-
Math.abs(a3 - b3) <= epsilon * Math.max(1, Math.abs(a3), Math.abs(b3)) &&
|
|
640
|
-
Math.abs(a4 - b4) <= epsilon * Math.max(1, Math.abs(a4), Math.abs(b4)) &&
|
|
641
|
-
Math.abs(a5 - b5) <= epsilon * Math.max(1, Math.abs(a5), Math.abs(b5)) &&
|
|
642
|
-
Math.abs(a6 - b6) <= epsilon * Math.max(1, Math.abs(a6), Math.abs(b6)) &&
|
|
643
|
-
Math.abs(a7 - b7) <= epsilon * Math.max(1, Math.abs(a7), Math.abs(b7)));
|
|
644
|
-
};
|
|
607
|
+
export const equals = (a, b) => approxRelative(a[0], b[0]) &&
|
|
608
|
+
approxRelative(a[1], b[1]) &&
|
|
609
|
+
approxRelative(a[2], b[2]) &&
|
|
610
|
+
approxRelative(a[3], b[3]) &&
|
|
611
|
+
approxRelative(a[4], b[4]) &&
|
|
612
|
+
approxRelative(a[5], b[5]) &&
|
|
613
|
+
approxRelative(a[6], b[6]) &&
|
|
614
|
+
approxRelative(a[7], b[7]);
|
|
645
615
|
/**
|
|
646
616
|
* A complex number that is commonly used to describe transformations.
|
|
647
|
-
* @see
|
|
617
|
+
* @see {@link https://en.wikipedia.org/wiki/Dual_quaternion | Dual quaternion}
|
|
618
|
+
* @public
|
|
648
619
|
*/
|
|
649
620
|
export default class DualQuaternion extends Float32Array {
|
|
650
621
|
/**
|
|
@@ -664,9 +635,9 @@ export default class DualQuaternion extends Float32Array {
|
|
|
664
635
|
return fromValues(x1, y1, z1, w1, x2, y2, z2, w2, out);
|
|
665
636
|
}
|
|
666
637
|
/**
|
|
667
|
-
* Create a dual quaternion from the given
|
|
668
|
-
* @param q - The quaternion.
|
|
669
|
-
* @param t - The translation.
|
|
638
|
+
* Create a dual quaternion from the given rotation and translation.
|
|
639
|
+
* @param q - The rotation quaternion.
|
|
640
|
+
* @param t - The translation vector.
|
|
670
641
|
* @param out - The dual quaternion to store the result in.
|
|
671
642
|
* @returns The dual quaternion.
|
|
672
643
|
*/
|
|
@@ -675,7 +646,7 @@ export default class DualQuaternion extends Float32Array {
|
|
|
675
646
|
}
|
|
676
647
|
/**
|
|
677
648
|
* Create a dual quaternion from the given translation.
|
|
678
|
-
* @param t - The translation.
|
|
649
|
+
* @param t - The translation vector.
|
|
679
650
|
* @param out - The dual quaternion to store the result in.
|
|
680
651
|
* @returns The dual quaternion.
|
|
681
652
|
*/
|
|
@@ -683,8 +654,8 @@ export default class DualQuaternion extends Float32Array {
|
|
|
683
654
|
return fromTranslation(t, out);
|
|
684
655
|
}
|
|
685
656
|
/**
|
|
686
|
-
* Create a dual quaternion from the given
|
|
687
|
-
* @param q - The quaternion.
|
|
657
|
+
* Create a dual quaternion from the given rotation.
|
|
658
|
+
* @param q - The rotation quaternion.
|
|
688
659
|
* @param out - The dual quaternion to store the result in.
|
|
689
660
|
* @returns The dual quaternion.
|
|
690
661
|
*/
|
|
@@ -702,7 +673,7 @@ export default class DualQuaternion extends Float32Array {
|
|
|
702
673
|
}
|
|
703
674
|
/**
|
|
704
675
|
* Create an identity dual quaternion.
|
|
705
|
-
* @see
|
|
676
|
+
* @see {@link https://en.wikipedia.org/wiki/Dual_quaternion | Dual quaternion}
|
|
706
677
|
*/
|
|
707
678
|
constructor() {
|
|
708
679
|
super(8);
|
|
@@ -753,14 +724,14 @@ export default class DualQuaternion extends Float32Array {
|
|
|
753
724
|
* @returns The real part.
|
|
754
725
|
*/
|
|
755
726
|
getReal(out = new Quaternion()) {
|
|
756
|
-
return
|
|
727
|
+
return getReal(this, out);
|
|
757
728
|
}
|
|
758
729
|
/**
|
|
759
730
|
* Set the real part of this dual quaternion.
|
|
760
731
|
* @param q - The quaternion.
|
|
761
732
|
*/
|
|
762
733
|
setReal(q) {
|
|
763
|
-
|
|
734
|
+
setReal(q, this);
|
|
764
735
|
}
|
|
765
736
|
/**
|
|
766
737
|
* Get the dual part of this dual quaternion.
|
|
@@ -822,21 +793,21 @@ export default class DualQuaternion extends Float32Array {
|
|
|
822
793
|
return rotateZ(this, r, out);
|
|
823
794
|
}
|
|
824
795
|
/**
|
|
825
|
-
*
|
|
796
|
+
* Rotate this dual quaternion by a quaternion (using the quaternion as the multiplicand).
|
|
826
797
|
* @param q - The quaternion.
|
|
827
798
|
* @param out - The dual quaternion to store the result in.
|
|
828
799
|
* @returns The rotated dual quaternion.
|
|
829
|
-
* @see
|
|
800
|
+
* @see {@link https://en.wikipedia.org/wiki/Quaternion | Quaternion}
|
|
830
801
|
*/
|
|
831
802
|
rotateByQuaternionAppend(q, out = new DualQuaternion()) {
|
|
832
803
|
return rotateByQuaternionAppend(this, q, out);
|
|
833
804
|
}
|
|
834
805
|
/**
|
|
835
|
-
*
|
|
806
|
+
* Rotate this dual quaternion by a quaternion (using the quaternion as the multiplier).
|
|
836
807
|
* @param q - The quaternion.
|
|
837
808
|
* @param out - The dual quaternion to store the result in.
|
|
838
809
|
* @returns The rotated dual quaternion.
|
|
839
|
-
* @see
|
|
810
|
+
* @see {@link https://en.wikipedia.org/wiki/Quaternion | Quaternion}
|
|
840
811
|
*/
|
|
841
812
|
rotateByQuaternionPrepend(q, out = new DualQuaternion()) {
|
|
842
813
|
return rotateByQuaternionPrepend(q, this, out);
|
|
@@ -882,7 +853,7 @@ export default class DualQuaternion extends Float32Array {
|
|
|
882
853
|
* Calculate the dot product of this and another dual quaternion.
|
|
883
854
|
* @param dq - The other dual quaternion.
|
|
884
855
|
* @returns The dot product.
|
|
885
|
-
* @see
|
|
856
|
+
* @see {@link https://en.wikipedia.org/wiki/Dot_product | Dot product}
|
|
886
857
|
*/
|
|
887
858
|
dot(dq) {
|
|
888
859
|
return dot(this, dq);
|