@ac-kit/math-linear 0.2.1 → 0.4.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/CHANGELOG.md +337 -0
- package/README.md +232 -16
- package/dist/_brand.d.ts +14 -0
- package/dist/_brand.d.ts.map +1 -0
- package/dist/_brand.js +2 -0
- package/dist/_brand.js.map +1 -0
- package/dist/_invert.d.ts +214 -0
- package/dist/_invert.d.ts.map +1 -0
- package/dist/_invert.js +884 -0
- package/dist/_invert.js.map +1 -0
- package/dist/_slerp.d.ts +29 -0
- package/dist/_slerp.d.ts.map +1 -1
- package/dist/_slerp.js +103 -0
- package/dist/_slerp.js.map +1 -1
- package/dist/_strided-range.d.ts +23 -0
- package/dist/_strided-range.d.ts.map +1 -0
- package/dist/_strided-range.js +75 -0
- package/dist/_strided-range.js.map +1 -0
- package/dist/_trs.d.ts +38 -0
- package/dist/_trs.d.ts.map +1 -0
- package/dist/_trs.js +132 -0
- package/dist/_trs.js.map +1 -0
- package/dist/affine2-array.d.ts +53 -0
- package/dist/affine2-array.d.ts.map +1 -0
- package/dist/affine2-array.js +107 -0
- package/dist/affine2-array.js.map +1 -0
- package/dist/affine2-componentwise.d.ts +28 -0
- package/dist/affine2-componentwise.d.ts.map +1 -0
- package/dist/affine2-componentwise.js +66 -0
- package/dist/affine2-componentwise.js.map +1 -0
- package/dist/affine2.d.ts +156 -0
- package/dist/affine2.d.ts.map +1 -0
- package/dist/affine2.js +437 -0
- package/dist/affine2.js.map +1 -0
- package/dist/affine3-array.d.ts +53 -0
- package/dist/affine3-array.d.ts.map +1 -0
- package/dist/affine3-array.js +137 -0
- package/dist/affine3-array.js.map +1 -0
- package/dist/affine3-componentwise.d.ts +32 -0
- package/dist/affine3-componentwise.d.ts.map +1 -0
- package/dist/affine3-componentwise.js +100 -0
- package/dist/affine3-componentwise.js.map +1 -0
- package/dist/affine3.d.ts +205 -0
- package/dist/affine3.d.ts.map +1 -0
- package/dist/affine3.js +792 -0
- package/dist/affine3.js.map +1 -0
- package/dist/checked/index.d.ts +35 -0
- package/dist/checked/index.d.ts.map +1 -0
- package/dist/checked/index.js +58 -0
- package/dist/checked/index.js.map +1 -0
- package/dist/euler.d.ts +65 -0
- package/dist/euler.d.ts.map +1 -0
- package/dist/euler.js +217 -0
- package/dist/euler.js.map +1 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -1
- package/dist/kl-activations.d.ts.map +1 -1
- package/dist/kl-activations.js +4 -3
- package/dist/kl-activations.js.map +1 -1
- package/dist/mat2x2-array.d.ts +36 -0
- package/dist/mat2x2-array.d.ts.map +1 -0
- package/dist/mat2x2-array.js +71 -0
- package/dist/mat2x2-array.js.map +1 -0
- package/dist/mat2x2-componentwise.d.ts +86 -0
- package/dist/mat2x2-componentwise.d.ts.map +1 -0
- package/dist/mat2x2-componentwise.js +199 -0
- package/dist/mat2x2-componentwise.js.map +1 -0
- package/dist/mat2x2.d.ts +79 -25
- package/dist/mat2x2.d.ts.map +1 -1
- package/dist/mat2x2.js +192 -93
- package/dist/mat2x2.js.map +1 -1
- package/dist/mat3x3-array.d.ts +36 -0
- package/dist/mat3x3-array.d.ts.map +1 -0
- package/dist/mat3x3-array.js +91 -0
- package/dist/mat3x3-array.js.map +1 -0
- package/dist/mat3x3-componentwise.d.ts +86 -0
- package/dist/mat3x3-componentwise.d.ts.map +1 -0
- package/dist/mat3x3-componentwise.js +299 -0
- package/dist/mat3x3-componentwise.js.map +1 -0
- package/dist/mat3x3.d.ts +153 -48
- package/dist/mat3x3.d.ts.map +1 -1
- package/dist/mat3x3.js +470 -192
- package/dist/mat3x3.js.map +1 -1
- package/dist/mat4x4-array.d.ts +46 -0
- package/dist/mat4x4-array.d.ts.map +1 -0
- package/dist/mat4x4-array.js +133 -0
- package/dist/mat4x4-array.js.map +1 -0
- package/dist/mat4x4-componentwise.d.ts +87 -0
- package/dist/mat4x4-componentwise.d.ts.map +1 -0
- package/dist/mat4x4-componentwise.js +434 -0
- package/dist/mat4x4-componentwise.js.map +1 -0
- package/dist/mat4x4.d.ts +221 -67
- package/dist/mat4x4.d.ts.map +1 -1
- package/dist/mat4x4.js +972 -334
- package/dist/mat4x4.js.map +1 -1
- package/dist/projection.d.ts +113 -0
- package/dist/projection.d.ts.map +1 -0
- package/dist/projection.js +418 -0
- package/dist/projection.js.map +1 -0
- package/dist/quaternion-array.d.ts +47 -0
- package/dist/quaternion-array.d.ts.map +1 -0
- package/dist/quaternion-array.js +86 -0
- package/dist/quaternion-array.js.map +1 -0
- package/dist/quaternion.d.ts +106 -22
- package/dist/quaternion.d.ts.map +1 -1
- package/dist/quaternion.js +253 -182
- package/dist/quaternion.js.map +1 -1
- package/dist/transform.d.ts +220 -0
- package/dist/transform.d.ts.map +1 -0
- package/dist/transform.js +412 -0
- package/dist/transform.js.map +1 -0
- package/dist/tridiagonal.d.ts +52 -0
- package/dist/tridiagonal.d.ts.map +1 -0
- package/dist/tridiagonal.js +90 -0
- package/dist/tridiagonal.js.map +1 -0
- package/dist/upload.d.ts +55 -0
- package/dist/upload.d.ts.map +1 -0
- package/dist/upload.js +129 -0
- package/dist/upload.js.map +1 -0
- package/dist/vec2-array-componentwise.d.ts +207 -0
- package/dist/vec2-array-componentwise.d.ts.map +1 -0
- package/dist/vec2-array-componentwise.js +472 -0
- package/dist/vec2-array-componentwise.js.map +1 -0
- package/dist/vec2-array.d.ts +53 -0
- package/dist/vec2-array.d.ts.map +1 -0
- package/dist/vec2-array.js +123 -0
- package/dist/vec2-array.js.map +1 -0
- package/dist/vec2-componentwise.d.ts +311 -0
- package/dist/vec2-componentwise.d.ts.map +1 -0
- package/dist/vec2-componentwise.js +542 -0
- package/dist/vec2-componentwise.js.map +1 -0
- package/dist/vec2.d.ts +97 -82
- package/dist/vec2.d.ts.map +1 -1
- package/dist/vec2.js +121 -216
- package/dist/vec2.js.map +1 -1
- package/dist/vec3-array-componentwise.d.ts +207 -0
- package/dist/vec3-array-componentwise.d.ts.map +1 -0
- package/dist/vec3-array-componentwise.js +510 -0
- package/dist/vec3-array-componentwise.js.map +1 -0
- package/dist/vec3-array.d.ts +102 -0
- package/dist/vec3-array.d.ts.map +1 -0
- package/dist/vec3-array.js +299 -0
- package/dist/vec3-array.js.map +1 -0
- package/dist/vec3-componentwise.d.ts +310 -0
- package/dist/vec3-componentwise.d.ts.map +1 -0
- package/dist/vec3-componentwise.js +594 -0
- package/dist/vec3-componentwise.js.map +1 -0
- package/dist/vec3.d.ts +177 -87
- package/dist/vec3.d.ts.map +1 -1
- package/dist/vec3.js +391 -272
- package/dist/vec3.js.map +1 -1
- package/dist/vec4-array-componentwise.d.ts +198 -0
- package/dist/vec4-array-componentwise.d.ts.map +1 -0
- package/dist/vec4-array-componentwise.js +521 -0
- package/dist/vec4-array-componentwise.js.map +1 -0
- package/dist/vec4-array.d.ts +12 -0
- package/dist/vec4-array.d.ts.map +1 -0
- package/dist/vec4-array.js +43 -0
- package/dist/vec4-array.js.map +1 -0
- package/dist/vec4-componentwise.d.ts +299 -0
- package/dist/vec4-componentwise.d.ts.map +1 -0
- package/dist/vec4-componentwise.js +637 -0
- package/dist/vec4-componentwise.js.map +1 -0
- package/dist/vec4.d.ts +59 -53
- package/dist/vec4.d.ts.map +1 -1
- package/dist/vec4.js +74 -249
- package/dist/vec4.js.map +1 -1
- package/dist/view-basis.d.ts +15 -0
- package/dist/view-basis.d.ts.map +1 -0
- package/dist/view-basis.js +29 -0
- package/dist/view-basis.js.map +1 -0
- package/dist/viewport.d.ts +114 -0
- package/dist/viewport.d.ts.map +1 -0
- package/dist/viewport.js +250 -0
- package/dist/viewport.js.map +1 -0
- package/package.json +19 -9
package/dist/quaternion.d.ts
CHANGED
|
@@ -1,23 +1,107 @@
|
|
|
1
|
-
import { type Quaternion } from "@ac-kit/math-complex";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
|
-
export declare function
|
|
16
|
-
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
import { type Quaternion, type ReadonlyQuaternion } from "@ac-kit/math-complex";
|
|
2
|
+
import type { ReadonlyMat3x3 } from "./mat3x3.js";
|
|
3
|
+
import type { ReadonlyMat4x4 } from "./mat4x4.js";
|
|
4
|
+
import { type ReadonlyVec3, type Vec3 } from "./vec3.js";
|
|
5
|
+
export { type Quaternion, quaternionAdd, quaternionClone, quaternionConjugate, quaternionCopy, quaternionCreate, quaternionDot, quaternionEquals, quaternionFromArray, quaternionIdentity, quaternionInvert, quaternionInvertScaled, quaternionIsClose, quaternionIsFinite, quaternionLength, quaternionLengthScaled, quaternionLengthSquared, quaternionMultiply, quaternionMultiplyScalar, quaternionNegate, quaternionNormalize, quaternionNormalizeScaled, quaternionOf, quaternionSet, quaternionSubtract, type ReadonlyQuaternion, } from "@ac-kit/math-complex";
|
|
6
|
+
/**
|
|
7
|
+
* The angle of the rotation of `q`, `2·atan2(|v|, |w|)` with `v` the vector
|
|
8
|
+
* part and `w` the scalar part: in `[0, π]` for `q` and `−q` alike (the same
|
|
9
|
+
* rotation), accurate for small angles where `2·acos(w)` is not, and right for
|
|
10
|
+
* a quaternion that is not unit length, as long as its components are between
|
|
11
|
+
* about `1e-150` and `1e150` (the vector part is squared): the zero quaternion
|
|
12
|
+
* gives `0`, and so does a rotation under about `1e-154` rad, while components
|
|
13
|
+
* beyond about `1e154` overflow to `π`. `NaN` gives `NaN`.
|
|
14
|
+
*/
|
|
15
|
+
export declare function quaternionAngle(q: ReadonlyQuaternion): number;
|
|
16
|
+
/**
|
|
17
|
+
* Writes the axis of the rotation of `q` into `out`: the unit vector `v / |v|`
|
|
18
|
+
* of the vector part, negated when the scalar part is negative so that the pair
|
|
19
|
+
* of this axis and {@link quaternionAngle} (in `[0, π]`) is the rotation of `q`
|
|
20
|
+
* and of `−q` alike. A quaternion with no vector part, the identity, has no
|
|
21
|
+
* axis and gives `[1, 0, 0]`. Accurate at every angle, however small, and for a
|
|
22
|
+
* quaternion that is not unit length. `NaN` gives `NaN`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function quaternionAxis(out: Vec3, q: ReadonlyQuaternion): Vec3;
|
|
25
|
+
/**
|
|
26
|
+
* Writes the rotation by `angle` radians about the unit vector `axis`
|
|
27
|
+
* (right-hand rule) into `out`: `[axis · sin(angle/2), cos(angle/2)]`. `axis`
|
|
28
|
+
* is not normalised here.
|
|
29
|
+
*/
|
|
30
|
+
export declare function quaternionFromAxisAngle(out: Quaternion, axis: ReadonlyVec3, angle: number): Quaternion;
|
|
31
|
+
/**
|
|
32
|
+
* Writes the unit quaternion of a rotation matrix into `out` (Shepperd's
|
|
33
|
+
* method: the largest of the trace and the diagonal entries picks the formula,
|
|
34
|
+
* so the divisor never vanishes). `m` must be orthonormal with a positive
|
|
35
|
+
* determinant; the result is not normalised, and `q` and `−q` are the same
|
|
36
|
+
* rotation.
|
|
37
|
+
*/
|
|
38
|
+
export declare function quaternionFromMat3x3(out: Quaternion, m: ReadonlyMat3x3): Quaternion;
|
|
39
|
+
/**
|
|
40
|
+
* Writes the unit quaternion of the rotation in the upper-left 3 × 3 block of
|
|
41
|
+
* `m` into `out`, as {@link quaternionFromMat3x3}; the translation and the last
|
|
42
|
+
* row are ignored.
|
|
43
|
+
*/
|
|
44
|
+
export declare function quaternionFromMat4x4(out: Quaternion, m: ReadonlyMat4x4): Quaternion;
|
|
45
|
+
/**
|
|
46
|
+
* Writes into `out` the shortest-arc rotation that turns the direction `from`
|
|
47
|
+
* onto the direction `to`. Neither needs to be unit length (they are normalised
|
|
48
|
+
* at any magnitude). Opposite directions, whose shortest arc is not unique,
|
|
49
|
+
* turn by `π` about {@link vec3Perpendicular} of `from`. A zero vector has no
|
|
50
|
+
* direction and gives the identity; `NaN` gives `NaN`. The rotation misses `to`
|
|
51
|
+
* by a few `1e-16` rad except near opposite directions, where no method does
|
|
52
|
+
* better than a few `1e-8` rad.
|
|
53
|
+
*/
|
|
54
|
+
export declare function quaternionFromVec3ToVec3(out: Quaternion, from: ReadonlyVec3, to: ReadonlyVec3): Quaternion;
|
|
55
|
+
/**
|
|
56
|
+
* Writes `q · Rx(angle)` into `out`: the rotation by `angle` radians about the
|
|
57
|
+
* x axis applied first, in the local frame of `q`. `out` may be `q`.
|
|
58
|
+
*/
|
|
59
|
+
export declare function quaternionRotateX(out: Quaternion, q: ReadonlyQuaternion, angle: number): Quaternion;
|
|
60
|
+
/**
|
|
61
|
+
* Writes `q · Ry(angle)` into `out`, as {@link quaternionRotateX} about the y
|
|
62
|
+
* axis. `out` may be `q`.
|
|
63
|
+
*/
|
|
64
|
+
export declare function quaternionRotateY(out: Quaternion, q: ReadonlyQuaternion, angle: number): Quaternion;
|
|
65
|
+
/**
|
|
66
|
+
* Writes `q · Rz(angle)` into `out`, as {@link quaternionRotateX} about the z
|
|
67
|
+
* axis. `out` may be `q`.
|
|
68
|
+
*/
|
|
69
|
+
export declare function quaternionRotateZ(out: Quaternion, q: ReadonlyQuaternion, angle: number): Quaternion;
|
|
70
|
+
/**
|
|
71
|
+
* Writes into `out` the normalised linear interpolation from `a` to `b`, along
|
|
72
|
+
* the shorter arc: `b` is negated first when the two lie in opposite
|
|
73
|
+
* hemispheres (`a · b < 0`, decided exactly where the plain dot product is
|
|
74
|
+
* within its own rounding error), then `a + t·(b − a)` is scaled to unit
|
|
75
|
+
* length. Cheaper than {@link quaternionSlerp} and the same path, but the angle
|
|
76
|
+
* does not grow evenly with `t`, and `t` outside `[0, 1]` extrapolates (the
|
|
77
|
+
* result is right for `|t|` up to about `1e150`, beyond which the normalisation
|
|
78
|
+
* overflows). `out` may be `a` or `b`.
|
|
79
|
+
*/
|
|
80
|
+
export declare function quaternionNlerp(out: Quaternion, a: ReadonlyQuaternion, b: ReadonlyQuaternion, t: number): Quaternion;
|
|
81
|
+
/**
|
|
82
|
+
* Writes into `out` the spherical linear interpolation from `a` to `b` along
|
|
83
|
+
* the shorter arc, at constant angular speed: `t = 0` is `a`, `t = 1` is `b` or
|
|
84
|
+
* `−b` (the same rotation), and `t` outside `[0, 1]` extrapolates along the
|
|
85
|
+
* same arc at the same speed. The hemisphere is decided as in
|
|
86
|
+
* {@link quaternionNlerp}. Both must be unit length. Within `[0, 1]`, where the
|
|
87
|
+
* two are within about `1.8°` of each other, the interpolation is the
|
|
88
|
+
* normalised linear one, the same arc to within `1e-3` rad of parameterisation;
|
|
89
|
+
* elsewhere the arc is evaluated in an orthonormal basis of its plane, `a ·
|
|
90
|
+
* cos(t · θ) + tangent · sin(t · θ)`, whose weights never cancel: a rotation of
|
|
91
|
+
* `1e-16` rad extrapolated to `t = 1e16` lands on the unit quaternion half a
|
|
92
|
+
* radian on. The angle `t · θ` it turns is right to its last digits while `|t ·
|
|
93
|
+
* θ|` is below about `1e15` rad (a sine of a larger angle has none left), and
|
|
94
|
+
* `t` past about `1e150` overflows. `out` may be `a` or `b`.
|
|
95
|
+
*/
|
|
96
|
+
export declare function quaternionSlerp(out: Quaternion, a: ReadonlyQuaternion, b: ReadonlyQuaternion, t: number): Quaternion;
|
|
97
|
+
/**
|
|
98
|
+
* The angle of the rotation that turns `a` into `b`, that of `a⁻¹ · b`, in `[0,
|
|
99
|
+
* π]`: `q` and `−q` count as the same rotation, and the angle is accurate for
|
|
100
|
+
* rotations that nearly coincide where `2·acos(a · b)` is not. Right for
|
|
101
|
+
* quaternions that are not unit length, as long as their components are between
|
|
102
|
+
* about `1e-150` and `1e150` (the products are squared): the angle reads `0`
|
|
103
|
+
* for a rotation under about `1e-154` rad and overflows to `π` beyond about
|
|
104
|
+
* `1e154`. `NaN` gives `NaN`.
|
|
105
|
+
*/
|
|
106
|
+
export declare function quaternionAngleBetween(a: ReadonlyQuaternion, b: ReadonlyQuaternion): number;
|
|
23
107
|
//# sourceMappingURL=quaternion.d.ts.map
|
package/dist/quaternion.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quaternion.d.ts","sourceRoot":"","sources":["../src/quaternion.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,UAAU,
|
|
1
|
+
{"version":3,"file":"quaternion.d.ts","sourceRoot":"","sources":["../src/quaternion.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,UAAU,EAEf,KAAK,kBAAkB,EACvB,MAAM,sBAAsB,CAAC;AAQ9B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AASlD,OAAO,EACN,KAAK,YAAY,EACjB,KAAK,IAAI,EAGT,MAAM,WAAW,CAAC;AAEnB,OAAO,EACN,KAAK,UAAU,EACf,aAAa,EACb,eAAe,EACf,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,EAChB,sBAAsB,EACtB,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,sBAAsB,EACtB,uBAAuB,EACvB,kBAAkB,EAClB,wBAAwB,EACxB,gBAAgB,EAChB,mBAAmB,EACnB,yBAAyB,EACzB,YAAY,EACZ,aAAa,EACb,kBAAkB,EAClB,KAAK,kBAAkB,GACvB,MAAM,sBAAsB,CAAC;AA6B9B;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,kBAAkB,GAAG,MAAM,CAK7D;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE,kBAAkB,GAAG,IAAI,CAYrE;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CACtC,GAAG,EAAE,UAAU,EACf,IAAI,EAAE,YAAY,EAClB,KAAK,EAAE,MAAM,GACX,UAAU,CAQZ;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CACnC,GAAG,EAAE,UAAU,EACf,CAAC,EAAE,cAAc,GACf,UAAU,CAaZ;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CACnC,GAAG,EAAE,UAAU,EACf,CAAC,EAAE,cAAc,GACf,UAAU,CAaZ;AAED;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CACvC,GAAG,EAAE,UAAU,EACf,IAAI,EAAE,YAAY,EAClB,EAAE,EAAE,YAAY,GACd,UAAU,CAoBZ;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAChC,GAAG,EAAE,UAAU,EACf,CAAC,EAAE,kBAAkB,EACrB,KAAK,EAAE,MAAM,GACX,UAAU,CAaZ;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAChC,GAAG,EAAE,UAAU,EACf,CAAC,EAAE,kBAAkB,EACrB,KAAK,EAAE,MAAM,GACX,UAAU,CAaZ;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAChC,GAAG,EAAE,UAAU,EACf,CAAC,EAAE,kBAAkB,EACrB,KAAK,EAAE,MAAM,GACX,UAAU,CAaZ;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAC9B,GAAG,EAAE,UAAU,EACf,CAAC,EAAE,kBAAkB,EACrB,CAAC,EAAE,kBAAkB,EACrB,CAAC,EAAE,MAAM,GACP,UAAU,CAqBZ;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,eAAe,CAC9B,GAAG,EAAE,UAAU,EACf,CAAC,EAAE,kBAAkB,EACrB,CAAC,EAAE,kBAAkB,EACrB,CAAC,EAAE,MAAM,GACP,UAAU,CAyBZ;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CACrC,CAAC,EAAE,kBAAkB,EACrB,CAAC,EAAE,kBAAkB,GACnB,MAAM,CAgBR"}
|
package/dist/quaternion.js
CHANGED
|
@@ -1,208 +1,279 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { SLERP_LINEAR_FALLBACK_DOT_ } from "./_slerp.js";
|
|
3
|
-
import {
|
|
1
|
+
import { quaternionNormalize, } from "@ac-kit/math-complex";
|
|
2
|
+
import { isOppositeHemisphere_, SLERP_LINEAR_FALLBACK_DOT_, slerpArc4_, } from "./_slerp.js";
|
|
3
|
+
import { quaternionFromRotationEntries_ } from "./_trs.js";
|
|
4
|
+
import { vec3Create, vec3Dot, vec3Length, vec3Negate, vec3NormalizeScaled, vec3Set, } from "./vec3-componentwise.js";
|
|
5
|
+
import { vec3Cross, vec3Perpendicular, } from "./vec3.js";
|
|
6
|
+
export { quaternionAdd, quaternionClone, quaternionConjugate, quaternionCopy, quaternionCreate, quaternionDot, quaternionEquals, quaternionFromArray, quaternionIdentity, quaternionInvert, quaternionInvertScaled, quaternionIsClose, quaternionIsFinite, quaternionLength, quaternionLengthScaled, quaternionLengthSquared, quaternionMultiply, quaternionMultiplyScalar, quaternionNegate, quaternionNormalize, quaternionNormalizeScaled, quaternionOf, quaternionSet, quaternionSubtract, } from "@ac-kit/math-complex";
|
|
4
7
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
8
|
+
* The sine of the angle between two directions below which they count as
|
|
9
|
+
* opposite in {@link quaternionFromVec3ToVec3}, which then turns by `π` about a
|
|
10
|
+
* perpendicular of the first instead of building the quaternion `[a×b, 1 +
|
|
11
|
+
* a·b]`.
|
|
7
12
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* So the norm is `√(2(1 + dot))`, which collapses to `0` as `dot → −1`: both
|
|
18
|
-
* the axis and the scalar part vanish together, and normalising divides one
|
|
19
|
-
* near-zero by another. At this margin the norm is still `√(2e-10) ≈ 1.4e-5`,
|
|
20
|
-
* large enough to divide by; past it the anti-parallel branch takes over.
|
|
21
|
-
*
|
|
22
|
-
* In angle, `1 − cos θ ≈ θ²/2`, so the margin corresponds to `θ ≤ √(2e-10) ≈
|
|
23
|
-
* 1.4e-5 rad` of the parallel case and `θ ≥ π − 1.4e-5 rad` of the
|
|
24
|
-
* anti-parallel one.
|
|
25
|
-
*
|
|
26
|
-
* The parallel side is a shortcut rather than a rescue — there the norm tends
|
|
27
|
-
* to `2` and the general formula would return the identity anyway.
|
|
13
|
+
* Near opposite directions the cross product `a×b` has the length `sin θ` but
|
|
14
|
+
* the absolute error of a rounded product, about `1e-16`, so its direction, the
|
|
15
|
+
* axis of the rotation, is off by `1e-16 / sin θ` and the rotation misses `b`
|
|
16
|
+
* by as much: the problem is that ill-conditioned (the shortest arc is not even
|
|
17
|
+
* continuous at `θ = π`). The `π` turn about a perpendicular misses by the
|
|
18
|
+
* angle to `π`, about `sin θ`. The two errors meet at `sin θ ≈ 1e-8`, which
|
|
19
|
+
* bounds the miss at a few `1e-8` rad everywhere; the quaternion is within a
|
|
20
|
+
* few `1e-16` of exact for every other pair, parallel included.
|
|
28
21
|
*
|
|
29
22
|
* Not a tolerance, and deliberately not configurable.
|
|
30
23
|
*/
|
|
31
|
-
const
|
|
24
|
+
const OPPOSITE_MAX_SINE_ = 2e-8;
|
|
32
25
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* That branch tries `a × x̂` first. For unit `a` the length is a sine, `|a ×
|
|
37
|
-
* x̂| = sin φ` with `φ` the angle between `a` and the x-axis, so this bounds `φ
|
|
38
|
-
* ≥ 1e-6 rad`. Below it the cross product has lost its direction and the branch
|
|
39
|
-
* retries against `ŷ`, which cannot also be near-parallel to `a`.
|
|
40
|
-
*
|
|
41
|
-
* Tighter in angle than {@link COLLINEAR_DOT_MARGIN_} despite the larger
|
|
42
|
-
* literal: a sine is linear in the angle where `1 − cos` is quadratic, so
|
|
43
|
-
* `1e-6` here means `1e-6 rad` against the other's `1.4e-5 rad`. The two bound
|
|
44
|
-
* different quantities and their raw values are not comparable.
|
|
26
|
+
* Scratch for {@link quaternionFromVec3ToVec3}: one call at a time, no callback
|
|
27
|
+
* inside it.
|
|
45
28
|
*/
|
|
46
|
-
const
|
|
29
|
+
const FROM_DIRECTION_ = vec3Create();
|
|
30
|
+
const TO_DIRECTION_ = vec3Create();
|
|
31
|
+
const ARC_AXIS_ = vec3Create();
|
|
47
32
|
/**
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* v = [qₓ, qᵧ, q_z] / s
|
|
56
|
-
* ```
|
|
57
|
-
*
|
|
58
|
-
* And the numerator is itself of order `s`, so the quotient degenerates into
|
|
59
|
-
* `0/0` as `θ → 0`. The identity rotation genuinely has no axis, so there is
|
|
60
|
-
* nothing to recover and the function returns an arbitrary one.
|
|
61
|
-
*
|
|
62
|
-
* `θ ≈ 2·asin(1e-3) ≈ 2e-3 rad ≈ 0.115°` — far looser than the two margins
|
|
63
|
-
* above because it protects a direction nobody can observe at that angle, not a
|
|
64
|
-
* quantity fed into further arithmetic.
|
|
33
|
+
* The angle of the rotation of `q`, `2·atan2(|v|, |w|)` with `v` the vector
|
|
34
|
+
* part and `w` the scalar part: in `[0, π]` for `q` and `−q` alike (the same
|
|
35
|
+
* rotation), accurate for small angles where `2·acos(w)` is not, and right for
|
|
36
|
+
* a quaternion that is not unit length, as long as its components are between
|
|
37
|
+
* about `1e-150` and `1e150` (the vector part is squared): the zero quaternion
|
|
38
|
+
* gives `0`, and so does a rotation under about `1e-154` rad, while components
|
|
39
|
+
* beyond about `1e154` overflow to `π`. `NaN` gives `NaN`.
|
|
65
40
|
*/
|
|
66
|
-
const AXIS_MIN_HALF_ANGLE_SINE_ = 0.001;
|
|
67
41
|
export function quaternionAngle(q) {
|
|
68
|
-
|
|
42
|
+
const x = q[0];
|
|
43
|
+
const y = q[1];
|
|
44
|
+
const z = q[2];
|
|
45
|
+
return 2 * Math.atan2(Math.sqrt(x * x + y * y + z * z), Math.abs(q[3]));
|
|
69
46
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
47
|
+
/**
|
|
48
|
+
* Writes the axis of the rotation of `q` into `out`: the unit vector `v / |v|`
|
|
49
|
+
* of the vector part, negated when the scalar part is negative so that the pair
|
|
50
|
+
* of this axis and {@link quaternionAngle} (in `[0, π]`) is the rotation of `q`
|
|
51
|
+
* and of `−q` alike. A quaternion with no vector part, the identity, has no
|
|
52
|
+
* axis and gives `[1, 0, 0]`. Accurate at every angle, however small, and for a
|
|
53
|
+
* quaternion that is not unit length. `NaN` gives `NaN`.
|
|
54
|
+
*/
|
|
55
|
+
export function quaternionAxis(out, q) {
|
|
56
|
+
const x = q[0];
|
|
57
|
+
const y = q[1];
|
|
58
|
+
const z = q[2];
|
|
59
|
+
if (x === 0 && y === 0 && z === 0) {
|
|
60
|
+
out[0] = 1;
|
|
61
|
+
out[1] = 0;
|
|
62
|
+
out[2] = 0;
|
|
63
|
+
return out;
|
|
74
64
|
}
|
|
75
|
-
|
|
65
|
+
vec3NormalizeScaled(vec3Set(out, x, y, z), out);
|
|
66
|
+
return q[3] < 0 ? vec3Negate(out, out) : out;
|
|
76
67
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
68
|
+
/**
|
|
69
|
+
* Writes the rotation by `angle` radians about the unit vector `axis`
|
|
70
|
+
* (right-hand rule) into `out`: `[axis · sin(angle/2), cos(angle/2)]`. `axis`
|
|
71
|
+
* is not normalised here.
|
|
72
|
+
*/
|
|
73
|
+
export function quaternionFromAxisAngle(out, axis, angle) {
|
|
74
|
+
const half = angle / 2;
|
|
75
|
+
const sin = Math.sin(half);
|
|
76
|
+
out[0] = axis[0] * sin;
|
|
77
|
+
out[1] = axis[1] * sin;
|
|
78
|
+
out[2] = axis[2] * sin;
|
|
79
|
+
out[3] = Math.cos(half);
|
|
80
|
+
return out;
|
|
81
81
|
}
|
|
82
|
-
/**
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
z = (m[1][0] - m[0][1]) * s;
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
if (m[0][0] > m[1][1] && m[0][0] > m[2][2]) {
|
|
95
|
-
const s = 2.0 * Math.sqrt(1.0 + m[0][0] - m[1][1] - m[2][2]);
|
|
96
|
-
w = (m[2][1] - m[1][2]) / s;
|
|
97
|
-
x = 0.25 * s;
|
|
98
|
-
y = (m[0][1] + m[1][0]) / s;
|
|
99
|
-
z = (m[0][2] + m[2][0]) / s;
|
|
100
|
-
}
|
|
101
|
-
else if (m[1][1] > m[2][2]) {
|
|
102
|
-
const s = 2.0 * Math.sqrt(1.0 + m[1][1] - m[0][0] - m[2][2]);
|
|
103
|
-
w = (m[0][2] - m[2][0]) / s;
|
|
104
|
-
x = (m[0][1] + m[1][0]) / s;
|
|
105
|
-
y = 0.25 * s;
|
|
106
|
-
z = (m[1][2] + m[2][1]) / s;
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
const s = 2.0 * Math.sqrt(1.0 + m[2][2] - m[0][0] - m[1][1]);
|
|
110
|
-
w = (m[1][0] - m[0][1]) / s;
|
|
111
|
-
x = (m[0][2] + m[2][0]) / s;
|
|
112
|
-
y = (m[1][2] + m[2][1]) / s;
|
|
113
|
-
z = 0.25 * s;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
return [x, y, z, w];
|
|
82
|
+
/**
|
|
83
|
+
* Writes the unit quaternion of a rotation matrix into `out` (Shepperd's
|
|
84
|
+
* method: the largest of the trace and the diagonal entries picks the formula,
|
|
85
|
+
* so the divisor never vanishes). `m` must be orthonormal with a positive
|
|
86
|
+
* determinant; the result is not normalised, and `q` and `−q` are the same
|
|
87
|
+
* rotation.
|
|
88
|
+
*/
|
|
89
|
+
export function quaternionFromMat3x3(out, m) {
|
|
90
|
+
return quaternionFromRotationEntries_(out, m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8]);
|
|
117
91
|
}
|
|
118
92
|
/**
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
93
|
+
* Writes the unit quaternion of the rotation in the upper-left 3 × 3 block of
|
|
94
|
+
* `m` into `out`, as {@link quaternionFromMat3x3}; the translation and the last
|
|
95
|
+
* row are ignored.
|
|
122
96
|
*/
|
|
123
|
-
export function
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
97
|
+
export function quaternionFromMat4x4(out, m) {
|
|
98
|
+
return quaternionFromRotationEntries_(out, m[0], m[1], m[2], m[4], m[5], m[6], m[8], m[9], m[10]);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Writes into `out` the shortest-arc rotation that turns the direction `from`
|
|
102
|
+
* onto the direction `to`. Neither needs to be unit length (they are normalised
|
|
103
|
+
* at any magnitude). Opposite directions, whose shortest arc is not unique,
|
|
104
|
+
* turn by `π` about {@link vec3Perpendicular} of `from`. A zero vector has no
|
|
105
|
+
* direction and gives the identity; `NaN` gives `NaN`. The rotation misses `to`
|
|
106
|
+
* by a few `1e-16` rad except near opposite directions, where no method does
|
|
107
|
+
* better than a few `1e-8` rad.
|
|
108
|
+
*/
|
|
109
|
+
export function quaternionFromVec3ToVec3(out, from, to) {
|
|
110
|
+
vec3NormalizeScaled(FROM_DIRECTION_, from);
|
|
111
|
+
vec3NormalizeScaled(TO_DIRECTION_, to);
|
|
112
|
+
vec3Cross(ARC_AXIS_, FROM_DIRECTION_, TO_DIRECTION_);
|
|
113
|
+
const cosine = vec3Dot(FROM_DIRECTION_, TO_DIRECTION_);
|
|
114
|
+
if (cosine < 0 && vec3Length(ARC_AXIS_) <= OPPOSITE_MAX_SINE_) {
|
|
115
|
+
vec3Perpendicular(ARC_AXIS_, FROM_DIRECTION_);
|
|
116
|
+
out[0] = ARC_AXIS_[0];
|
|
117
|
+
out[1] = ARC_AXIS_[1];
|
|
118
|
+
out[2] = ARC_AXIS_[2];
|
|
119
|
+
out[3] = 0;
|
|
120
|
+
return out;
|
|
138
121
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
122
|
+
// [sin θ · n, 1 + cos θ] is 2·cos(θ/2) times the unit quaternion of the arc,
|
|
123
|
+
// for every θ but π.
|
|
124
|
+
out[0] = ARC_AXIS_[0];
|
|
125
|
+
out[1] = ARC_AXIS_[1];
|
|
126
|
+
out[2] = ARC_AXIS_[2];
|
|
127
|
+
out[3] = 1 + cosine;
|
|
128
|
+
return quaternionNormalize(out, out);
|
|
143
129
|
}
|
|
144
130
|
/**
|
|
145
|
-
*
|
|
146
|
-
*
|
|
131
|
+
* Writes `q · Rx(angle)` into `out`: the rotation by `angle` radians about the
|
|
132
|
+
* x axis applied first, in the local frame of `q`. `out` may be `q`.
|
|
147
133
|
*/
|
|
148
|
-
export function
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
];
|
|
134
|
+
export function quaternionRotateX(out, q, angle) {
|
|
135
|
+
const x = q[0];
|
|
136
|
+
const y = q[1];
|
|
137
|
+
const z = q[2];
|
|
138
|
+
const w = q[3];
|
|
139
|
+
const half = angle / 2;
|
|
140
|
+
const sin = Math.sin(half);
|
|
141
|
+
const cos = Math.cos(half);
|
|
142
|
+
out[0] = x * cos + w * sin;
|
|
143
|
+
out[1] = y * cos + z * sin;
|
|
144
|
+
out[2] = z * cos - y * sin;
|
|
145
|
+
out[3] = w * cos - x * sin;
|
|
146
|
+
return out;
|
|
158
147
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
148
|
+
/**
|
|
149
|
+
* Writes `q · Ry(angle)` into `out`, as {@link quaternionRotateX} about the y
|
|
150
|
+
* axis. `out` may be `q`.
|
|
151
|
+
*/
|
|
152
|
+
export function quaternionRotateY(out, q, angle) {
|
|
153
|
+
const x = q[0];
|
|
154
|
+
const y = q[1];
|
|
155
|
+
const z = q[2];
|
|
156
|
+
const w = q[3];
|
|
157
|
+
const half = angle / 2;
|
|
158
|
+
const sin = Math.sin(half);
|
|
159
|
+
const cos = Math.cos(half);
|
|
160
|
+
out[0] = x * cos - z * sin;
|
|
161
|
+
out[1] = y * cos + w * sin;
|
|
162
|
+
out[2] = z * cos + x * sin;
|
|
163
|
+
out[3] = w * cos - y * sin;
|
|
164
|
+
return out;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Writes `q · Rz(angle)` into `out`, as {@link quaternionRotateX} about the z
|
|
168
|
+
* axis. `out` may be `q`.
|
|
169
|
+
*/
|
|
170
|
+
export function quaternionRotateZ(out, q, angle) {
|
|
171
|
+
const x = q[0];
|
|
172
|
+
const y = q[1];
|
|
173
|
+
const z = q[2];
|
|
174
|
+
const w = q[3];
|
|
175
|
+
const half = angle / 2;
|
|
176
|
+
const sin = Math.sin(half);
|
|
177
|
+
const cos = Math.cos(half);
|
|
178
|
+
out[0] = x * cos + y * sin;
|
|
179
|
+
out[1] = y * cos - x * sin;
|
|
180
|
+
out[2] = z * cos + w * sin;
|
|
181
|
+
out[3] = w * cos - z * sin;
|
|
182
|
+
return out;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Writes into `out` the normalised linear interpolation from `a` to `b`, along
|
|
186
|
+
* the shorter arc: `b` is negated first when the two lie in opposite
|
|
187
|
+
* hemispheres (`a · b < 0`, decided exactly where the plain dot product is
|
|
188
|
+
* within its own rounding error), then `a + t·(b − a)` is scaled to unit
|
|
189
|
+
* length. Cheaper than {@link quaternionSlerp} and the same path, but the angle
|
|
190
|
+
* does not grow evenly with `t`, and `t` outside `[0, 1]` extrapolates (the
|
|
191
|
+
* result is right for `|t|` up to about `1e150`, beyond which the normalisation
|
|
192
|
+
* overflows). `out` may be `a` or `b`.
|
|
193
|
+
*/
|
|
194
|
+
export function quaternionNlerp(out, a, b, t) {
|
|
195
|
+
const ax = a[0];
|
|
196
|
+
const ay = a[1];
|
|
197
|
+
const az = a[2];
|
|
198
|
+
const aw = a[3];
|
|
199
|
+
const side = isOppositeHemisphere_(a, b, ax * b[0] + ay * b[1] + az * b[2] + aw * b[3])
|
|
200
|
+
? -1
|
|
201
|
+
: 1;
|
|
202
|
+
const bx = side * b[0];
|
|
203
|
+
const by = side * b[1];
|
|
204
|
+
const bz = side * b[2];
|
|
205
|
+
const bw = side * b[3];
|
|
206
|
+
out[0] = ax + t * (bx - ax);
|
|
207
|
+
out[1] = ay + t * (by - ay);
|
|
208
|
+
out[2] = az + t * (bz - az);
|
|
209
|
+
out[3] = aw + t * (bw - aw);
|
|
210
|
+
return quaternionNormalize(out, out);
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Writes into `out` the spherical linear interpolation from `a` to `b` along
|
|
214
|
+
* the shorter arc, at constant angular speed: `t = 0` is `a`, `t = 1` is `b` or
|
|
215
|
+
* `−b` (the same rotation), and `t` outside `[0, 1]` extrapolates along the
|
|
216
|
+
* same arc at the same speed. The hemisphere is decided as in
|
|
217
|
+
* {@link quaternionNlerp}. Both must be unit length. Within `[0, 1]`, where the
|
|
218
|
+
* two are within about `1.8°` of each other, the interpolation is the
|
|
219
|
+
* normalised linear one, the same arc to within `1e-3` rad of parameterisation;
|
|
220
|
+
* elsewhere the arc is evaluated in an orthonormal basis of its plane, `a ·
|
|
221
|
+
* cos(t · θ) + tangent · sin(t · θ)`, whose weights never cancel: a rotation of
|
|
222
|
+
* `1e-16` rad extrapolated to `t = 1e16` lands on the unit quaternion half a
|
|
223
|
+
* radian on. The angle `t · θ` it turns is right to its last digits while `|t ·
|
|
224
|
+
* θ|` is below about `1e15` rad (a sine of a larger angle has none left), and
|
|
225
|
+
* `t` past about `1e150` overflows. `out` may be `a` or `b`.
|
|
226
|
+
*/
|
|
227
|
+
export function quaternionSlerp(out, a, b, t) {
|
|
228
|
+
const ax = a[0];
|
|
229
|
+
const ay = a[1];
|
|
230
|
+
const az = a[2];
|
|
231
|
+
const aw = a[3];
|
|
232
|
+
// The cosine of the angle between the two, plain: its magnitude picks the
|
|
233
|
+
// formula and the angle. Its sign picks the hemisphere, which is decided
|
|
234
|
+
// exactly where the plain sum is within its rounding error.
|
|
235
|
+
const plainDot = ax * b[0] + ay * b[1] + az * b[2] + aw * b[3];
|
|
236
|
+
const dot = Math.abs(plainDot);
|
|
237
|
+
const side = isOppositeHemisphere_(a, b, plainDot) ? -1 : 1;
|
|
238
|
+
const bx = side * b[0];
|
|
239
|
+
const by = side * b[1];
|
|
240
|
+
const bz = side * b[2];
|
|
241
|
+
const bw = side * b[3];
|
|
242
|
+
const interpolating = t >= 0 && t <= 1;
|
|
243
|
+
if (interpolating && dot > SLERP_LINEAR_FALLBACK_DOT_) {
|
|
244
|
+
out[0] = ax + t * (bx - ax);
|
|
245
|
+
out[1] = ay + t * (by - ay);
|
|
246
|
+
out[2] = az + t * (bz - az);
|
|
247
|
+
out[3] = aw + t * (bw - aw);
|
|
248
|
+
return quaternionNormalize(out, out);
|
|
175
249
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
const theta = theta_0 * t; // theta = angle between q1 and result
|
|
179
|
-
const sin_theta = Math.sin(theta);
|
|
180
|
-
const sin_theta_0 = Math.sin(theta_0);
|
|
181
|
-
const s1 = Math.cos(theta) - (dot * sin_theta) / sin_theta_0;
|
|
182
|
-
const s2 = sin_theta / sin_theta_0;
|
|
183
|
-
return [
|
|
184
|
-
s1 * q1[0] + s2 * q2[0],
|
|
185
|
-
s1 * q1[1] + s2 * q2[1],
|
|
186
|
-
s1 * q1[2] + s2 * q2[2],
|
|
187
|
-
s1 * q1[3] + s2 * q2[3],
|
|
188
|
-
];
|
|
250
|
+
slerpArc4_(out, ax, ay, az, aw, bx, by, bz, bw, t);
|
|
251
|
+
return out;
|
|
189
252
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
const
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
];
|
|
253
|
+
/**
|
|
254
|
+
* The angle of the rotation that turns `a` into `b`, that of `a⁻¹ · b`, in `[0,
|
|
255
|
+
* π]`: `q` and `−q` count as the same rotation, and the angle is accurate for
|
|
256
|
+
* rotations that nearly coincide where `2·acos(a · b)` is not. Right for
|
|
257
|
+
* quaternions that are not unit length, as long as their components are between
|
|
258
|
+
* about `1e-150` and `1e150` (the products are squared): the angle reads `0`
|
|
259
|
+
* for a rotation under about `1e-154` rad and overflows to `π` beyond about
|
|
260
|
+
* `1e154`. `NaN` gives `NaN`.
|
|
261
|
+
*/
|
|
262
|
+
export function quaternionAngleBetween(a, b) {
|
|
263
|
+
const ax = a[0];
|
|
264
|
+
const ay = a[1];
|
|
265
|
+
const az = a[2];
|
|
266
|
+
const aw = a[3];
|
|
267
|
+
const bx = b[0];
|
|
268
|
+
const by = b[1];
|
|
269
|
+
const bz = b[2];
|
|
270
|
+
const bw = b[3];
|
|
271
|
+
// The conjugate of a times b: the scalar part is a·b, the vector part
|
|
272
|
+
// aw·bv − bw·av − av × bv.
|
|
273
|
+
const w = aw * bw + ax * bx + ay * by + az * bz;
|
|
274
|
+
const x = aw * bx - bw * ax - (ay * bz - az * by);
|
|
275
|
+
const y = aw * by - bw * ay - (az * bx - ax * bz);
|
|
276
|
+
const z = aw * bz - bw * az - (ax * by - ay * bx);
|
|
277
|
+
return 2 * Math.atan2(Math.sqrt(x * x + y * y + z * z), Math.abs(w));
|
|
207
278
|
}
|
|
208
279
|
//# sourceMappingURL=quaternion.js.map
|