@pawells/math-extended 1.1.1 → 2.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/build/angles.d.ts +28 -18
- package/build/angles.d.ts.map +1 -1
- package/build/angles.js +28 -18
- package/build/angles.js.map +1 -1
- package/build/clamp.d.ts +5 -3
- package/build/clamp.d.ts.map +1 -1
- package/build/clamp.js +5 -3
- package/build/clamp.js.map +1 -1
- package/build/interpolation.d.ts +158 -96
- package/build/interpolation.d.ts.map +1 -1
- package/build/interpolation.js +158 -96
- package/build/interpolation.js.map +1 -1
- package/build/matrices/_exports.d.ts +13 -0
- package/build/matrices/_exports.d.ts.map +1 -0
- package/build/matrices/_exports.js +13 -0
- package/build/matrices/_exports.js.map +1 -0
- package/build/matrices/arithmetic.d.ts +170 -181
- package/build/matrices/arithmetic.d.ts.map +1 -1
- package/build/matrices/arithmetic.js +192 -202
- package/build/matrices/arithmetic.js.map +1 -1
- package/build/matrices/asserts.d.ts +240 -109
- package/build/matrices/asserts.d.ts.map +1 -1
- package/build/matrices/asserts.js +287 -87
- package/build/matrices/asserts.js.map +1 -1
- package/build/matrices/core.d.ts +29 -29
- package/build/matrices/core.js +1 -1
- package/build/matrices/decompositions.d.ts +102 -104
- package/build/matrices/decompositions.d.ts.map +1 -1
- package/build/matrices/decompositions.js +87 -89
- package/build/matrices/decompositions.js.map +1 -1
- package/build/matrices/index.d.ts +3 -2
- package/build/matrices/index.d.ts.map +1 -1
- package/build/matrices/index.js +5 -2
- package/build/matrices/index.js.map +1 -1
- package/build/matrices/linear-algebra.d.ts +12 -12
- package/build/matrices/linear-algebra.js +4 -4
- package/build/matrices/normalization.d.ts +8 -8
- package/build/matrices/transformations.d.ts +184 -165
- package/build/matrices/transformations.d.ts.map +1 -1
- package/build/matrices/transformations.js +99 -80
- package/build/matrices/transformations.js.map +1 -1
- package/build/matrices/types.d.ts +12 -12
- package/build/matrices/types.d.ts.map +1 -1
- package/build/quaternions/_exports.d.ts +11 -0
- package/build/quaternions/_exports.d.ts.map +1 -0
- package/build/quaternions/_exports.js +11 -0
- package/build/quaternions/_exports.js.map +1 -0
- package/build/quaternions/asserts.d.ts +115 -7
- package/build/quaternions/asserts.d.ts.map +1 -1
- package/build/quaternions/asserts.js +162 -8
- package/build/quaternions/asserts.js.map +1 -1
- package/build/quaternions/conversions.d.ts +31 -21
- package/build/quaternions/conversions.d.ts.map +1 -1
- package/build/quaternions/conversions.js +28 -18
- package/build/quaternions/conversions.js.map +1 -1
- package/build/quaternions/core.d.ts +67 -39
- package/build/quaternions/core.d.ts.map +1 -1
- package/build/quaternions/core.js +67 -39
- package/build/quaternions/core.js.map +1 -1
- package/build/quaternions/index.d.ts +3 -2
- package/build/quaternions/index.d.ts.map +1 -1
- package/build/quaternions/index.js +5 -2
- package/build/quaternions/index.js.map +1 -1
- package/build/quaternions/interpolation.d.ts +15 -9
- package/build/quaternions/interpolation.d.ts.map +1 -1
- package/build/quaternions/interpolation.js +15 -9
- package/build/quaternions/interpolation.js.map +1 -1
- package/build/quaternions/predefined.d.ts +9 -3
- package/build/quaternions/predefined.d.ts.map +1 -1
- package/build/quaternions/predefined.js +9 -3
- package/build/quaternions/predefined.js.map +1 -1
- package/build/quaternions/types.d.ts +3 -3
- package/build/vectors/_exports.d.ts +10 -0
- package/build/vectors/_exports.d.ts.map +1 -0
- package/build/vectors/_exports.js +10 -0
- package/build/vectors/_exports.js.map +1 -0
- package/build/vectors/asserts.d.ts +153 -49
- package/build/vectors/asserts.d.ts.map +1 -1
- package/build/vectors/asserts.js +202 -52
- package/build/vectors/asserts.js.map +1 -1
- package/build/vectors/core.d.ts +216 -137
- package/build/vectors/core.d.ts.map +1 -1
- package/build/vectors/core.js +212 -149
- package/build/vectors/core.js.map +1 -1
- package/build/vectors/index.d.ts +1 -0
- package/build/vectors/index.d.ts.map +1 -1
- package/build/vectors/index.js +3 -0
- package/build/vectors/index.js.map +1 -1
- package/build/vectors/interpolation.d.ts +39 -27
- package/build/vectors/interpolation.d.ts.map +1 -1
- package/build/vectors/interpolation.js +39 -27
- package/build/vectors/interpolation.js.map +1 -1
- package/build/vectors/predefined.d.ts +48 -24
- package/build/vectors/predefined.d.ts.map +1 -1
- package/build/vectors/predefined.js +38 -18
- package/build/vectors/predefined.js.map +1 -1
- package/package.json +3 -3
|
@@ -8,8 +8,16 @@ import { AssertVector, VectorError } from '../vectors/asserts.js';
|
|
|
8
8
|
* Extends the base VectorError to maintain consistency with vector operations.
|
|
9
9
|
*/
|
|
10
10
|
export class QuaternionError extends VectorError {
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
code = 'QUATERNION_ERROR';
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new QuaternionError instance.
|
|
14
|
+
*
|
|
15
|
+
* @param message - Error message describing the validation failure
|
|
16
|
+
* @param options - Optional error context
|
|
17
|
+
* @param options.cause - Original error that caused this error
|
|
18
|
+
*/
|
|
19
|
+
constructor(message, options) {
|
|
20
|
+
super(message, options);
|
|
13
21
|
this.name = 'QuaternionError';
|
|
14
22
|
}
|
|
15
23
|
}
|
|
@@ -22,9 +30,11 @@ export class QuaternionError extends VectorError {
|
|
|
22
30
|
* @throws {QuaternionError} If the quaternion is invalid
|
|
23
31
|
*
|
|
24
32
|
* @example
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
33
|
+
* ```typescript
|
|
34
|
+
* AssertQuaternion([0, 0, 0, 1]); // Valid - passes silently
|
|
35
|
+
* AssertQuaternion([1, 2, 3]); // Throws QuaternionError - wrong length
|
|
36
|
+
* AssertQuaternion([1, 2, 3, NaN]); // Throws QuaternionError - contains NaN
|
|
37
|
+
* ```
|
|
28
38
|
*/
|
|
29
39
|
export function AssertQuaternion(quaternion, options = {}) {
|
|
30
40
|
if (!Array.isArray(quaternion)) {
|
|
@@ -53,8 +63,10 @@ export function AssertQuaternion(quaternion, options = {}) {
|
|
|
53
63
|
* @throws {QuaternionError} If the quaternion is not normalized
|
|
54
64
|
*
|
|
55
65
|
* @example
|
|
56
|
-
|
|
57
|
-
|
|
66
|
+
* ```typescript
|
|
67
|
+
* AssertNormalizedQuaternion([0, 0, 0, 1]); // Valid unit quaternion
|
|
68
|
+
* AssertNormalizedQuaternion([1, 1, 1, 1]); // Throws - not normalized
|
|
69
|
+
* ```
|
|
58
70
|
*/
|
|
59
71
|
export function AssertNormalizedQuaternion(quaternion, tolerance = 1e-6) {
|
|
60
72
|
AssertQuaternion(quaternion);
|
|
@@ -116,7 +128,7 @@ export function AssertAxisAngle(axisAngle, options = {}) {
|
|
|
116
128
|
}
|
|
117
129
|
/**
|
|
118
130
|
* Validates that a value is a proper rotation matrix.
|
|
119
|
-
* Rotation matrix must be a 3x3 matrix (
|
|
131
|
+
* Rotation matrix must be a 3x3 matrix (TMatrix3).
|
|
120
132
|
*
|
|
121
133
|
* @param matrix - The value to validate as a rotation matrix
|
|
122
134
|
* @param options - Validation options
|
|
@@ -172,4 +184,146 @@ export function AssertQuaternions(quaternions, options = {}) {
|
|
|
172
184
|
}
|
|
173
185
|
}
|
|
174
186
|
}
|
|
187
|
+
/**
|
|
188
|
+
* Validates that an unknown value is a valid quaternion without throwing an error.
|
|
189
|
+
*
|
|
190
|
+
* This function performs the same validation as AssertQuaternion but returns
|
|
191
|
+
* a boolean instead of throwing an exception, making it suitable for
|
|
192
|
+
* conditional logic where exceptions are not desired.
|
|
193
|
+
*
|
|
194
|
+
* @param quaternion - The value to validate as a quaternion
|
|
195
|
+
* @param options - Validation options
|
|
196
|
+
* @returns true if the quaternion is valid, false otherwise
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```typescript
|
|
200
|
+
* if (ValidateQuaternion(someValue)) {
|
|
201
|
+
* // Process the valid quaternion
|
|
202
|
+
* }
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
export function ValidateQuaternion(quaternion, options = {}) {
|
|
206
|
+
try {
|
|
207
|
+
AssertQuaternion(quaternion, options);
|
|
208
|
+
return true;
|
|
209
|
+
}
|
|
210
|
+
catch {
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Validates that a quaternion is normalized (magnitude = 1) without throwing an error.
|
|
216
|
+
*
|
|
217
|
+
* @param quaternion - The quaternion to validate as normalized
|
|
218
|
+
* @param tolerance - Maximum allowed deviation from unit magnitude (default: 1e-6)
|
|
219
|
+
* @returns true if the quaternion is normalized, false otherwise
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* ```typescript
|
|
223
|
+
* if (ValidateNormalizedQuaternion([1, 0, 0, 0])) {
|
|
224
|
+
* // Process the normalized quaternion
|
|
225
|
+
* }
|
|
226
|
+
* ```
|
|
227
|
+
*/
|
|
228
|
+
export function ValidateNormalizedQuaternion(quaternion, tolerance = 1e-6) {
|
|
229
|
+
try {
|
|
230
|
+
AssertNormalizedQuaternion(quaternion, tolerance);
|
|
231
|
+
return true;
|
|
232
|
+
}
|
|
233
|
+
catch {
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Validates that an unknown value is valid Euler angles without throwing an error.
|
|
239
|
+
*
|
|
240
|
+
* @param euler - The value to validate as Euler angles
|
|
241
|
+
* @param options - Validation options
|
|
242
|
+
* @returns true if the Euler angles are valid, false otherwise
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* ```typescript
|
|
246
|
+
* if (ValidateEulerAngles([0.5, 1.0, 1.5])) {
|
|
247
|
+
* // Process the valid Euler angles
|
|
248
|
+
* }
|
|
249
|
+
* ```
|
|
250
|
+
*/
|
|
251
|
+
export function ValidateEulerAngles(euler, options = {}) {
|
|
252
|
+
try {
|
|
253
|
+
AssertEulerAngles(euler, options);
|
|
254
|
+
return true;
|
|
255
|
+
}
|
|
256
|
+
catch {
|
|
257
|
+
return false;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Validates that an unknown value is a valid axis-angle representation without throwing an error.
|
|
262
|
+
*
|
|
263
|
+
* @param axisAngle - The value to validate as axis-angle
|
|
264
|
+
* @param options - Validation options
|
|
265
|
+
* @returns true if the axis-angle is valid, false otherwise
|
|
266
|
+
*
|
|
267
|
+
* @example
|
|
268
|
+
* ```typescript
|
|
269
|
+
* if (ValidateAxisAngle({ axis: [0, 0, 1], angle: Math.PI / 2 })) {
|
|
270
|
+
* // Process the valid axis-angle
|
|
271
|
+
* }
|
|
272
|
+
* ```
|
|
273
|
+
*/
|
|
274
|
+
export function ValidateAxisAngle(axisAngle, options = {}) {
|
|
275
|
+
try {
|
|
276
|
+
AssertAxisAngle(axisAngle, options);
|
|
277
|
+
return true;
|
|
278
|
+
}
|
|
279
|
+
catch {
|
|
280
|
+
return false;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Validates that an unknown value is a valid rotation matrix without throwing an error.
|
|
285
|
+
*
|
|
286
|
+
* @param matrix - The value to validate as a rotation matrix
|
|
287
|
+
* @param options - Validation options
|
|
288
|
+
* @returns true if the matrix is a valid rotation matrix, false otherwise
|
|
289
|
+
*
|
|
290
|
+
* @example
|
|
291
|
+
* ```typescript
|
|
292
|
+
* if (ValidateRotationMatrix(someValue)) {
|
|
293
|
+
* // Process the valid rotation matrix
|
|
294
|
+
* }
|
|
295
|
+
* ```
|
|
296
|
+
*/
|
|
297
|
+
export function ValidateRotationMatrix(matrix, options = {}) {
|
|
298
|
+
try {
|
|
299
|
+
AssertRotationMatrix(matrix, options);
|
|
300
|
+
return true;
|
|
301
|
+
}
|
|
302
|
+
catch {
|
|
303
|
+
return false;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Validates that an unknown value is an array of valid quaternions without throwing an error.
|
|
308
|
+
*
|
|
309
|
+
* @param quaternions - The value to validate as an array of quaternions
|
|
310
|
+
* @param options - Validation options
|
|
311
|
+
* @returns true if all quaternions are valid, false otherwise
|
|
312
|
+
*
|
|
313
|
+
* @example
|
|
314
|
+
* ```typescript
|
|
315
|
+
* if (ValidateQuaternions([q1, q2, q3])) {
|
|
316
|
+
* // Process the valid quaternion array
|
|
317
|
+
* }
|
|
318
|
+
* ```
|
|
319
|
+
*/
|
|
320
|
+
export function ValidateQuaternions(quaternions, options = {}) {
|
|
321
|
+
try {
|
|
322
|
+
AssertQuaternions(quaternions, options);
|
|
323
|
+
return true;
|
|
324
|
+
}
|
|
325
|
+
catch {
|
|
326
|
+
return false;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
175
329
|
//# sourceMappingURL=asserts.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asserts.js","sourceRoot":"","sources":["../../src/quaternions/asserts.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGlE;;;GAGG;AACH,MAAM,OAAO,eAAgB,SAAQ,WAAW;IAC/
|
|
1
|
+
{"version":3,"file":"asserts.js","sourceRoot":"","sources":["../../src/quaternions/asserts.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGlE;;;GAGG;AACH,MAAM,OAAO,eAAgB,SAAQ,WAAW;IAC/B,IAAI,GAAW,kBAAkB,CAAC;IAElD;;;;;;OAMG;IACH,YAAY,OAAe,EAAE,OAA6B;QACzD,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAC/B,CAAC;CACD;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,gBAAgB,CAAC,UAAmB,EAAE,UAAmC,EAAE;IAC1F,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QAChC,MAAM,IAAI,eAAe,CAAC,6BAA6B,CAAC,CAAC;IA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C,CAAC;QACpC,OAAO,IAAI,CAAC;IACb,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,KAAK,CAAC;IACd,CAAC;AACF,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,sBAAsB,CAAC,MAAe,EAAE,UAAmC,EAAE;IAC5F,IAAI,CAAC;QACJ,oBAAoB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACtC,OAAO,IAAI,CAAC;IACb,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,KAAK,CAAC;IACd,CAAC;AACF,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,mBAAmB,CAAC,WAAsB,EAAE,UAAmC,EAAE;IAChG,IAAI,CAAC;QACJ,iBAAiB,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;QACxC,OAAO,IAAI,CAAC;IACb,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,KAAK,CAAC;IACd,CAAC;AACF,CAAC"}
|
|
@@ -2,32 +2,36 @@
|
|
|
2
2
|
* Conversion utilities for quaternions and various rotation representations.
|
|
3
3
|
* Provides comprehensive conversion between different rotation formats.
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
5
|
+
import { TMatrix4 } from '../matrices/types.js';
|
|
6
6
|
import { TQuaternion, TRotationMatrix } from './types.js';
|
|
7
7
|
/**
|
|
8
8
|
* Converts a quaternion to a 3x3 rotation matrix.
|
|
9
|
-
* The matrix is returned as a proper
|
|
9
|
+
* The matrix is returned as a proper TMatrix3 type.
|
|
10
10
|
*
|
|
11
11
|
* @param quaternion - The normalized quaternion to convert
|
|
12
|
-
* @returns 3x3 rotation matrix as
|
|
12
|
+
* @returns 3x3 rotation matrix as TMatrix3
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const q = [0, 0, 0.707, 0.707]; // 90° rotation around Z-axis
|
|
17
|
+
* const matrix = QuaternionToRotationMatrix(q);
|
|
18
|
+
* // matrix represents rotation that transforms +X to +Y
|
|
19
|
+
* ```
|
|
18
20
|
*/
|
|
19
21
|
export declare function QuaternionToRotationMatrix(quaternion: TQuaternion): TRotationMatrix;
|
|
20
22
|
/**
|
|
21
23
|
* Converts a 3x3 rotation matrix to a quaternion.
|
|
22
|
-
* The matrix should be a proper
|
|
24
|
+
* The matrix should be a proper TMatrix3 type.
|
|
23
25
|
*
|
|
24
|
-
* @param matrix - 3x3 rotation matrix as
|
|
26
|
+
* @param matrix - 3x3 rotation matrix as TMatrix3
|
|
25
27
|
* @returns Normalized quaternion representing the same rotation
|
|
26
28
|
*
|
|
27
29
|
* @example
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const identityMatrix = [[1, 0, 0], [0, 1, 0], [0, 0, 1]];
|
|
32
|
+
* const q = QuaternionFromRotationMatrix(identityMatrix);
|
|
33
|
+
* console.log(q); // [0, 0, 0, 1] (identity quaternion)
|
|
34
|
+
* ```
|
|
31
35
|
*/
|
|
32
36
|
export declare function QuaternionFromRotationMatrix(matrix: TRotationMatrix): TQuaternion;
|
|
33
37
|
/**
|
|
@@ -39,11 +43,13 @@ export declare function QuaternionFromRotationMatrix(matrix: TRotationMatrix): T
|
|
|
39
43
|
* @returns 4x4 transformation matrix as a flat array of 16 elements (row-major)
|
|
40
44
|
*
|
|
41
45
|
* @example
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
46
|
+
* ```typescript
|
|
47
|
+
* const q = [0, 0, 0, 1]; // Identity quaternion
|
|
48
|
+
* const matrix4x4 = QuaternionToTransformationMatrix(q);
|
|
49
|
+
* // Returns identity 4x4 matrix
|
|
50
|
+
* ```
|
|
45
51
|
*/
|
|
46
|
-
export declare function QuaternionToTransformationMatrix(quaternion: TQuaternion):
|
|
52
|
+
export declare function QuaternionToTransformationMatrix(quaternion: TQuaternion): TMatrix4;
|
|
47
53
|
/**
|
|
48
54
|
* Extracts the rotation quaternion from a 4x4 transformation matrix.
|
|
49
55
|
* Ignores translation and scaling components, extracting only the rotation.
|
|
@@ -52,11 +58,13 @@ export declare function QuaternionToTransformationMatrix(quaternion: TQuaternion
|
|
|
52
58
|
* @returns Normalized quaternion representing the rotation component
|
|
53
59
|
*
|
|
54
60
|
* @example
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
61
|
+
* ```typescript
|
|
62
|
+
* const transformMatrix = [1, 0, 0, 5, 0, 1, 0, 10, 0, 0, 1, 15, 0, 0, 0, 1];
|
|
63
|
+
* const q = QuaternionFromTransformationMatrix(transformMatrix);
|
|
64
|
+
* // Extracts rotation (identity in this case), ignores translation [5, 10, 15]
|
|
65
|
+
* ```
|
|
58
66
|
*/
|
|
59
|
-
export declare function QuaternionFromTransformationMatrix(matrix:
|
|
67
|
+
export declare function QuaternionFromTransformationMatrix(matrix: TMatrix4): TQuaternion;
|
|
60
68
|
/**
|
|
61
69
|
* Checks if a matrix is a valid rotation matrix.
|
|
62
70
|
* A valid rotation matrix should be orthogonal and have determinant +1.
|
|
@@ -66,8 +74,10 @@ export declare function QuaternionFromTransformationMatrix(matrix: IMatrix4): TQ
|
|
|
66
74
|
* @returns True if the matrix is a valid rotation matrix
|
|
67
75
|
*
|
|
68
76
|
* @example
|
|
69
|
-
|
|
70
|
-
|
|
77
|
+
* ```typescript
|
|
78
|
+
* const matrix = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]; // Identity matrix
|
|
79
|
+
* console.log(IsValidRotationMatrix(matrix)); // true
|
|
80
|
+
* ```
|
|
71
81
|
*/
|
|
72
82
|
export declare function IsValidRotationMatrix(matrix: TRotationMatrix, tolerance?: number): boolean;
|
|
73
83
|
//# sourceMappingURL=conversions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversions.d.ts","sourceRoot":"","sources":["../../src/quaternions/conversions.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAI1D
|
|
1
|
+
{"version":3,"file":"conversions.d.ts","sourceRoot":"","sources":["../../src/quaternions/conversions.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAI1D;;;;;;;;;;;;;GAaG;AACH,wBAAgB,0BAA0B,CAAC,UAAU,EAAE,WAAW,GAAG,eAAe,CAmBnF;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,eAAe,GAAG,WAAW,CAyCjF;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gCAAgC,CAAC,UAAU,EAAE,WAAW,GAAG,QAAQ,CAUlF;AACD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kCAAkC,CAAC,MAAM,EAAE,QAAQ,GAAG,WAAW,CAShF;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,eAAe,EAAE,SAAS,GAAE,MAAa,GAAG,OAAO,CAkChG"}
|
|
@@ -6,15 +6,17 @@ import { AssertNormalizedQuaternion, AssertRotationMatrix } from './asserts.js';
|
|
|
6
6
|
const SHEPPERD_QUARTER = 0.25;
|
|
7
7
|
/**
|
|
8
8
|
* Converts a quaternion to a 3x3 rotation matrix.
|
|
9
|
-
* The matrix is returned as a proper
|
|
9
|
+
* The matrix is returned as a proper TMatrix3 type.
|
|
10
10
|
*
|
|
11
11
|
* @param quaternion - The normalized quaternion to convert
|
|
12
|
-
* @returns 3x3 rotation matrix as
|
|
12
|
+
* @returns 3x3 rotation matrix as TMatrix3
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const q = [0, 0, 0.707, 0.707]; // 90° rotation around Z-axis
|
|
17
|
+
* const matrix = QuaternionToRotationMatrix(q);
|
|
18
|
+
* // matrix represents rotation that transforms +X to +Y
|
|
19
|
+
* ```
|
|
18
20
|
*/
|
|
19
21
|
export function QuaternionToRotationMatrix(quaternion) {
|
|
20
22
|
AssertNormalizedQuaternion(quaternion);
|
|
@@ -36,15 +38,17 @@ export function QuaternionToRotationMatrix(quaternion) {
|
|
|
36
38
|
}
|
|
37
39
|
/**
|
|
38
40
|
* Converts a 3x3 rotation matrix to a quaternion.
|
|
39
|
-
* The matrix should be a proper
|
|
41
|
+
* The matrix should be a proper TMatrix3 type.
|
|
40
42
|
*
|
|
41
|
-
* @param matrix - 3x3 rotation matrix as
|
|
43
|
+
* @param matrix - 3x3 rotation matrix as TMatrix3
|
|
42
44
|
* @returns Normalized quaternion representing the same rotation
|
|
43
45
|
*
|
|
44
46
|
* @example
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
* ```typescript
|
|
48
|
+
* const identityMatrix = [[1, 0, 0], [0, 1, 0], [0, 0, 1]];
|
|
49
|
+
* const q = QuaternionFromRotationMatrix(identityMatrix);
|
|
50
|
+
* console.log(q); // [0, 0, 0, 1] (identity quaternion)
|
|
51
|
+
* ```
|
|
48
52
|
*/
|
|
49
53
|
export function QuaternionFromRotationMatrix(matrix) {
|
|
50
54
|
AssertRotationMatrix(matrix);
|
|
@@ -97,9 +101,11 @@ export function QuaternionFromRotationMatrix(matrix) {
|
|
|
97
101
|
* @returns 4x4 transformation matrix as a flat array of 16 elements (row-major)
|
|
98
102
|
*
|
|
99
103
|
* @example
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
104
|
+
* ```typescript
|
|
105
|
+
* const q = [0, 0, 0, 1]; // Identity quaternion
|
|
106
|
+
* const matrix4x4 = QuaternionToTransformationMatrix(q);
|
|
107
|
+
* // Returns identity 4x4 matrix
|
|
108
|
+
* ```
|
|
103
109
|
*/
|
|
104
110
|
export function QuaternionToTransformationMatrix(quaternion) {
|
|
105
111
|
const rotationMatrix = QuaternionToRotationMatrix(quaternion);
|
|
@@ -119,9 +125,11 @@ export function QuaternionToTransformationMatrix(quaternion) {
|
|
|
119
125
|
* @returns Normalized quaternion representing the rotation component
|
|
120
126
|
*
|
|
121
127
|
* @example
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
128
|
+
* ```typescript
|
|
129
|
+
* const transformMatrix = [1, 0, 0, 5, 0, 1, 0, 10, 0, 0, 1, 15, 0, 0, 0, 1];
|
|
130
|
+
* const q = QuaternionFromTransformationMatrix(transformMatrix);
|
|
131
|
+
* // Extracts rotation (identity in this case), ignores translation [5, 10, 15]
|
|
132
|
+
* ```
|
|
125
133
|
*/
|
|
126
134
|
export function QuaternionFromTransformationMatrix(matrix) {
|
|
127
135
|
// Extract 3x3 rotation matrix from 4x4 transformation matrix
|
|
@@ -141,8 +149,10 @@ export function QuaternionFromTransformationMatrix(matrix) {
|
|
|
141
149
|
* @returns True if the matrix is a valid rotation matrix
|
|
142
150
|
*
|
|
143
151
|
* @example
|
|
144
|
-
|
|
145
|
-
|
|
152
|
+
* ```typescript
|
|
153
|
+
* const matrix = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]; // Identity matrix
|
|
154
|
+
* console.log(IsValidRotationMatrix(matrix)); // true
|
|
155
|
+
* ```
|
|
146
156
|
*/
|
|
147
157
|
export function IsValidRotationMatrix(matrix, tolerance = 1e-6) {
|
|
148
158
|
AssertRotationMatrix(matrix);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversions.js","sourceRoot":"","sources":["../../src/quaternions/conversions.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,0BAA0B,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAGhF,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAE9B
|
|
1
|
+
{"version":3,"file":"conversions.js","sour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,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,SAAS;QAAE,OAAO,KAAK,CAAC;IAEhD,OAAO,IAAI,CAAC;AACb,CAAC"}
|
|
@@ -11,8 +11,10 @@ import { TQuaternion, TEulerAngles, TAxisAngle } from './types.js';
|
|
|
11
11
|
* @returns Identity quaternion [0, 0, 0, 1]
|
|
12
12
|
*
|
|
13
13
|
* @example
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const identity = QuaternionIdentity();
|
|
16
|
+
* console.log(identity); // [0, 0, 0, 1]
|
|
17
|
+
* ```
|
|
16
18
|
*/
|
|
17
19
|
export declare function QuaternionIdentity(): TQuaternion;
|
|
18
20
|
/**
|
|
@@ -23,9 +25,11 @@ export declare function QuaternionIdentity(): TQuaternion;
|
|
|
23
25
|
* @returns A new quaternion with identical components
|
|
24
26
|
*
|
|
25
27
|
* @example
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
* ```typescript
|
|
29
|
+
* const original = [0, 0, 0.707, 0.707];
|
|
30
|
+
* const copy = QuaternionClone(original);
|
|
31
|
+
* copy[0] = 1; // original remains unchanged
|
|
32
|
+
* ```
|
|
29
33
|
*/
|
|
30
34
|
export declare function QuaternionClone(quaternion: TQuaternion): TQuaternion;
|
|
31
35
|
/**
|
|
@@ -40,10 +44,12 @@ export declare function QuaternionClone(quaternion: TQuaternion): TQuaternion;
|
|
|
40
44
|
* @returns True if quaternions are equal within tolerance
|
|
41
45
|
*
|
|
42
46
|
* @example
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
+
* ```typescript
|
|
48
|
+
* const q1 = [0, 0, 0, 1];
|
|
49
|
+
* const q2 = [0, 0, 0, -1];
|
|
50
|
+
* console.log(QuaternionEquals(q1, q2)); // false (different components)
|
|
51
|
+
* console.log(QuaternionEquals(q1, q2, 1e-6, true)); // true (same rotation)
|
|
52
|
+
* ```
|
|
47
53
|
*/
|
|
48
54
|
export declare function QuaternionEquals(a: TQuaternion, b: TQuaternion, tolerance?: number, checkEquivalence?: boolean): boolean;
|
|
49
55
|
/**
|
|
@@ -54,8 +60,10 @@ export declare function QuaternionEquals(a: TQuaternion, b: TQuaternion, toleran
|
|
|
54
60
|
* @returns The magnitude of the quaternion
|
|
55
61
|
*
|
|
56
62
|
* @example
|
|
57
|
-
|
|
58
|
-
|
|
63
|
+
* ```typescript
|
|
64
|
+
* const q = [0, 0, 0, 1];
|
|
65
|
+
* console.log(QuaternionMagnitude(q)); // 1
|
|
66
|
+
* ```
|
|
59
67
|
*/
|
|
60
68
|
export declare function QuaternionMagnitude(quaternion: TQuaternion): number;
|
|
61
69
|
/**
|
|
@@ -66,9 +74,11 @@ export declare function QuaternionMagnitude(quaternion: TQuaternion): number;
|
|
|
66
74
|
* @returns A normalized quaternion with magnitude 1
|
|
67
75
|
*
|
|
68
76
|
* @example
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
77
|
+
* ```typescript
|
|
78
|
+
* const q = [1, 1, 1, 1];
|
|
79
|
+
* const normalized = QuaternionNormalize(q);
|
|
80
|
+
* console.log(QuaternionMagnitude(normalized)); // 1
|
|
81
|
+
* ```
|
|
72
82
|
*/
|
|
73
83
|
export declare function QuaternionNormalize(quaternion: TQuaternion): TQuaternion;
|
|
74
84
|
/**
|
|
@@ -80,9 +90,11 @@ export declare function QuaternionNormalize(quaternion: TQuaternion): TQuaternio
|
|
|
80
90
|
* @returns The conjugate quaternion
|
|
81
91
|
*
|
|
82
92
|
* @example
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
93
|
+
* ```typescript
|
|
94
|
+
* const q = [0.5, 0.5, 0.5, 0.5];
|
|
95
|
+
* const conjugate = QuaternionConjugate(q);
|
|
96
|
+
* console.log(conjugate); // [-0.5, -0.5, -0.5, 0.5]
|
|
97
|
+
* ```
|
|
86
98
|
*/
|
|
87
99
|
export declare function QuaternionConjugate(quaternion: TQuaternion): TQuaternion;
|
|
88
100
|
/**
|
|
@@ -94,8 +106,10 @@ export declare function QuaternionConjugate(quaternion: TQuaternion): TQuaternio
|
|
|
94
106
|
* @returns The inverse quaternion
|
|
95
107
|
*
|
|
96
108
|
* @example
|
|
97
|
-
|
|
98
|
-
|
|
109
|
+
* ```typescript
|
|
110
|
+
* const q = [0, 0, 0.707, 0.707]; // 90° rotation around Z
|
|
111
|
+
* const inverse = QuaternionInverse(q); // -90° rotation around Z
|
|
112
|
+
* ```
|
|
99
113
|
*/
|
|
100
114
|
export declare function QuaternionInverse(quaternion: TQuaternion): TQuaternion;
|
|
101
115
|
/**
|
|
@@ -108,9 +122,11 @@ export declare function QuaternionInverse(quaternion: TQuaternion): TQuaternion;
|
|
|
108
122
|
* @returns The product quaternion representing the combined rotation
|
|
109
123
|
*
|
|
110
124
|
* @example
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
125
|
+
* ```typescript
|
|
126
|
+
* const rotX = QuaternionFromAxisAngle([1, 0, 0], Math.PI/2); // 90° around X
|
|
127
|
+
* const rotY = QuaternionFromAxisAngle([0, 1, 0], Math.PI/2); // 90° around Y
|
|
128
|
+
* const combined = QuaternionMultiply(rotX, rotY); // Y rotation then X rotation
|
|
129
|
+
* ```
|
|
114
130
|
*/
|
|
115
131
|
export declare function QuaternionMultiply(a: TQuaternion, b: TQuaternion): TQuaternion;
|
|
116
132
|
/**
|
|
@@ -122,9 +138,11 @@ export declare function QuaternionMultiply(a: TQuaternion, b: TQuaternion): TQua
|
|
|
122
138
|
* @returns A quaternion representing the rotation
|
|
123
139
|
*
|
|
124
140
|
* @example
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
141
|
+
* ```typescript
|
|
142
|
+
* const axis = [0, 1, 0]; // Y-axis
|
|
143
|
+
* const angle = Math.PI / 2; // 90 degrees
|
|
144
|
+
* const q = QuaternionFromAxisAngle(axis, angle);
|
|
145
|
+
* ```
|
|
128
146
|
*/
|
|
129
147
|
export declare function QuaternionFromAxisAngle(axis: TVector3, angle: number): TQuaternion;
|
|
130
148
|
/**
|
|
@@ -145,9 +163,11 @@ export declare function QuaternionFromAxisAngleVector(axisAngle: TAxisAngle): TQ
|
|
|
145
163
|
* @throws {Error} If the quaternion is not normalized
|
|
146
164
|
*
|
|
147
165
|
* @example
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
166
|
+
* ```typescript
|
|
167
|
+
* const q = [0, 0.707, 0, 0.707]; // 90° around Y-axis
|
|
168
|
+
* const axisAngle = QuaternionToAxisAngle(q);
|
|
169
|
+
* console.log(axisAngle); // [0, 1, 0, π/2]
|
|
170
|
+
* ```
|
|
151
171
|
*/
|
|
152
172
|
export declare function QuaternionToAxisAngle(quaternion: TQuaternion): TAxisAngle;
|
|
153
173
|
/**
|
|
@@ -158,8 +178,10 @@ export declare function QuaternionToAxisAngle(quaternion: TQuaternion): TAxisAng
|
|
|
158
178
|
* @returns A quaternion representing the rotation
|
|
159
179
|
*
|
|
160
180
|
* @example
|
|
161
|
-
|
|
162
|
-
|
|
181
|
+
* ```typescript
|
|
182
|
+
* const euler = [0, Math.PI/4, 0]; // 45° pitch
|
|
183
|
+
* const q = QuaternionFromEuler(euler);
|
|
184
|
+
* ```
|
|
163
185
|
*/
|
|
164
186
|
export declare function QuaternionFromEuler(euler: TEulerAngles): TQuaternion;
|
|
165
187
|
/**
|
|
@@ -170,9 +192,11 @@ export declare function QuaternionFromEuler(euler: TEulerAngles): TQuaternion;
|
|
|
170
192
|
* @returns Euler angles as [x, y, z] in radians
|
|
171
193
|
*
|
|
172
194
|
* @example
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
195
|
+
* ```typescript
|
|
196
|
+
* const q = [0, 0.383, 0, 0.924]; // ~45° around Y-axis
|
|
197
|
+
* const euler = QuaternionToEuler(q);
|
|
198
|
+
* console.log(euler); // [0, π/4, 0]
|
|
199
|
+
* ```
|
|
176
200
|
*/
|
|
177
201
|
export declare function QuaternionToEuler(quaternion: TQuaternion): TEulerAngles;
|
|
178
202
|
/**
|
|
@@ -184,9 +208,11 @@ export declare function QuaternionToEuler(quaternion: TQuaternion): TEulerAngles
|
|
|
184
208
|
* @returns The rotated vector
|
|
185
209
|
*
|
|
186
210
|
* @example
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
211
|
+
* ```typescript
|
|
212
|
+
* const q = QuaternionFromAxisAngle([0, 0, 1], Math.PI/2); // 90° around Z
|
|
213
|
+
* const v = [1, 0, 0]; // Point along X-axis
|
|
214
|
+
* const rotated = QuaternionRotateVector(q, v); // Should point along Y-axis
|
|
215
|
+
* ```
|
|
190
216
|
*/
|
|
191
217
|
export declare function QuaternionRotateVector(quaternion: TQuaternion, vector: TVector3): TVector3;
|
|
192
218
|
/**
|
|
@@ -199,9 +225,11 @@ export declare function QuaternionRotateVector(quaternion: TQuaternion, vector:
|
|
|
199
225
|
* @returns Interpolated quaternion
|
|
200
226
|
*
|
|
201
227
|
* @example
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
228
|
+
* ```typescript
|
|
229
|
+
* const q1 = QuaternionIdentity();
|
|
230
|
+
* const q2 = QuaternionFromAxisAngle([0, 1, 0], Math.PI/2);
|
|
231
|
+
* const halfway = QuaternionSLERP(q1, q2, 0.5); // 45° rotation
|
|
232
|
+
* ```
|
|
205
233
|
*/
|
|
206
234
|
export declare function QuaternionSLERP(a: TQuaternion, b: TQuaternion, t: number): TQuaternion;
|
|
207
235
|
//# sourceMappingURL=core.d.ts.map
|