@lakuna/umath 1.3.5 → 1.3.7
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/combinations.d.ts +7 -0
- package/dist/algorithms/combinations.d.ts.map +1 -1
- package/dist/algorithms/combinations.js +7 -0
- package/dist/algorithms/combinations.js.map +1 -1
- package/dist/algorithms/degreesToRadians.d.ts +7 -0
- package/dist/algorithms/degreesToRadians.d.ts.map +1 -1
- package/dist/algorithms/degreesToRadians.js +7 -0
- package/dist/algorithms/degreesToRadians.js.map +1 -1
- package/dist/algorithms/factorial.d.ts +6 -0
- package/dist/algorithms/factorial.d.ts.map +1 -1
- package/dist/algorithms/factorial.js +8 -1
- package/dist/algorithms/factorial.js.map +1 -1
- package/dist/algorithms/fibonacci.d.ts +6 -1
- package/dist/algorithms/fibonacci.d.ts.map +1 -1
- package/dist/algorithms/fibonacci.js +5 -0
- package/dist/algorithms/fibonacci.js.map +1 -1
- package/dist/algorithms/greatestCommonDivisor.d.ts +14 -0
- package/dist/algorithms/greatestCommonDivisor.d.ts.map +1 -1
- package/dist/algorithms/greatestCommonDivisor.js +2 -0
- package/dist/algorithms/greatestCommonDivisor.js.map +1 -1
- package/dist/algorithms/hypergeometricPmf.d.ts +9 -0
- package/dist/algorithms/hypergeometricPmf.d.ts.map +1 -1
- package/dist/algorithms/hypergeometricPmf.js +9 -0
- package/dist/algorithms/hypergeometricPmf.js.map +1 -1
- package/dist/algorithms/isPrime.d.ts +6 -0
- package/dist/algorithms/isPrime.d.ts.map +1 -1
- package/dist/algorithms/isPrime.js +7 -0
- package/dist/algorithms/isPrime.js.map +1 -1
- package/dist/algorithms/permutations.d.ts +7 -0
- package/dist/algorithms/permutations.d.ts.map +1 -1
- package/dist/algorithms/permutations.js +7 -0
- package/dist/algorithms/permutations.js.map +1 -1
- package/dist/algorithms/primeFactorization.d.ts +6 -0
- package/dist/algorithms/primeFactorization.d.ts.map +1 -1
- package/dist/algorithms/primeFactorization.js +6 -0
- package/dist/algorithms/primeFactorization.js.map +1 -1
- package/dist/algorithms/radiansToDegrees.d.ts +7 -0
- package/dist/algorithms/radiansToDegrees.d.ts.map +1 -1
- package/dist/algorithms/radiansToDegrees.js +7 -0
- package/dist/algorithms/radiansToDegrees.js.map +1 -1
- package/dist/algorithms/summation.d.ts +8 -0
- package/dist/algorithms/summation.d.ts.map +1 -1
- package/dist/algorithms/summation.js +9 -0
- package/dist/algorithms/summation.js.map +1 -1
- package/dist/linalg/DualQuaternion.d.ts +410 -27
- package/dist/linalg/DualQuaternion.d.ts.map +1 -1
- package/dist/linalg/DualQuaternion.js +429 -54
- package/dist/linalg/DualQuaternion.js.map +1 -1
- package/dist/linalg/Matrix.d.ts +67 -0
- package/dist/linalg/Matrix.d.ts.map +1 -1
- package/dist/linalg/Matrix2.d.ts +309 -20
- package/dist/linalg/Matrix2.d.ts.map +1 -1
- package/dist/linalg/Matrix2.js +321 -40
- package/dist/linalg/Matrix2.js.map +1 -1
- package/dist/linalg/Matrix3.d.ts +424 -26
- package/dist/linalg/Matrix3.d.ts.map +1 -1
- package/dist/linalg/Matrix3.js +437 -52
- package/dist/linalg/Matrix3.js.map +1 -1
- package/dist/linalg/Matrix4.d.ts +766 -42
- package/dist/linalg/Matrix4.d.ts.map +1 -1
- package/dist/linalg/Matrix4.js +789 -84
- package/dist/linalg/Matrix4.js.map +1 -1
- package/dist/linalg/Quaternion.d.ts +359 -21
- package/dist/linalg/Quaternion.d.ts.map +1 -1
- package/dist/linalg/Quaternion.js +380 -42
- package/dist/linalg/Quaternion.js.map +1 -1
- package/dist/linalg/SlowMatrix.d.ts +70 -0
- package/dist/linalg/SlowMatrix.d.ts.map +1 -1
- package/dist/linalg/SlowMatrix.js +71 -0
- package/dist/linalg/SlowMatrix.js.map +1 -1
- package/dist/linalg/SlowSquareMatrix.d.ts +55 -0
- package/dist/linalg/SlowSquareMatrix.d.ts.map +1 -1
- package/dist/linalg/SlowSquareMatrix.js +58 -0
- package/dist/linalg/SlowSquareMatrix.js.map +1 -1
- package/dist/linalg/SquareMatrix.d.ts +23 -0
- package/dist/linalg/SquareMatrix.d.ts.map +1 -1
- package/dist/linalg/Vector.d.ts +123 -0
- package/dist/linalg/Vector.d.ts.map +1 -1
- package/dist/linalg/Vector2.d.ts +450 -33
- package/dist/linalg/Vector2.d.ts.map +1 -1
- package/dist/linalg/Vector2.js +480 -66
- package/dist/linalg/Vector2.js.map +1 -1
- package/dist/linalg/Vector3.d.ts +542 -38
- package/dist/linalg/Vector3.d.ts.map +1 -1
- package/dist/linalg/Vector3.js +579 -76
- package/dist/linalg/Vector3.js.map +1 -1
- package/dist/linalg/Vector4.d.ts +416 -30
- package/dist/linalg/Vector4.d.ts.map +1 -1
- package/dist/linalg/Vector4.js +441 -60
- package/dist/linalg/Vector4.js.map +1 -1
- package/dist/types/AxisAngle.d.ts +3 -0
- package/dist/types/AxisAngle.d.ts.map +1 -1
- package/dist/types/FieldOfView.d.ts +5 -0
- package/dist/types/FieldOfView.d.ts.map +1 -1
- package/dist/utility/BigNumber.d.ts +36 -0
- package/dist/utility/BigNumber.d.ts.map +1 -1
- package/dist/utility/BigNumber.js +42 -0
- package/dist/utility/BigNumber.js.map +1 -1
- package/dist/utility/MagnitudeError.d.ts +5 -0
- package/dist/utility/MagnitudeError.d.ts.map +1 -1
- package/dist/utility/MagnitudeError.js +5 -0
- package/dist/utility/MagnitudeError.js.map +1 -1
- package/dist/utility/MatrixSizeError.d.ts +5 -0
- package/dist/utility/MatrixSizeError.d.ts.map +1 -1
- package/dist/utility/MatrixSizeError.js +5 -0
- package/dist/utility/MatrixSizeError.js.map +1 -1
- package/dist/utility/PartialMatrixError.d.ts +5 -0
- package/dist/utility/PartialMatrixError.d.ts.map +1 -1
- package/dist/utility/PartialMatrixError.js +5 -0
- package/dist/utility/PartialMatrixError.js.map +1 -1
- package/dist/utility/SingularMatrixError.d.ts +8 -0
- package/dist/utility/SingularMatrixError.d.ts.map +1 -1
- package/dist/utility/SingularMatrixError.js +8 -0
- package/dist/utility/SingularMatrixError.js.map +1 -1
- package/dist/utility/epsilon.d.ts +1 -0
- package/dist/utility/epsilon.d.ts.map +1 -1
- package/dist/utility/epsilon.js +1 -0
- package/dist/utility/epsilon.js.map +1 -1
- package/package.json +1 -1
- package/src/algorithms/combinations.ts +1 -1
- package/src/algorithms/degreesToRadians.ts +1 -1
- package/src/algorithms/factorial.ts +1 -1
- package/src/algorithms/fibonacci.ts +1 -1
- package/src/algorithms/hypergeometricPmf.ts +1 -1
- package/src/algorithms/isPrime.ts +1 -1
- package/src/algorithms/permutations.ts +1 -1
- package/src/algorithms/primeFactorization.ts +1 -1
- package/src/algorithms/radiansToDegrees.ts +1 -1
- package/src/algorithms/summation.ts +1 -1
- package/src/linalg/DualQuaternion.ts +115 -109
- package/src/linalg/Matrix2.ts +83 -70
- package/src/linalg/Matrix3.ts +107 -94
- package/src/linalg/Matrix4.ts +171 -155
- package/src/linalg/Quaternion.ts +96 -92
- package/src/linalg/SlowMatrix.ts +13 -13
- package/src/linalg/SlowSquareMatrix.ts +11 -11
- package/src/linalg/Vector2.ts +130 -116
- package/src/linalg/Vector3.ts +152 -135
- package/src/linalg/Vector4.ts +121 -104
- package/src/utility/BigNumber.ts +7 -7
package/dist/linalg/Matrix3.js
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
import SingularMatrixError from "../utility/SingularMatrixError.js";
|
|
2
2
|
import epsilon from "../utility/epsilon.js";
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Creates a 3x3 matrix-like object.
|
|
5
|
+
* @returns A 3x3 matrix-like object.
|
|
6
|
+
*/
|
|
7
|
+
export const createMatrix3Like = () => {
|
|
4
8
|
return new Float32Array(9);
|
|
5
|
-
}
|
|
6
|
-
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Create a transformation matrix that represents a rotation by the given angle around the Z-axis.
|
|
12
|
+
* @param r - The angle in radians.
|
|
13
|
+
* @param out - The matrix to store the result in.
|
|
14
|
+
* @returns The transformation matrix.
|
|
15
|
+
* @see [Rotation matrix](https://en.wikipedia.org/wiki/Rotation_matrix)
|
|
16
|
+
*/
|
|
17
|
+
export const fromRotation = (r, out) => {
|
|
7
18
|
const s = Math.sin(r);
|
|
8
19
|
const c = Math.cos(r);
|
|
9
20
|
out[0] = c;
|
|
@@ -16,8 +27,15 @@ export function fromRotation(r, out) {
|
|
|
16
27
|
out[7] = 0;
|
|
17
28
|
out[8] = 1;
|
|
18
29
|
return out;
|
|
19
|
-
}
|
|
20
|
-
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Create a transformation matrix that represents a scaling by the given vector.
|
|
33
|
+
* @param vector - The scaling vector.
|
|
34
|
+
* @param out - The matrix to store the result in.
|
|
35
|
+
* @returns The transformation matrix.
|
|
36
|
+
* @see [Transformation matrix](https://en.wikipedia.org/wiki/Transformation_matrix)
|
|
37
|
+
*/
|
|
38
|
+
export const fromScaling = (vector, out) => {
|
|
21
39
|
out[0] = vector[0];
|
|
22
40
|
out[1] = 0;
|
|
23
41
|
out[2] = 0;
|
|
@@ -28,8 +46,15 @@ export function fromScaling(vector, out) {
|
|
|
28
46
|
out[7] = 0;
|
|
29
47
|
out[8] = 1;
|
|
30
48
|
return out;
|
|
31
|
-
}
|
|
32
|
-
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Create a transformation matrix that represents a translation by the given vector.
|
|
52
|
+
* @param vector - The translation vector.
|
|
53
|
+
* @param out - The matrix to store the result in.
|
|
54
|
+
* @returns The transformation matrix.
|
|
55
|
+
* @see [Transformation matrix](https://en.wikipedia.org/wiki/Transformation_matrix)
|
|
56
|
+
*/
|
|
57
|
+
export const fromTranslation = (vector, out) => {
|
|
33
58
|
out[0] = 1;
|
|
34
59
|
out[1] = 0;
|
|
35
60
|
out[2] = 0;
|
|
@@ -40,8 +65,16 @@ export function fromTranslation(vector, out) {
|
|
|
40
65
|
out[7] = vector[1];
|
|
41
66
|
out[8] = 1;
|
|
42
67
|
return out;
|
|
43
|
-
}
|
|
44
|
-
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Create a transformation matrix that represents a rotation by the given quaternion.
|
|
71
|
+
* @param quaternion - The quaternion.
|
|
72
|
+
* @param out - The matrix to store the result in.
|
|
73
|
+
* @returns The transformation matrix.
|
|
74
|
+
* @see [Quaternion](https://en.wikipedia.org/wiki/Quaternion)
|
|
75
|
+
* @see [Rotation matrix](https://en.wikipedia.org/wiki/Rotation_matrix)
|
|
76
|
+
*/
|
|
77
|
+
export const fromQuaternion = (quaternion, out) => {
|
|
45
78
|
const x = quaternion[0];
|
|
46
79
|
const y = quaternion[1];
|
|
47
80
|
const z = quaternion[2];
|
|
@@ -68,8 +101,15 @@ export function fromQuaternion(quaternion, out) {
|
|
|
68
101
|
out[5] = zy + wx;
|
|
69
102
|
out[8] = 1 - xx - yy;
|
|
70
103
|
return out;
|
|
71
|
-
}
|
|
72
|
-
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Calculate a three-by-three normal (inverse transpose) matrix from a four-by-four matrix.
|
|
107
|
+
* @param matrix - The four-by-four matrix.
|
|
108
|
+
* @param out - The matrix to store the result in.
|
|
109
|
+
* @returns The normal matrix.
|
|
110
|
+
* @see [Normal matrix](https://en.wikipedia.org/wiki/Normal_matrix)
|
|
111
|
+
*/
|
|
112
|
+
export const normalFromMatrix4 = (matrix, out) => {
|
|
73
113
|
const a00 = matrix[0];
|
|
74
114
|
const a01 = matrix[1];
|
|
75
115
|
const a02 = matrix[2];
|
|
@@ -113,8 +153,17 @@ export function normalFromMatrix4(matrix, out) {
|
|
|
113
153
|
out[7] = (a32 * b02 - a30 * b05 - a33 * b01) * det;
|
|
114
154
|
out[8] = (a30 * b04 - a31 * b02 + a33 * b00) * det;
|
|
115
155
|
return out;
|
|
116
|
-
}
|
|
117
|
-
|
|
156
|
+
};
|
|
157
|
+
/**
|
|
158
|
+
* Generate a two-dimensional projection matrix with the given bounds.
|
|
159
|
+
* @param width - The width of the projection.
|
|
160
|
+
* @param height - The height of the projection.
|
|
161
|
+
* @param out - The matrix to store the result in.
|
|
162
|
+
* @returns The projection matrix.
|
|
163
|
+
* @see [Camera matrix](https://en.wikipedia.org/wiki/Camera_matrix)
|
|
164
|
+
* @see [3D projection](https://en.wikipedia.org/wiki/3D_projection)
|
|
165
|
+
*/
|
|
166
|
+
export const projection = (width, height, out) => {
|
|
118
167
|
out[0] = 2 / width;
|
|
119
168
|
out[1] = 0;
|
|
120
169
|
out[2] = 0;
|
|
@@ -125,8 +174,14 @@ export function projection(width, height, out) {
|
|
|
125
174
|
out[7] = 1;
|
|
126
175
|
out[8] = 1;
|
|
127
176
|
return out;
|
|
128
|
-
}
|
|
129
|
-
|
|
177
|
+
};
|
|
178
|
+
/**
|
|
179
|
+
* Create a three-by-three matrix from the upper-left corner of a four-by-four matrix.
|
|
180
|
+
* @param matrix - The four-by-four matrix.
|
|
181
|
+
* @param out - The matrix to store the result in.
|
|
182
|
+
* @returns The three-by-three matrix.
|
|
183
|
+
*/
|
|
184
|
+
export const fromMatrix4 = (matrix, out) => {
|
|
130
185
|
out[0] = matrix[0];
|
|
131
186
|
out[1] = matrix[1];
|
|
132
187
|
out[2] = matrix[2];
|
|
@@ -137,8 +192,22 @@ export function fromMatrix4(matrix, out) {
|
|
|
137
192
|
out[7] = matrix[9];
|
|
138
193
|
out[8] = matrix[10];
|
|
139
194
|
return out;
|
|
140
|
-
}
|
|
141
|
-
|
|
195
|
+
};
|
|
196
|
+
/**
|
|
197
|
+
* Create a two-by-two matrix with the given values.
|
|
198
|
+
* @param c0r0 - The value in the first column and first row.
|
|
199
|
+
* @param c0r1 - The value in the first column and second row.
|
|
200
|
+
* @param c0r2 - The value in the first column and third row.
|
|
201
|
+
* @param c1r0 - The value in the second column and first row.
|
|
202
|
+
* @param c1r1 - The value in the second column and second row.
|
|
203
|
+
* @param c1r2 - The value in the second column and third row.
|
|
204
|
+
* @param c2r0 - The value in the third column and first row.
|
|
205
|
+
* @param c2r1 - The value in the third column and second row.
|
|
206
|
+
* @param c2r2 - The value in the third column and third row.
|
|
207
|
+
* @param out - The matrix to store the result in.
|
|
208
|
+
* @returns The matrix.
|
|
209
|
+
*/
|
|
210
|
+
export const fromValues = (c0r0, c0r1, c0r2, c1r0, c1r1, c1r2, c2r0, c2r1, c2r2, out) => {
|
|
142
211
|
out[0] = c0r0;
|
|
143
212
|
out[1] = c0r1;
|
|
144
213
|
out[2] = c0r2;
|
|
@@ -149,8 +218,14 @@ export function fromValues(c0r0, c0r1, c0r2, c1r0, c1r1, c1r2, c2r0, c2r1, c2r2,
|
|
|
149
218
|
out[7] = c2r1;
|
|
150
219
|
out[8] = c2r2;
|
|
151
220
|
return out;
|
|
152
|
-
}
|
|
153
|
-
|
|
221
|
+
};
|
|
222
|
+
/**
|
|
223
|
+
* Determine whether or not two matrices are roughly equivalent.
|
|
224
|
+
* @param a - The first matrix.
|
|
225
|
+
* @param b - The second matrix.
|
|
226
|
+
* @returns Whether or not the matrices are equivalent.
|
|
227
|
+
*/
|
|
228
|
+
export const equals = (a, b) => {
|
|
154
229
|
const a0 = a[0];
|
|
155
230
|
const a1 = a[1];
|
|
156
231
|
const a2 = a[2];
|
|
@@ -178,8 +253,14 @@ export function equals(a, b) {
|
|
|
178
253
|
Math.abs(a6 - b6) <= epsilon * Math.max(1, Math.abs(a6), Math.abs(b6)) &&
|
|
179
254
|
Math.abs(a7 - b7) <= epsilon * Math.max(1, Math.abs(a7), Math.abs(b7)) &&
|
|
180
255
|
Math.abs(a8 - b8) <= epsilon * Math.max(1, Math.abs(a8), Math.abs(b8)));
|
|
181
|
-
}
|
|
182
|
-
|
|
256
|
+
};
|
|
257
|
+
/**
|
|
258
|
+
* Determine whether or not two matrices are exactly equivalent.
|
|
259
|
+
* @param a - The first matrix.
|
|
260
|
+
* @param b - The second matrix.
|
|
261
|
+
* @returns Whether or not the matrices are equivalent.
|
|
262
|
+
*/
|
|
263
|
+
export const exactEquals = (a, b) => {
|
|
183
264
|
return (a[0] === b[0] &&
|
|
184
265
|
a[1] === b[1] &&
|
|
185
266
|
a[2] === b[2] &&
|
|
@@ -189,8 +270,16 @@ export function exactEquals(a, b) {
|
|
|
189
270
|
a[6] === b[6] &&
|
|
190
271
|
a[7] === b[7] &&
|
|
191
272
|
a[8] === b[8]);
|
|
192
|
-
}
|
|
193
|
-
|
|
273
|
+
};
|
|
274
|
+
/**
|
|
275
|
+
* Add two matrices.
|
|
276
|
+
* @param a - The augend.
|
|
277
|
+
* @param b - The addend.
|
|
278
|
+
* @param out - The matrix to store the result in.
|
|
279
|
+
* @returns The sum.
|
|
280
|
+
* @see [Matrix addition](https://en.wikipedia.org/wiki/Matrix_addition)
|
|
281
|
+
*/
|
|
282
|
+
export const add = (a, b, out) => {
|
|
194
283
|
out[0] = a[0] + b[0];
|
|
195
284
|
out[1] = a[1] + b[1];
|
|
196
285
|
out[2] = a[2] + b[2];
|
|
@@ -201,8 +290,15 @@ export function add(a, b, out) {
|
|
|
201
290
|
out[7] = a[7] + b[7];
|
|
202
291
|
out[8] = a[8] + b[8];
|
|
203
292
|
return out;
|
|
204
|
-
}
|
|
205
|
-
|
|
293
|
+
};
|
|
294
|
+
/**
|
|
295
|
+
* Calculate the adjugate of a matrix.
|
|
296
|
+
* @param matrix - The matrix.
|
|
297
|
+
* @param out - The matrix to store the result in.
|
|
298
|
+
* @returns The adjugate of the matrix.
|
|
299
|
+
* @see [Adjugate matrix](https://en.wikipedia.org/wiki/Adjugate_matrix)
|
|
300
|
+
*/
|
|
301
|
+
export const adjoint = (matrix, out) => {
|
|
206
302
|
const a00 = matrix[0];
|
|
207
303
|
const a01 = matrix[1];
|
|
208
304
|
const a02 = matrix[2];
|
|
@@ -222,8 +318,14 @@ export function adjoint(matrix, out) {
|
|
|
222
318
|
out[7] = a01 * a20 - a00 * a21;
|
|
223
319
|
out[8] = a00 * a11 - a01 * a10;
|
|
224
320
|
return out;
|
|
225
|
-
}
|
|
226
|
-
|
|
321
|
+
};
|
|
322
|
+
/**
|
|
323
|
+
* Copy the values of one matrix into another.
|
|
324
|
+
* @param matrix - The matrix to copy.
|
|
325
|
+
* @param out - The matrix to store the result in.
|
|
326
|
+
* @returns This matrix.
|
|
327
|
+
*/
|
|
328
|
+
export const copy = (matrix, out) => {
|
|
227
329
|
out[0] = matrix[0];
|
|
228
330
|
out[1] = matrix[1];
|
|
229
331
|
out[2] = matrix[2];
|
|
@@ -234,11 +336,25 @@ export function copy(matrix, out) {
|
|
|
234
336
|
out[7] = matrix[7];
|
|
235
337
|
out[8] = matrix[8];
|
|
236
338
|
return out;
|
|
237
|
-
}
|
|
238
|
-
|
|
339
|
+
};
|
|
340
|
+
/**
|
|
341
|
+
* Calculate the Frobenius norm of a matrix.
|
|
342
|
+
* @param matrix - The matrix.
|
|
343
|
+
* @returns The Frobenius norm.
|
|
344
|
+
* @see [Matrix norm](https://en.wikipedia.org/wiki/Matrix_norm)
|
|
345
|
+
*/
|
|
346
|
+
export const frob = (matrix) => {
|
|
239
347
|
return Math.hypot(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5], matrix[6], matrix[7], matrix[8]);
|
|
240
|
-
}
|
|
241
|
-
|
|
348
|
+
};
|
|
349
|
+
/**
|
|
350
|
+
* Multiply two matrices.
|
|
351
|
+
* @param a - The multiplicand.
|
|
352
|
+
* @param b - The multiplier.
|
|
353
|
+
* @param out - The matrix to store the result in.
|
|
354
|
+
* @returns The product of the matrices.
|
|
355
|
+
* @see [Matrix multiplication](https://en.wikipedia.org/wiki/Matrix_multiplication)
|
|
356
|
+
*/
|
|
357
|
+
export const multiply = (a, b, out) => {
|
|
242
358
|
const a00 = a[0];
|
|
243
359
|
const a01 = a[1];
|
|
244
360
|
const a02 = a[2];
|
|
@@ -267,8 +383,16 @@ export function multiply(a, b, out) {
|
|
|
267
383
|
out[7] = b20 * a01 + b21 * a11 + b22 * a21;
|
|
268
384
|
out[8] = b20 * a02 + b21 * a12 + b22 * a22;
|
|
269
385
|
return out;
|
|
270
|
-
}
|
|
271
|
-
|
|
386
|
+
};
|
|
387
|
+
/**
|
|
388
|
+
* Multiply a matrix by a scalar value.
|
|
389
|
+
* @param matrix - The multiplicand.
|
|
390
|
+
* @param scalar - The multiplier.
|
|
391
|
+
* @param out - The matrix to store the result in.
|
|
392
|
+
* @returns The product.
|
|
393
|
+
* @see [Matrix multiplication](https://en.wikipedia.org/wiki/Matrix_multiplication)
|
|
394
|
+
*/
|
|
395
|
+
export const multiplyScalar = (matrix, scalar, out) => {
|
|
272
396
|
out[0] = matrix[0] * scalar;
|
|
273
397
|
out[1] = matrix[1] * scalar;
|
|
274
398
|
out[2] = matrix[2] * scalar;
|
|
@@ -279,8 +403,18 @@ export function multiplyScalar(matrix, scalar, out) {
|
|
|
279
403
|
out[7] = matrix[7] * scalar;
|
|
280
404
|
out[8] = matrix[8] * scalar;
|
|
281
405
|
return out;
|
|
282
|
-
}
|
|
283
|
-
|
|
406
|
+
};
|
|
407
|
+
/**
|
|
408
|
+
* Add a matrix to another after multiplying the other by a scalar.
|
|
409
|
+
* @param a - The augend.
|
|
410
|
+
* @param b - The addend.
|
|
411
|
+
* @param scalar - The multiplier.
|
|
412
|
+
* @param out - The matrix to store the result in.
|
|
413
|
+
* @returns The sum.
|
|
414
|
+
* @see [Matrix addition](https://en.wikipedia.org/wiki/Matrix_addition)
|
|
415
|
+
* @see [Matrix multiplication](https://en.wikipedia.org/wiki/Matrix_multiplication)
|
|
416
|
+
*/
|
|
417
|
+
export const multiplyScalarAndAdd = (a, b, scalar, out) => {
|
|
284
418
|
out[0] = a[0] + b[0] * scalar;
|
|
285
419
|
out[1] = a[1] + b[1] * scalar;
|
|
286
420
|
out[2] = a[2] + b[2] * scalar;
|
|
@@ -291,8 +425,16 @@ export function multiplyScalarAndAdd(a, b, scalar, out) {
|
|
|
291
425
|
out[7] = a[7] + b[7] * scalar;
|
|
292
426
|
out[8] = a[8] + b[8] * scalar;
|
|
293
427
|
return out;
|
|
294
|
-
}
|
|
295
|
-
|
|
428
|
+
};
|
|
429
|
+
/**
|
|
430
|
+
* Subtract two matrices.
|
|
431
|
+
* @param a - The minuend.
|
|
432
|
+
* @param b - The subtrahend.
|
|
433
|
+
* @param out - The matrix to store the result in.
|
|
434
|
+
* @returns The difference.
|
|
435
|
+
* @see [Matrix addition](https://en.wikipedia.org/wiki/Matrix_addition)
|
|
436
|
+
*/
|
|
437
|
+
export const subtract = (a, b, out) => {
|
|
296
438
|
out[0] = a[0] - b[0];
|
|
297
439
|
out[1] = a[1] - b[1];
|
|
298
440
|
out[2] = a[2] - b[2];
|
|
@@ -303,8 +445,15 @@ export function subtract(a, b, out) {
|
|
|
303
445
|
out[7] = a[7] - b[7];
|
|
304
446
|
out[8] = a[8] - b[8];
|
|
305
447
|
return out;
|
|
306
|
-
}
|
|
307
|
-
|
|
448
|
+
};
|
|
449
|
+
/**
|
|
450
|
+
* Transpose a matrix.
|
|
451
|
+
* @param matrix - The matrix.
|
|
452
|
+
* @param out - The matrix to store the result in.
|
|
453
|
+
* @returns The transpose of the matrix.
|
|
454
|
+
* @see [Transpose](https://en.wikipedia.org/wiki/Transpose)
|
|
455
|
+
*/
|
|
456
|
+
export const transpose = (matrix, out) => {
|
|
308
457
|
if (out === matrix) {
|
|
309
458
|
const a01 = matrix[1];
|
|
310
459
|
const a02 = matrix[2];
|
|
@@ -328,8 +477,14 @@ export function transpose(matrix, out) {
|
|
|
328
477
|
out[8] = matrix[8];
|
|
329
478
|
}
|
|
330
479
|
return out;
|
|
331
|
-
}
|
|
332
|
-
|
|
480
|
+
};
|
|
481
|
+
/**
|
|
482
|
+
* Calculate the determinant of a matrix.
|
|
483
|
+
* @param matrix - The matrix.
|
|
484
|
+
* @returns The determinant.
|
|
485
|
+
* @see [Determinant](https://en.wikipedia.org/wiki/Determinant)
|
|
486
|
+
*/
|
|
487
|
+
export const determinant = (matrix) => {
|
|
333
488
|
const a00 = matrix[0];
|
|
334
489
|
const a01 = matrix[1];
|
|
335
490
|
const a02 = matrix[2];
|
|
@@ -342,8 +497,14 @@ export function determinant(matrix) {
|
|
|
342
497
|
return (a00 * (a22 * a11 - a12 * a21) +
|
|
343
498
|
a01 * (-a22 * a10 + a12 * a20) +
|
|
344
499
|
a02 * (a21 * a10 - a11 * a20));
|
|
345
|
-
}
|
|
346
|
-
|
|
500
|
+
};
|
|
501
|
+
/**
|
|
502
|
+
* Reset a matrix to identity.
|
|
503
|
+
* @param out - The matrix to store the result in.
|
|
504
|
+
* @returns The matrix.
|
|
505
|
+
* @see [Identity matrix](https://en.wikipedia.org/wiki/Identity_matrix)
|
|
506
|
+
*/
|
|
507
|
+
export const identity = (out) => {
|
|
347
508
|
out[0] = 1;
|
|
348
509
|
out[1] = 0;
|
|
349
510
|
out[2] = 0;
|
|
@@ -354,8 +515,15 @@ export function identity(out) {
|
|
|
354
515
|
out[7] = 0;
|
|
355
516
|
out[8] = 1;
|
|
356
517
|
return out;
|
|
357
|
-
}
|
|
358
|
-
|
|
518
|
+
};
|
|
519
|
+
/**
|
|
520
|
+
* Invert a matrix.
|
|
521
|
+
* @param matrix - The matrix.
|
|
522
|
+
* @param out - The matrix to store the result in.
|
|
523
|
+
* @returns The inverted matrix.
|
|
524
|
+
* @see [Invertible matrix](https://en.wikipedia.org/wiki/Invertible_matrix)
|
|
525
|
+
*/
|
|
526
|
+
export const invert = (matrix, out) => {
|
|
359
527
|
const a00 = matrix[0];
|
|
360
528
|
const a01 = matrix[1];
|
|
361
529
|
const a02 = matrix[2];
|
|
@@ -383,8 +551,16 @@ export function invert(matrix, out) {
|
|
|
383
551
|
out[7] = (-a21 * a00 + a01 * a20) * det;
|
|
384
552
|
out[8] = (a11 * a00 - a01 * a10) * det;
|
|
385
553
|
return out;
|
|
386
|
-
}
|
|
387
|
-
|
|
554
|
+
};
|
|
555
|
+
/**
|
|
556
|
+
* Rotate a matrix by the given angle around the Z-axis.
|
|
557
|
+
* @param matrix - The matrix.
|
|
558
|
+
* @param radians - The angle in radians.
|
|
559
|
+
* @param out - The matrix to store the result in.
|
|
560
|
+
* @returns The rotated matrix.
|
|
561
|
+
* @see [Rotation matrix](https://en.wikipedia.org/wiki/Rotation_matrix)
|
|
562
|
+
*/
|
|
563
|
+
export const rotate = (matrix, radians, out) => {
|
|
388
564
|
const a00 = matrix[0];
|
|
389
565
|
const a01 = matrix[1];
|
|
390
566
|
const a02 = matrix[2];
|
|
@@ -406,8 +582,16 @@ export function rotate(matrix, radians, out) {
|
|
|
406
582
|
out[7] = a21;
|
|
407
583
|
out[8] = a22;
|
|
408
584
|
return out;
|
|
409
|
-
}
|
|
410
|
-
|
|
585
|
+
};
|
|
586
|
+
/**
|
|
587
|
+
* Scale a matrix by the given vector.
|
|
588
|
+
* @param matrix - The matrix.
|
|
589
|
+
* @param vector - The scaling vector.
|
|
590
|
+
* @param out - The matrix to store the result in.
|
|
591
|
+
* @returns The scaled matrix.
|
|
592
|
+
* @see [Transformation matrix](https://en.wikipedia.org/wiki/Transformation_matrix)
|
|
593
|
+
*/
|
|
594
|
+
export const scale = (matrix, vector, out) => {
|
|
411
595
|
const x = vector[0];
|
|
412
596
|
const y = vector[1];
|
|
413
597
|
out[0] = matrix[0] * x;
|
|
@@ -420,8 +604,16 @@ export function scale(matrix, vector, out) {
|
|
|
420
604
|
out[7] = matrix[7];
|
|
421
605
|
out[8] = matrix[8];
|
|
422
606
|
return out;
|
|
423
|
-
}
|
|
424
|
-
|
|
607
|
+
};
|
|
608
|
+
/**
|
|
609
|
+
* Translate a matrix by the given vector.
|
|
610
|
+
* @param matrix - The matrix.
|
|
611
|
+
* @param vector - The translation vector.
|
|
612
|
+
* @param out - The matrix to store the result in.
|
|
613
|
+
* @returns The translated matrix.
|
|
614
|
+
* @see [Transformation matrix](https://en.wikipedia.org/wiki/Transformation_matrix)
|
|
615
|
+
*/
|
|
616
|
+
export const translate = (matrix, vector, out) => {
|
|
425
617
|
const a00 = matrix[0];
|
|
426
618
|
const a01 = matrix[1];
|
|
427
619
|
const a02 = matrix[2];
|
|
@@ -443,32 +635,105 @@ export function translate(matrix, vector, out) {
|
|
|
443
635
|
out[7] = x * a01 + y * a11 + a21;
|
|
444
636
|
out[8] = x * a02 + y * a12 + a22;
|
|
445
637
|
return out;
|
|
446
|
-
}
|
|
638
|
+
};
|
|
639
|
+
/**
|
|
640
|
+
* A three-by-three matrix.
|
|
641
|
+
* @see [Matrix](https://en.wikipedia.org/wiki/Matrix_(mathematics))
|
|
642
|
+
*/
|
|
447
643
|
export default class Matrix3 extends Float32Array {
|
|
644
|
+
/**
|
|
645
|
+
* Create a transformation matrix that represents a rotation by the given angle around the Z-axis.
|
|
646
|
+
* @param r - The angle in radians.
|
|
647
|
+
* @param out - The matrix to store the result in.
|
|
648
|
+
* @returns The transformation matrix.
|
|
649
|
+
* @see [Rotation matrix](https://en.wikipedia.org/wiki/Rotation_matrix)
|
|
650
|
+
*/
|
|
448
651
|
static fromRotation(r, out = new Matrix3()) {
|
|
449
652
|
return fromRotation(r, out);
|
|
450
653
|
}
|
|
654
|
+
/**
|
|
655
|
+
* Create a transformation matrix that represents a scaling by the given vector.
|
|
656
|
+
* @param vector - The scaling vector.
|
|
657
|
+
* @param out - The matrix to store the result in.
|
|
658
|
+
* @returns The transformation matrix.
|
|
659
|
+
* @see [Transformation matrix](https://en.wikipedia.org/wiki/Transformation_matrix)
|
|
660
|
+
*/
|
|
451
661
|
static fromScaling(vector, out = new Matrix3()) {
|
|
452
662
|
return fromScaling(vector, out);
|
|
453
663
|
}
|
|
664
|
+
/**
|
|
665
|
+
* Create a transformation matrix that represents a translation by the given vector.
|
|
666
|
+
* @param vector - The translation vector.
|
|
667
|
+
* @param out - The matrix to store the result in.
|
|
668
|
+
* @returns The transformation matrix.
|
|
669
|
+
* @see [Transformation matrix](https://en.wikipedia.org/wiki/Transformation_matrix)
|
|
670
|
+
*/
|
|
454
671
|
static fromTranslation(vector, out = new Matrix3()) {
|
|
455
672
|
return fromTranslation(vector, out);
|
|
456
673
|
}
|
|
674
|
+
/**
|
|
675
|
+
* Create a transformation matrix that represents a rotation by the given quaternion.
|
|
676
|
+
* @param quaternion - The quaternion.
|
|
677
|
+
* @param out - The matrix to store the result in.
|
|
678
|
+
* @returns The transformation matrix.
|
|
679
|
+
* @see [Quaternion](https://en.wikipedia.org/wiki/Quaternion)
|
|
680
|
+
* @see [Rotation matrix](https://en.wikipedia.org/wiki/Rotation_matrix)
|
|
681
|
+
*/
|
|
457
682
|
static fromQuaternion(quaternion, out = new Matrix3()) {
|
|
458
683
|
return fromQuaternion(quaternion, out);
|
|
459
684
|
}
|
|
685
|
+
/**
|
|
686
|
+
* Calculate a three-by-three normal (inverse transpose) matrix from a four-by-four matrix.
|
|
687
|
+
* @param matrix - The four-by-four matrix.
|
|
688
|
+
* @param out - The matrix to store the result in.
|
|
689
|
+
* @returns The normal matrix.
|
|
690
|
+
* @see [Normal matrix](https://en.wikipedia.org/wiki/Normal_matrix)
|
|
691
|
+
*/
|
|
460
692
|
static normalFromMatrix4(matrix, out = new Matrix3()) {
|
|
461
693
|
return normalFromMatrix4(matrix, out);
|
|
462
694
|
}
|
|
695
|
+
/**
|
|
696
|
+
* Generate a two-dimensional projection matrix with the given bounds.
|
|
697
|
+
* @param width - The width of the projection.
|
|
698
|
+
* @param height - The height of the projection.
|
|
699
|
+
* @param out - The matrix to store the result in.
|
|
700
|
+
* @returns The projection matrix.
|
|
701
|
+
* @see [Camera matrix](https://en.wikipedia.org/wiki/Camera_matrix)
|
|
702
|
+
* @see [3D projection](https://en.wikipedia.org/wiki/3D_projection)
|
|
703
|
+
*/
|
|
463
704
|
static projection(width, height, out = new Matrix3()) {
|
|
464
705
|
return projection(width, height, out);
|
|
465
706
|
}
|
|
707
|
+
/**
|
|
708
|
+
* Create a three-by-three matrix from the upper-left corner of a four-by-four matrix.
|
|
709
|
+
* @param matrix - The four-by-four matrix.
|
|
710
|
+
* @param out - The matrix to store the result in.
|
|
711
|
+
* @returns The three-by-three matrix.
|
|
712
|
+
*/
|
|
466
713
|
static fromMatrix4(matrix, out = new Matrix3()) {
|
|
467
714
|
return fromMatrix4(matrix, out);
|
|
468
715
|
}
|
|
716
|
+
/**
|
|
717
|
+
* Create a two-by-two matrix with the given values.
|
|
718
|
+
* @param c0r0 - The value in the first column and first row.
|
|
719
|
+
* @param c0r1 - The value in the first column and second row.
|
|
720
|
+
* @param c0r2 - The value in the first column and third row.
|
|
721
|
+
* @param c1r0 - The value in the second column and first row.
|
|
722
|
+
* @param c1r1 - The value in the second column and second row.
|
|
723
|
+
* @param c1r2 - The value in the second column and third row.
|
|
724
|
+
* @param c2r0 - The value in the third column and first row.
|
|
725
|
+
* @param c2r1 - The value in the third column and second row.
|
|
726
|
+
* @param c2r2 - The value in the third column and third row.
|
|
727
|
+
* @param out - The matrix to store the result in.
|
|
728
|
+
* @returns The matrix.
|
|
729
|
+
*/
|
|
469
730
|
static fromValues(c0r0, c0r1, c0r2, c1r0, c1r1, c1r2, c2r0, c2r1, c2r2, out = new Matrix3()) {
|
|
470
731
|
return fromValues(c0r0, c0r1, c0r2, c1r0, c1r1, c1r2, c2r0, c2r1, c2r2, out);
|
|
471
732
|
}
|
|
733
|
+
/**
|
|
734
|
+
* Create a three-by-three identity matrix.
|
|
735
|
+
* @see [Identity matrix](https://en.wikipedia.org/wiki/Identity_matrix)
|
|
736
|
+
*/
|
|
472
737
|
constructor() {
|
|
473
738
|
super(9);
|
|
474
739
|
this[0] = 1;
|
|
@@ -477,68 +742,188 @@ export default class Matrix3 extends Float32Array {
|
|
|
477
742
|
this.width = 3;
|
|
478
743
|
this.height = 3;
|
|
479
744
|
}
|
|
745
|
+
/** The value in the first column and first row. */
|
|
480
746
|
0;
|
|
747
|
+
/** The value in the first column and second row. */
|
|
481
748
|
1;
|
|
749
|
+
/** The value in the first column and third row. */
|
|
482
750
|
2;
|
|
751
|
+
/** The value in the second column and first row. */
|
|
483
752
|
3;
|
|
753
|
+
/** The value in the second column and second row. */
|
|
484
754
|
4;
|
|
755
|
+
/** The value in the second column and third row. */
|
|
485
756
|
5;
|
|
757
|
+
/** The value in the third column and first row. */
|
|
486
758
|
6;
|
|
759
|
+
/** The value in the third column and second row. */
|
|
487
760
|
7;
|
|
761
|
+
/** The value in the third column and third row. */
|
|
488
762
|
8;
|
|
763
|
+
/** The number of columns in this matrix. */
|
|
489
764
|
width;
|
|
765
|
+
/** The number of rows in this matrix. */
|
|
490
766
|
height;
|
|
767
|
+
/**
|
|
768
|
+
* Determine whether or not this matrix is roughly equivalent to another.
|
|
769
|
+
* @param matrix - The other matrix.
|
|
770
|
+
* @returns Whether or not the matrices are equivalent.
|
|
771
|
+
*/
|
|
491
772
|
equals(matrix) {
|
|
492
773
|
return equals(this, matrix);
|
|
493
774
|
}
|
|
775
|
+
/**
|
|
776
|
+
* Determine whether or not this matrix is exactly equivalent to another.
|
|
777
|
+
* @param matrix - The other matrix.
|
|
778
|
+
* @returns Whether or not the matrices are equivalent.
|
|
779
|
+
*/
|
|
494
780
|
exactEquals(matrix) {
|
|
495
781
|
return exactEquals(this, matrix);
|
|
496
782
|
}
|
|
783
|
+
/**
|
|
784
|
+
* Add two matrices of the same size.
|
|
785
|
+
* @param matrix - The other matrix.
|
|
786
|
+
* @param out - The matrix to store the result in.
|
|
787
|
+
* @returns The sum of the matrices.
|
|
788
|
+
* @see [Matrix addition](https://en.wikipedia.org/wiki/Matrix_addition)
|
|
789
|
+
*/
|
|
497
790
|
add(matrix, out = new Matrix3()) {
|
|
498
791
|
return add(this, matrix, out);
|
|
499
792
|
}
|
|
793
|
+
/**
|
|
794
|
+
* Calculate the adjugate of this matrix.
|
|
795
|
+
* @param out - The matrix to store the result in.
|
|
796
|
+
* @returns The adjugate of this matrix.
|
|
797
|
+
* @see [Adjugate matrix](https://en.wikipedia.org/wiki/Adjugate_matrix)
|
|
798
|
+
*/
|
|
500
799
|
adjoint(out = new Matrix3()) {
|
|
501
800
|
return adjoint(this, out);
|
|
502
801
|
}
|
|
802
|
+
/**
|
|
803
|
+
* Copy the values from this matrix to another one.
|
|
804
|
+
* @param out - The matrix to store the result in.
|
|
805
|
+
* @returns The copy.
|
|
806
|
+
*/
|
|
503
807
|
clone(out = new Matrix3()) {
|
|
504
808
|
return copy(this, out);
|
|
505
809
|
}
|
|
810
|
+
/**
|
|
811
|
+
* Copy the values of another matrix into this one.
|
|
812
|
+
* @param matrix - The matrix to copy.
|
|
813
|
+
* @returns This matrix.
|
|
814
|
+
*/
|
|
506
815
|
copy(matrix) {
|
|
507
816
|
return copy(matrix, this);
|
|
508
817
|
}
|
|
818
|
+
/**
|
|
819
|
+
* Get the Frobenius norm of this matrix.
|
|
820
|
+
* @see [Matrix norm](https://en.wikipedia.org/wiki/Matrix_norm)
|
|
821
|
+
*/
|
|
509
822
|
get frob() {
|
|
510
823
|
return frob(this);
|
|
511
824
|
}
|
|
825
|
+
/**
|
|
826
|
+
* Multiply this matrix by another.
|
|
827
|
+
* @param matrix - The other matrix.
|
|
828
|
+
* @param out - The matrix to store the result in.
|
|
829
|
+
* @returns The product of the matrices.
|
|
830
|
+
* @see [Matrix multiplication](https://en.wikipedia.org/wiki/Matrix_multiplication)
|
|
831
|
+
*/
|
|
512
832
|
multiply(matrix, out = new Matrix3()) {
|
|
513
833
|
return multiply(this, matrix, out);
|
|
514
834
|
}
|
|
835
|
+
/**
|
|
836
|
+
* Multiply this matrix by a scalar value.
|
|
837
|
+
* @param scalar - The scalar value.
|
|
838
|
+
* @param out - The matrix to store the result in.
|
|
839
|
+
* @returns The product of the matrix and the scalar value.
|
|
840
|
+
* @see [Matrix multiplication](https://en.wikipedia.org/wiki/Matrix_multiplication)
|
|
841
|
+
*/
|
|
515
842
|
multiplyScalar(scalar, out = new Matrix3()) {
|
|
516
843
|
return multiplyScalar(this, scalar, out);
|
|
517
844
|
}
|
|
845
|
+
/**
|
|
846
|
+
* Add this matrix to another after multiplying the other by a scalar.
|
|
847
|
+
* @param matrix - The other matrix.
|
|
848
|
+
* @param scalar - The scalar.
|
|
849
|
+
* @param out - The matrix to store the result in.
|
|
850
|
+
* @returns The sum.
|
|
851
|
+
* @see [Matrix addition](https://en.wikipedia.org/wiki/Matrix_addition)
|
|
852
|
+
* @see [Matrix multiplication](https://en.wikipedia.org/wiki/Matrix_multiplication)
|
|
853
|
+
*/
|
|
518
854
|
multiplyScalarAndAdd(matrix, scalar, out = new Matrix3()) {
|
|
519
855
|
return multiplyScalarAndAdd(this, matrix, scalar, out);
|
|
520
856
|
}
|
|
857
|
+
/**
|
|
858
|
+
* Subtract another matrix from this one.
|
|
859
|
+
* @param matrix - The other matrix.
|
|
860
|
+
* @param out - The matrix to store the result in.
|
|
861
|
+
* @returns The difference between the matrices.
|
|
862
|
+
* @see [Matrix addition](https://en.wikipedia.org/wiki/Matrix_addition)
|
|
863
|
+
*/
|
|
521
864
|
subtract(matrix, out = new Matrix3()) {
|
|
522
865
|
return subtract(this, matrix, out);
|
|
523
866
|
}
|
|
867
|
+
/**
|
|
868
|
+
* Transpose this matrix.
|
|
869
|
+
* @param out - The matrix to store the result in.
|
|
870
|
+
* @returns The transpose of this matrix.
|
|
871
|
+
* @see [Transpose](https://en.wikipedia.org/wiki/Transpose)
|
|
872
|
+
*/
|
|
524
873
|
transpose(out = new Matrix3()) {
|
|
525
874
|
return transpose(this, out);
|
|
526
875
|
}
|
|
876
|
+
/**
|
|
877
|
+
* Get the determinant of this matrix.
|
|
878
|
+
* @see [Determinant](https://en.wikipedia.org/wiki/Determinant)
|
|
879
|
+
*/
|
|
527
880
|
get determinant() {
|
|
528
881
|
return determinant(this);
|
|
529
882
|
}
|
|
883
|
+
/**
|
|
884
|
+
* Reset this matrix to identity.
|
|
885
|
+
* @returns This matrix.
|
|
886
|
+
* @see [Identity matrix](https://en.wikipedia.org/wiki/Identity_matrix)
|
|
887
|
+
*/
|
|
530
888
|
identity() {
|
|
531
889
|
return identity(this);
|
|
532
890
|
}
|
|
891
|
+
/**
|
|
892
|
+
* Invert this matrix.
|
|
893
|
+
* @param out - The matrix to store the result in.
|
|
894
|
+
* @returns The inverted matrix.
|
|
895
|
+
* @see [Invertible matrix](https://en.wikipedia.org/wiki/Invertible_matrix)
|
|
896
|
+
*/
|
|
533
897
|
invert(out = new Matrix3()) {
|
|
534
898
|
return invert(this, out);
|
|
535
899
|
}
|
|
900
|
+
/**
|
|
901
|
+
* Rotate this matrix by the given angle around the Z-axis.
|
|
902
|
+
* @param r - The angle in radians.
|
|
903
|
+
* @param out - The matrix to store the result in.
|
|
904
|
+
* @returns The rotated matrix.
|
|
905
|
+
* @see [Rotation matrix](https://en.wikipedia.org/wiki/Rotation_matrix)
|
|
906
|
+
*/
|
|
536
907
|
rotate(r, out = new Matrix3()) {
|
|
537
908
|
return rotate(this, r, out);
|
|
538
909
|
}
|
|
910
|
+
/**
|
|
911
|
+
* Scale this matrix by the given vector.
|
|
912
|
+
* @param vector - The scaling vector.
|
|
913
|
+
* @param out - The matrix to store the result in.
|
|
914
|
+
* @returns The scaled matrix.
|
|
915
|
+
* @see [Transformation matrix](https://en.wikipedia.org/wiki/Transformation_matrix)
|
|
916
|
+
*/
|
|
539
917
|
scale(vector, out = new Matrix3()) {
|
|
540
918
|
return scale(this, vector, out);
|
|
541
919
|
}
|
|
920
|
+
/**
|
|
921
|
+
* Translate this matrix by the given vector.
|
|
922
|
+
* @param vector - The translation vector.
|
|
923
|
+
* @param out - The matrix to store the result in.
|
|
924
|
+
* @returns The translated matrix.
|
|
925
|
+
* @see [Transformation matrix](https://en.wikipedia.org/wiki/Transformation_matrix)
|
|
926
|
+
*/
|
|
542
927
|
translate(vector, out = new Matrix3()) {
|
|
543
928
|
return translate(this, vector, out);
|
|
544
929
|
}
|