math 0.0.0 → 0.1.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/API.md +1605 -0
- package/LICENSE +21 -0
- package/README.md +197 -0
- package/dist/color/color.js +136 -0
- package/dist/color/color.js.map +1 -0
- package/dist/color/colorspace.js +43 -0
- package/dist/color/colorspace.js.map +1 -0
- package/dist/color/hsl.js +123 -0
- package/dist/color/hsl.js.map +1 -0
- package/dist/color/index.js +7 -0
- package/dist/color/index.js.map +1 -0
- package/dist/color/parse.js +276 -0
- package/dist/color/parse.js.map +1 -0
- package/dist/core/angle.js +43 -0
- package/dist/core/angle.js.map +1 -0
- package/dist/core/euler.js +212 -0
- package/dist/core/euler.js.map +1 -0
- package/dist/core/mat2.js +385 -0
- package/dist/core/mat2.js.map +1 -0
- package/dist/core/mat2d.js +422 -0
- package/dist/core/mat2d.js.map +1 -0
- package/dist/core/mat3.js +749 -0
- package/dist/core/mat3.js.map +1 -0
- package/dist/core/mat4.js +2197 -0
- package/dist/core/mat4.js.map +1 -0
- package/dist/core/polar.js +200 -0
- package/dist/core/polar.js.map +1 -0
- package/dist/core/quat.js +730 -0
- package/dist/core/quat.js.map +1 -0
- package/dist/core/quat2.js +883 -0
- package/dist/core/quat2.js.map +1 -0
- package/dist/core/scalar.js +112 -0
- package/dist/core/scalar.js.map +1 -0
- package/dist/core/spherical.js +248 -0
- package/dist/core/spherical.js.map +1 -0
- package/dist/core/vec2.js +597 -0
- package/dist/core/vec2.js.map +1 -0
- package/dist/core/vec3.js +916 -0
- package/dist/core/vec3.js.map +1 -0
- package/dist/core/vec4.js +573 -0
- package/dist/core/vec4.js.map +1 -0
- package/dist/geometry/circumcircle.js +39 -0
- package/dist/geometry/circumcircle.js.map +1 -0
- package/dist/geometry/index.js +6 -0
- package/dist/geometry/index.js.map +1 -0
- package/dist/geometry/polygon2-decompose.js +411 -0
- package/dist/geometry/polygon2-decompose.js.map +1 -0
- package/dist/geometry/polygon2-triangulate.js +222 -0
- package/dist/geometry/polygon2-triangulate.js.map +1 -0
- package/dist/geometry/quickhull2.js +123 -0
- package/dist/geometry/quickhull2.js.map +1 -0
- package/dist/geometry/quickhull3.js +605 -0
- package/dist/geometry/quickhull3.js.map +1 -0
- package/dist/ik/fabrik2.js +675 -0
- package/dist/ik/fabrik2.js.map +1 -0
- package/dist/ik/fabrik3.js +912 -0
- package/dist/ik/fabrik3.js.map +1 -0
- package/dist/ik/index.js +5 -0
- package/dist/ik/index.js.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/noise/fractal.js +185 -0
- package/dist/noise/fractal.js.map +1 -0
- package/dist/noise/index.js +16 -0
- package/dist/noise/index.js.map +1 -0
- package/dist/noise/perlin2d.js +50 -0
- package/dist/noise/perlin2d.js.map +1 -0
- package/dist/noise/perlin3d.js +72 -0
- package/dist/noise/perlin3d.js.map +1 -0
- package/dist/noise/permutation.js +120 -0
- package/dist/noise/permutation.js.map +1 -0
- package/dist/noise/simplex2d.js +84 -0
- package/dist/noise/simplex2d.js.map +1 -0
- package/dist/noise/simplex3d.js +147 -0
- package/dist/noise/simplex3d.js.map +1 -0
- package/dist/noise/simplex4d.js +149 -0
- package/dist/noise/simplex4d.js.map +1 -0
- package/dist/noise/worley2d.js +50 -0
- package/dist/noise/worley2d.js.map +1 -0
- package/dist/noise/worley3d.js +61 -0
- package/dist/noise/worley3d.js.map +1 -0
- package/dist/random/index.js +9 -0
- package/dist/random/index.js.map +1 -0
- package/dist/random/isaac32.js +164 -0
- package/dist/random/isaac32.js.map +1 -0
- package/dist/random/isaac64.js +215 -0
- package/dist/random/isaac64.js.map +1 -0
- package/dist/random/mulberry32.js +48 -0
- package/dist/random/mulberry32.js.map +1 -0
- package/dist/random/random.js +120 -0
- package/dist/random/random.js.map +1 -0
- package/dist/shapes/box2.js +300 -0
- package/dist/shapes/box2.js.map +1 -0
- package/dist/shapes/box3.js +550 -0
- package/dist/shapes/box3.js.map +1 -0
- package/dist/shapes/circle.js +6 -0
- package/dist/shapes/circle.js.map +1 -0
- package/dist/shapes/frustum.js +662 -0
- package/dist/shapes/frustum.js.map +1 -0
- package/dist/shapes/index.js +25 -0
- package/dist/shapes/index.js.map +1 -0
- package/dist/shapes/obb3.js +557 -0
- package/dist/shapes/obb3.js.map +1 -0
- package/dist/shapes/plane3.js +267 -0
- package/dist/shapes/plane3.js.map +1 -0
- package/dist/shapes/polygon2.js +451 -0
- package/dist/shapes/polygon2.js.map +1 -0
- package/dist/shapes/raycast3.js +164 -0
- package/dist/shapes/raycast3.js.map +1 -0
- package/dist/shapes/segment2.js +82 -0
- package/dist/shapes/segment2.js.map +1 -0
- package/dist/shapes/sphere.js +23 -0
- package/dist/shapes/sphere.js.map +1 -0
- package/dist/shapes/triangle2.js +79 -0
- package/dist/shapes/triangle2.js.map +1 -0
- package/dist/shapes/triangle3.js +60 -0
- package/dist/shapes/triangle3.js.map +1 -0
- package/dist/src/color/color.d.ts +50 -0
- package/dist/src/color/colorspace.d.ts +15 -0
- package/dist/src/color/hsl.d.ts +28 -0
- package/dist/src/color/index.d.ts +5 -0
- package/dist/src/color/parse.d.ts +15 -0
- package/dist/src/core/angle.d.ts +29 -0
- package/dist/src/core/arrays.d.ts +4 -0
- package/dist/src/core/euler.d.ts +78 -0
- package/dist/src/core/index.d.ts +27 -0
- package/dist/src/core/mat2.d.ts +217 -0
- package/dist/src/core/mat2d.d.ts +218 -0
- package/dist/src/core/mat3.d.ts +295 -0
- package/dist/src/core/mat4.d.ts +667 -0
- package/dist/src/core/polar.d.ts +151 -0
- package/dist/src/core/quat.d.ts +370 -0
- package/dist/src/core/quat2.d.ts +344 -0
- package/dist/src/core/scalar.d.ts +75 -0
- package/dist/src/core/spherical.d.ts +165 -0
- package/dist/src/core/vec2.d.ts +403 -0
- package/dist/src/core/vec3.d.ts +493 -0
- package/dist/src/core/vec4.d.ts +336 -0
- package/dist/src/geometry/circumcircle.d.ts +9 -0
- package/dist/src/geometry/index.d.ts +5 -0
- package/dist/src/geometry/polygon2-decompose.d.ts +25 -0
- package/dist/src/geometry/polygon2-triangulate.d.ts +15 -0
- package/dist/src/geometry/quickhull2.d.ts +10 -0
- package/dist/src/geometry/quickhull3.d.ts +27 -0
- package/dist/src/ik/fabrik2.d.ts +314 -0
- package/dist/src/ik/fabrik3.d.ts +371 -0
- package/dist/src/ik/index.d.ts +2 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/noise/fractal.d.ts +95 -0
- package/dist/src/noise/index.d.ts +9 -0
- package/dist/src/noise/perlin2d.d.ts +19 -0
- package/dist/src/noise/perlin3d.d.ts +20 -0
- package/dist/src/noise/permutation.d.ts +22 -0
- package/dist/src/noise/simplex2d.d.ts +19 -0
- package/dist/src/noise/simplex3d.d.ts +20 -0
- package/dist/src/noise/simplex4d.d.ts +24 -0
- package/dist/src/noise/worley2d.d.ts +22 -0
- package/dist/src/noise/worley3d.d.ts +23 -0
- package/dist/src/random/index.d.ts +8 -0
- package/dist/src/random/isaac32.d.ts +62 -0
- package/dist/src/random/isaac64.d.ts +75 -0
- package/dist/src/random/mulberry32.d.ts +43 -0
- package/dist/src/random/random.d.ts +67 -0
- package/dist/src/shapes/box2.d.ts +174 -0
- package/dist/src/shapes/box3.d.ts +213 -0
- package/dist/src/shapes/circle.d.ts +7 -0
- package/dist/src/shapes/frustum.d.ts +147 -0
- package/dist/src/shapes/index.d.ts +20 -0
- package/dist/src/shapes/obb3.d.ts +105 -0
- package/dist/src/shapes/plane3.d.ts +130 -0
- package/dist/src/shapes/polygon2.d.ts +155 -0
- package/dist/src/shapes/raycast3.d.ts +42 -0
- package/dist/src/shapes/segment2.d.ts +34 -0
- package/dist/src/shapes/sphere.d.ts +19 -0
- package/dist/src/shapes/triangle2.d.ts +53 -0
- package/dist/src/shapes/triangle3.d.ts +29 -0
- package/dist/src/time/easing.d.ts +21 -0
- package/dist/src/time/index.d.ts +6 -0
- package/dist/src/time/spring-core.d.ts +15 -0
- package/dist/src/time/spring.d.ts +36 -0
- package/dist/src/time/spring2.d.ts +11 -0
- package/dist/src/time/spring3.d.ts +11 -0
- package/dist/src/time/spring4.d.ts +11 -0
- package/dist/time/easing.js +24 -0
- package/dist/time/easing.js.map +1 -0
- package/dist/time/index.js +11 -0
- package/dist/time/index.js.map +1 -0
- package/dist/time/spring-core.js +48 -0
- package/dist/time/spring-core.js.map +1 -0
- package/dist/time/spring.js +62 -0
- package/dist/time/spring.js.map +1 -0
- package/dist/time/spring2.js +31 -0
- package/dist/time/spring2.js.map +1 -0
- package/dist/time/spring3.js +32 -0
- package/dist/time/spring3.js.map +1 -0
- package/dist/time/spring4.js +32 -0
- package/dist/time/spring4.js.map +1 -0
- package/package.json +90 -12
- package/skills/math/SKILL.md +140 -0
- package/math.coffee +0 -36
- package/math.js +0 -67
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
import type { Mat4 } from './mat4.js';
|
|
2
|
+
import type { Quat } from './quat.js';
|
|
3
|
+
import type { Vec3 } from './vec3.js';
|
|
4
|
+
/** A dual quaternion that represents both rotation and translation */
|
|
5
|
+
export type Quat2 = [x: number, y: number, z: number, w: number, x2: number, y2: number, z2: number, w2: number];
|
|
6
|
+
/**
|
|
7
|
+
* Creates a new identity dual quat
|
|
8
|
+
*
|
|
9
|
+
* @returns a new dual quaternion [real -> rotation, dual -> translation]
|
|
10
|
+
*/
|
|
11
|
+
export declare function create(): Quat2;
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new quat initialized with values from an existing quaternion
|
|
14
|
+
*
|
|
15
|
+
* @param a dual quaternion to clone
|
|
16
|
+
* @returns new dual quaternion
|
|
17
|
+
* @function
|
|
18
|
+
*/
|
|
19
|
+
export declare function clone(a: Quat2): Quat2;
|
|
20
|
+
/**
|
|
21
|
+
* Creates a new dual quat initialized with the given values
|
|
22
|
+
*
|
|
23
|
+
* @param x1 X component
|
|
24
|
+
* @param y1 Y component
|
|
25
|
+
* @param z1 Z component
|
|
26
|
+
* @param w1 W component
|
|
27
|
+
* @param x2 X component
|
|
28
|
+
* @param y2 Y component
|
|
29
|
+
* @param z2 Z component
|
|
30
|
+
* @param w2 W component
|
|
31
|
+
* @returns new dual quaternion
|
|
32
|
+
* @function
|
|
33
|
+
*/
|
|
34
|
+
export declare function fromValues(x1: number, y1: number, z1: number, w1: number, x2: number, y2: number, z2: number, w2: number): Quat2;
|
|
35
|
+
/**
|
|
36
|
+
* Creates a new dual quat from the given values (quat and translation)
|
|
37
|
+
*
|
|
38
|
+
* @param x1 X component
|
|
39
|
+
* @param y1 Y component
|
|
40
|
+
* @param z1 Z component
|
|
41
|
+
* @param w1 W component
|
|
42
|
+
* @param x2 X component (translation)
|
|
43
|
+
* @param y2 Y component (translation)
|
|
44
|
+
* @param z2 Z component (translation)
|
|
45
|
+
* @returns new dual quaternion
|
|
46
|
+
* @function
|
|
47
|
+
*/
|
|
48
|
+
export declare function fromRotationTranslationValues(x1: number, y1: number, z1: number, w1: number, x2: number, y2: number, z2: number): Quat2;
|
|
49
|
+
/**
|
|
50
|
+
* Creates a dual quat from a quaternion and a translation
|
|
51
|
+
*
|
|
52
|
+
* @param out dual quaternion receiving operation result
|
|
53
|
+
* @param q a normalized quaternion
|
|
54
|
+
* @param t translation vector
|
|
55
|
+
* @returns dual quaternion receiving operation result
|
|
56
|
+
* @function
|
|
57
|
+
*/
|
|
58
|
+
export declare function fromRotationTranslation(out: Quat2, q: Quat, t: Vec3): Quat2;
|
|
59
|
+
/**
|
|
60
|
+
* Creates a dual quat from a translation
|
|
61
|
+
*
|
|
62
|
+
* @param out dual quaternion receiving operation result
|
|
63
|
+
* @param t translation vector
|
|
64
|
+
* @returns dual quaternion receiving operation result
|
|
65
|
+
* @function
|
|
66
|
+
*/
|
|
67
|
+
export declare function fromTranslation(out: Quat2, t: Vec3): Quat2;
|
|
68
|
+
/**
|
|
69
|
+
* Creates a dual quat from a quaternion
|
|
70
|
+
*
|
|
71
|
+
* @param out dual quaternion receiving operation result
|
|
72
|
+
* @param q the quaternion
|
|
73
|
+
* @returns dual quaternion receiving operation result
|
|
74
|
+
* @function
|
|
75
|
+
*/
|
|
76
|
+
export declare function fromRotation(out: Quat2, q: Quat): Quat2;
|
|
77
|
+
/**
|
|
78
|
+
* Creates a new dual quat from a matrix (4x4)
|
|
79
|
+
*
|
|
80
|
+
* @param out the dual quaternion
|
|
81
|
+
* @param a the matrix
|
|
82
|
+
* @returns dual quat receiving operation result
|
|
83
|
+
*/
|
|
84
|
+
export declare function fromMat4(out: Quat2, a: Mat4): Quat2;
|
|
85
|
+
/**
|
|
86
|
+
* Copy the values from one dual quat to another
|
|
87
|
+
*
|
|
88
|
+
* @param out the receiving dual quaternion
|
|
89
|
+
* @param a the source dual quaternion
|
|
90
|
+
* @returns out
|
|
91
|
+
* @function
|
|
92
|
+
*/
|
|
93
|
+
export declare function copy(out: Quat2, a: Quat2): Quat2;
|
|
94
|
+
/**
|
|
95
|
+
* Set a dual quat to the identity dual quaternion
|
|
96
|
+
*
|
|
97
|
+
* @param out the receiving quaternion
|
|
98
|
+
* @returns out
|
|
99
|
+
*/
|
|
100
|
+
export declare function identity(out: Quat2): Quat2;
|
|
101
|
+
/**
|
|
102
|
+
* Set the components of a dual quat to the given values
|
|
103
|
+
*
|
|
104
|
+
* @param out the receiving quaternion
|
|
105
|
+
* @param x1 X component
|
|
106
|
+
* @param y1 Y component
|
|
107
|
+
* @param z1 Z component
|
|
108
|
+
* @param w1 W component
|
|
109
|
+
* @param x2 X component
|
|
110
|
+
* @param y2 Y component
|
|
111
|
+
* @param z2 Z component
|
|
112
|
+
* @param w2 W component
|
|
113
|
+
* @returns out
|
|
114
|
+
* @function
|
|
115
|
+
*/
|
|
116
|
+
export declare function set(out: Quat2, x1: number, y1: number, z1: number, w1: number, x2: number, y2: number, z2: number, w2: number): Quat2;
|
|
117
|
+
/**
|
|
118
|
+
* Gets the real part of a dual quat
|
|
119
|
+
* @param out real part
|
|
120
|
+
* @param a Dual Quaternion
|
|
121
|
+
* @return real part
|
|
122
|
+
*/
|
|
123
|
+
export declare function getReal(out: Quat, a: Quat2): Quat;
|
|
124
|
+
/**
|
|
125
|
+
* Gets the dual part of a dual quat
|
|
126
|
+
* @param out dual part
|
|
127
|
+
* @param a Dual Quaternion
|
|
128
|
+
* @return dual part
|
|
129
|
+
*/
|
|
130
|
+
export declare function getDual(out: Quat, a: Quat2): Quat;
|
|
131
|
+
/**
|
|
132
|
+
* Set the real component of a dual quat to the given quaternion
|
|
133
|
+
*
|
|
134
|
+
* @param out the receiving dual quaternion
|
|
135
|
+
* @param q a quaternion representing the real part
|
|
136
|
+
* @returns out
|
|
137
|
+
*/
|
|
138
|
+
export declare function setReal(out: Quat2, q: Quat): Quat2;
|
|
139
|
+
/**
|
|
140
|
+
* Set the dual component of a dual quat to the given quaternion
|
|
141
|
+
*
|
|
142
|
+
* @param out the receiving quaternion
|
|
143
|
+
* @param q a quaternion representing the dual part
|
|
144
|
+
* @returns out
|
|
145
|
+
* @function
|
|
146
|
+
*/
|
|
147
|
+
export declare function setDual(out: Quat2, q: Quat): Quat2;
|
|
148
|
+
/**
|
|
149
|
+
* Gets the translation of a normalized dual quat
|
|
150
|
+
* @param out translation
|
|
151
|
+
* @param a Dual Quaternion to be decomposed
|
|
152
|
+
* @return translation
|
|
153
|
+
*/
|
|
154
|
+
export declare function getTranslation(out: Vec3, a: Quat2): Vec3;
|
|
155
|
+
/**
|
|
156
|
+
* Translates a dual quat by the given vector
|
|
157
|
+
*
|
|
158
|
+
* @param out the receiving dual quaternion
|
|
159
|
+
* @param a the dual quaternion to translate
|
|
160
|
+
* @param v vector to translate by
|
|
161
|
+
* @returns out
|
|
162
|
+
*/
|
|
163
|
+
export declare function translate(out: Quat2, a: Quat2, v: Vec3): Quat2;
|
|
164
|
+
/**
|
|
165
|
+
* Rotates a dual quat around the X axis
|
|
166
|
+
*
|
|
167
|
+
* @param out the receiving dual quaternion
|
|
168
|
+
* @param a the dual quaternion to rotate
|
|
169
|
+
* @param rad how far should the rotation be
|
|
170
|
+
* @returns out
|
|
171
|
+
*/
|
|
172
|
+
export declare function rotateX(out: Quat2, a: Quat2, rad: number): Quat2;
|
|
173
|
+
/**
|
|
174
|
+
* Rotates a dual quat around the Y axis
|
|
175
|
+
*
|
|
176
|
+
* @param out the receiving dual quaternion
|
|
177
|
+
* @param a the dual quaternion to rotate
|
|
178
|
+
* @param rad how far should the rotation be
|
|
179
|
+
* @returns out
|
|
180
|
+
*/
|
|
181
|
+
export declare function rotateY(out: Quat2, a: Quat2, rad: number): Quat2;
|
|
182
|
+
/**
|
|
183
|
+
* Rotates a dual quat around the Z axis
|
|
184
|
+
*
|
|
185
|
+
* @param out the receiving dual quaternion
|
|
186
|
+
* @param a the dual quaternion to rotate
|
|
187
|
+
* @param rad how far should the rotation be
|
|
188
|
+
* @returns out
|
|
189
|
+
*/
|
|
190
|
+
export declare function rotateZ(out: Quat2, a: Quat2, rad: number): Quat2;
|
|
191
|
+
/**
|
|
192
|
+
* Rotates a dual quat by a given quaternion (a * q)
|
|
193
|
+
*
|
|
194
|
+
* @param out the receiving dual quaternion
|
|
195
|
+
* @param a the dual quaternion to rotate
|
|
196
|
+
* @param q quaternion to rotate by
|
|
197
|
+
* @returns out
|
|
198
|
+
*/
|
|
199
|
+
export declare function rotateByQuatAppend(out: Quat2, a: Quat2, q: Quat): Quat2;
|
|
200
|
+
/**
|
|
201
|
+
* Rotates a dual quat by a given quaternion (q * a)
|
|
202
|
+
*
|
|
203
|
+
* @param out the receiving dual quaternion
|
|
204
|
+
* @param q quaternion to rotate by
|
|
205
|
+
* @param a the dual quaternion to rotate
|
|
206
|
+
* @returns out
|
|
207
|
+
*/
|
|
208
|
+
export declare function rotateByQuatPrepend(out: Quat2, q: Quat, a: Quat2): Quat2;
|
|
209
|
+
/**
|
|
210
|
+
* Rotates a dual quat around a given axis. Does the normalisation automatically
|
|
211
|
+
*
|
|
212
|
+
* @param out the receiving dual quaternion
|
|
213
|
+
* @param a the dual quaternion to rotate
|
|
214
|
+
* @param axis the axis to rotate around
|
|
215
|
+
* @param rad how far the rotation should be
|
|
216
|
+
* @returns out
|
|
217
|
+
*/
|
|
218
|
+
export declare function rotateAroundAxis(out: Quat2, a: Quat2, axis: Vec3, rad: number): Quat2;
|
|
219
|
+
/**
|
|
220
|
+
* Adds two dual quat's
|
|
221
|
+
*
|
|
222
|
+
* @param out the receiving dual quaternion
|
|
223
|
+
* @param a the first operand
|
|
224
|
+
* @param b the second operand
|
|
225
|
+
* @returns out
|
|
226
|
+
* @function
|
|
227
|
+
*/
|
|
228
|
+
export declare function add(out: Quat2, a: Quat2, b: Quat2): Quat2;
|
|
229
|
+
/**
|
|
230
|
+
* Multiplies two dual quat's
|
|
231
|
+
*
|
|
232
|
+
* @param out the receiving dual quaternion
|
|
233
|
+
* @param a the first operand
|
|
234
|
+
* @param b the second operand
|
|
235
|
+
* @returns out
|
|
236
|
+
*/
|
|
237
|
+
export declare function multiply(out: Quat2, a: Quat2, b: Quat2): Quat2;
|
|
238
|
+
/**
|
|
239
|
+
* Alias for {@link quat2.multiply}
|
|
240
|
+
* @function
|
|
241
|
+
*/
|
|
242
|
+
export declare const mul: typeof multiply;
|
|
243
|
+
/**
|
|
244
|
+
* Scales a dual quat by a scalar number
|
|
245
|
+
*
|
|
246
|
+
* @param out the receiving dual quat
|
|
247
|
+
* @param a the dual quat to scale
|
|
248
|
+
* @param b amount to scale the dual quat by
|
|
249
|
+
* @returns out
|
|
250
|
+
* @function
|
|
251
|
+
*/
|
|
252
|
+
export declare function scale(out: Quat2, a: Quat2, b: number): Quat2;
|
|
253
|
+
/**
|
|
254
|
+
* Calculates the dot product of two dual quat's (The dot product of the real parts)
|
|
255
|
+
*
|
|
256
|
+
* @param a the first operand
|
|
257
|
+
* @param b the second operand
|
|
258
|
+
* @returns dot product of a and b
|
|
259
|
+
*/
|
|
260
|
+
export declare function dot(a: Quat2, b: Quat2): number;
|
|
261
|
+
/**
|
|
262
|
+
* Performs a linear interpolation between two dual quats's
|
|
263
|
+
* NOTE: The resulting dual quaternions won't always be normalized (The error is most noticeable when t = 0.5)
|
|
264
|
+
*
|
|
265
|
+
* @param out the receiving dual quat
|
|
266
|
+
* @param a the first operand
|
|
267
|
+
* @param b the second operand
|
|
268
|
+
* @param t interpolation amount, in the range [0-1], between the two inputs
|
|
269
|
+
* @returns out
|
|
270
|
+
*/
|
|
271
|
+
export declare function lerp(out: Quat2, a: Quat2, b: Quat2, t: number): Quat2;
|
|
272
|
+
/**
|
|
273
|
+
* Calculates the inverse of a dual quat. If they are normalized, conjugate is cheaper
|
|
274
|
+
*
|
|
275
|
+
* @param out the receiving dual quaternion
|
|
276
|
+
* @param a dual quat to calculate inverse of
|
|
277
|
+
* @returns out
|
|
278
|
+
*/
|
|
279
|
+
export declare function invert(out: Quat2, a: Quat2): Quat2;
|
|
280
|
+
/**
|
|
281
|
+
* Calculates the conjugate of a dual quat
|
|
282
|
+
* If the dual quaternion is normalized, this function is faster than quat2.inverse and produces the same result.
|
|
283
|
+
*
|
|
284
|
+
* @param out the receiving quaternion
|
|
285
|
+
* @param a quat to calculate conjugate of
|
|
286
|
+
* @returns out
|
|
287
|
+
*/
|
|
288
|
+
export declare function conjugate(out: Quat2, a: Quat2): Quat2;
|
|
289
|
+
/**
|
|
290
|
+
* Calculates the length of a dual quat (the length of its real/rotation part)
|
|
291
|
+
*
|
|
292
|
+
* @param a dual quat to calculate length of
|
|
293
|
+
* @returns length of a
|
|
294
|
+
*/
|
|
295
|
+
export declare function length(a: Quat2): number;
|
|
296
|
+
/**
|
|
297
|
+
* Alias for {@link quat2.length}
|
|
298
|
+
* @function
|
|
299
|
+
*/
|
|
300
|
+
export declare const len: typeof length;
|
|
301
|
+
/**
|
|
302
|
+
* Calculates the squared length of a dual quat (the squared length of its real/rotation part)
|
|
303
|
+
*
|
|
304
|
+
* @param a dual quat to calculate squared length of
|
|
305
|
+
* @returns squared length of a
|
|
306
|
+
*/
|
|
307
|
+
export declare function squaredLength(a: Quat2): number;
|
|
308
|
+
/**
|
|
309
|
+
* Alias for {@link quat2.squaredLength}
|
|
310
|
+
* @function
|
|
311
|
+
*/
|
|
312
|
+
export declare const sqrLen: typeof squaredLength;
|
|
313
|
+
/**
|
|
314
|
+
* Normalize a dual quat
|
|
315
|
+
*
|
|
316
|
+
* @param out the receiving dual quaternion
|
|
317
|
+
* @param a dual quaternion to normalize
|
|
318
|
+
* @returns out
|
|
319
|
+
* @function
|
|
320
|
+
*/
|
|
321
|
+
export declare function normalize(out: Quat2, a: Quat2): Quat2;
|
|
322
|
+
/**
|
|
323
|
+
* Returns a string representation of a dual quaternion
|
|
324
|
+
*
|
|
325
|
+
* @param a dual quaternion to represent as a string
|
|
326
|
+
* @returns string representation of the dual quat
|
|
327
|
+
*/
|
|
328
|
+
export declare function str(a: Quat2): string;
|
|
329
|
+
/**
|
|
330
|
+
* Returns whether or not the dual quaternions have exactly the same elements in the same position (when compared with ===)
|
|
331
|
+
*
|
|
332
|
+
* @param a the first dual quaternion.
|
|
333
|
+
* @param b the second dual quaternion.
|
|
334
|
+
* @returns true if the dual quaternions are equal, false otherwise.
|
|
335
|
+
*/
|
|
336
|
+
export declare function exactEquals(a: Quat2, b: Quat2): boolean;
|
|
337
|
+
/**
|
|
338
|
+
* Returns whether or not the dual quaternions have approximately the same elements in the same position.
|
|
339
|
+
*
|
|
340
|
+
* @param a the first dual quat.
|
|
341
|
+
* @param b the second dual quat.
|
|
342
|
+
* @returns true if the dual quats are equal, false otherwise.
|
|
343
|
+
*/
|
|
344
|
+
export declare function equals(a: Quat2, b: Quat2): boolean;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
export declare const EPSILON = 0.000001;
|
|
2
|
+
/**
|
|
3
|
+
* Symmetric round
|
|
4
|
+
* see https://www.npmjs.com/package/round-half-up-symmetric#user-content-detailed-background
|
|
5
|
+
*
|
|
6
|
+
* @param a value to round
|
|
7
|
+
*/
|
|
8
|
+
export declare function round(a: number): number;
|
|
9
|
+
/**
|
|
10
|
+
* Tests whether or not the arguments have approximately the same value, within an absolute
|
|
11
|
+
* or relative tolerance of glMatrix.EPSILON (an absolute tolerance is used for values less
|
|
12
|
+
* than or equal to 1.0, and a relative tolerance is used for larger values)
|
|
13
|
+
*
|
|
14
|
+
* @param a The first number to test.
|
|
15
|
+
* @param b The second number to test.
|
|
16
|
+
* @returns True if the numbers are approximately equal, false otherwise.
|
|
17
|
+
*/
|
|
18
|
+
export declare function equals(a: number, b: number, epsilon?: number): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Ease-in-out, goes to -Infinite before 0 and Infinite after 1
|
|
21
|
+
*
|
|
22
|
+
* https://www.desmos.com/calculator/vsnmlaljdu
|
|
23
|
+
*
|
|
24
|
+
* @param t
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
27
|
+
export declare function fade(t: number): number;
|
|
28
|
+
/**
|
|
29
|
+
*
|
|
30
|
+
* Returns the result of linearly interpolating between input A and input B by input T.
|
|
31
|
+
*
|
|
32
|
+
* @param v0
|
|
33
|
+
* @param v1
|
|
34
|
+
* @param t
|
|
35
|
+
* @returns
|
|
36
|
+
*/
|
|
37
|
+
export declare function lerp(v0: number, v1: number, t: number): number;
|
|
38
|
+
/**
|
|
39
|
+
*
|
|
40
|
+
* Quadratic interpolation through three values using Lagrange interpolation.
|
|
41
|
+
* Passes through v0 at t=0, v1 at t=0.5, and v2 at t=1.
|
|
42
|
+
*
|
|
43
|
+
* @param v0 value at t=0
|
|
44
|
+
* @param v1 value at t=0.5
|
|
45
|
+
* @param v2 value at t=1
|
|
46
|
+
* @param t
|
|
47
|
+
* @returns
|
|
48
|
+
*/
|
|
49
|
+
export declare function lagrange(v0: number, v1: number, v2: number, t: number): number;
|
|
50
|
+
/**
|
|
51
|
+
*
|
|
52
|
+
* Binomial coefficient, "n choose k": the number of ways to choose k items
|
|
53
|
+
* from a set of n without order or repetition.
|
|
54
|
+
*
|
|
55
|
+
* @param n total number of items
|
|
56
|
+
* @param k number of items to choose
|
|
57
|
+
* @returns the binomial coefficient, or 0 when k is out of range
|
|
58
|
+
*/
|
|
59
|
+
export declare function binomial(n: number, k: number): number;
|
|
60
|
+
/**
|
|
61
|
+
* Clamp a value between min and max
|
|
62
|
+
*/
|
|
63
|
+
export declare const clamp: (value: number, min: number, max: number) => number;
|
|
64
|
+
/**
|
|
65
|
+
* Loops `t` so that it is never larger than `length` and never smaller than 0.
|
|
66
|
+
*/
|
|
67
|
+
export declare function repeat(t: number, length: number): number;
|
|
68
|
+
/**
|
|
69
|
+
* Remaps a number from one range to another.
|
|
70
|
+
*/
|
|
71
|
+
export declare function remap(number: number, inLow: number, inHigh: number, outLow: number, outHigh: number): number;
|
|
72
|
+
/**
|
|
73
|
+
* Remaps a number from one range to another, clamping the result to the output range.
|
|
74
|
+
*/
|
|
75
|
+
export declare function remapClamp(value: number, inLow: number, inHigh: number, outLow: number, outHigh: number): number;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import type { Vec2 } from './vec2.js';
|
|
2
|
+
import type { Vec3 } from './vec3.js';
|
|
3
|
+
/**
|
|
4
|
+
* A point in spherical coordinates [r, theta, phi] (Three.js / OpenGL convention)
|
|
5
|
+
* r - radial distance from the origin
|
|
6
|
+
* theta - azimuthal angle in the XZ plane from the +Z axis (radians, range [-π, π])
|
|
7
|
+
* phi - polar angle from the +Y axis (radians, range [0, π])
|
|
8
|
+
*/
|
|
9
|
+
export type Spherical = [r: number, theta: number, phi: number];
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new spherical coordinate at r=1, theta=0, phi=0
|
|
12
|
+
*
|
|
13
|
+
* @returns a new Spherical
|
|
14
|
+
*/
|
|
15
|
+
export declare function create(): Spherical;
|
|
16
|
+
/**
|
|
17
|
+
* Creates a new Spherical initialized with the given values
|
|
18
|
+
*
|
|
19
|
+
* @param r radial distance
|
|
20
|
+
* @param theta azimuthal angle in the XZ plane from +Z (radians)
|
|
21
|
+
* @param phi polar angle from +Y axis (radians)
|
|
22
|
+
* @returns a new Spherical
|
|
23
|
+
*/
|
|
24
|
+
export declare function fromValues(r: number, theta: number, phi: number): Spherical;
|
|
25
|
+
/**
|
|
26
|
+
* Creates a new Spherical initialized with values from an existing one
|
|
27
|
+
*
|
|
28
|
+
* @param a the source Spherical
|
|
29
|
+
* @returns a new Spherical
|
|
30
|
+
*/
|
|
31
|
+
export declare function clone(a: Spherical): Spherical;
|
|
32
|
+
/**
|
|
33
|
+
* Copies values from one Spherical to another
|
|
34
|
+
*
|
|
35
|
+
* @param out the receiving Spherical
|
|
36
|
+
* @param a the source Spherical
|
|
37
|
+
* @returns out
|
|
38
|
+
*/
|
|
39
|
+
export declare function copy(out: Spherical, a: Spherical): Spherical;
|
|
40
|
+
/**
|
|
41
|
+
* Sets the components of a Spherical
|
|
42
|
+
*
|
|
43
|
+
* @param out the receiving Spherical
|
|
44
|
+
* @param r radial distance
|
|
45
|
+
* @param theta azimuthal angle in the XZ plane from +Z (radians)
|
|
46
|
+
* @param phi polar angle from +Y axis (radians)
|
|
47
|
+
* @returns out
|
|
48
|
+
*/
|
|
49
|
+
export declare function set(out: Spherical, r: number, theta: number, phi: number): Spherical;
|
|
50
|
+
/**
|
|
51
|
+
* Sets r=1, preserving the angles. No-op if r is already zero.
|
|
52
|
+
*
|
|
53
|
+
* @param out the receiving Spherical
|
|
54
|
+
* @param a the source Spherical
|
|
55
|
+
* @returns out
|
|
56
|
+
*/
|
|
57
|
+
export declare function normalize(out: Spherical, a: Spherical): Spherical;
|
|
58
|
+
/**
|
|
59
|
+
* Scales the radial distance r by a scalar
|
|
60
|
+
*
|
|
61
|
+
* @param out the receiving Spherical
|
|
62
|
+
* @param a the source Spherical
|
|
63
|
+
* @param s scalar to multiply r by
|
|
64
|
+
* @returns out
|
|
65
|
+
*/
|
|
66
|
+
export declare function scale(out: Spherical, a: Spherical, s: number): Spherical;
|
|
67
|
+
/**
|
|
68
|
+
* Linearly interpolates between two Spherical coordinates taking the shortest
|
|
69
|
+
* angular path for theta and phi.
|
|
70
|
+
*
|
|
71
|
+
* @param out the receiving Spherical
|
|
72
|
+
* @param a the first operand
|
|
73
|
+
* @param b the second operand
|
|
74
|
+
* @param t interpolation factor in [0, 1]
|
|
75
|
+
* @returns out
|
|
76
|
+
*/
|
|
77
|
+
export declare function lerp(out: Spherical, a: Spherical, b: Spherical, t: number): Spherical;
|
|
78
|
+
/**
|
|
79
|
+
* Sets a Spherical from Cartesian Vec3 coordinates (Three.js / OpenGL convention):
|
|
80
|
+
* r = sqrt(x² + y² + z²)
|
|
81
|
+
* theta = atan2(x, z) (azimuthal angle in XZ plane from +Z)
|
|
82
|
+
* phi = acos(y / r) (polar angle from +Y)
|
|
83
|
+
*
|
|
84
|
+
* @param out the receiving Spherical
|
|
85
|
+
* @param v the source Vec3
|
|
86
|
+
* @returns out
|
|
87
|
+
*/
|
|
88
|
+
export declare function setFromVec3(out: Spherical, v: Vec3): Spherical;
|
|
89
|
+
/** @alias setFromVec3 */
|
|
90
|
+
export declare const fromVec3: typeof setFromVec3;
|
|
91
|
+
/**
|
|
92
|
+
* Clamps phi to the range [EPSILON, π - EPSILON] to avoid coordinate
|
|
93
|
+
* singularities at the poles (gimbal lock / division by zero).
|
|
94
|
+
* r and theta are left unchanged.
|
|
95
|
+
*
|
|
96
|
+
* @param out the receiving Spherical
|
|
97
|
+
* @param a the source Spherical
|
|
98
|
+
* @returns out
|
|
99
|
+
*/
|
|
100
|
+
export declare function makeSafe(out: Spherical, a: Spherical): Spherical;
|
|
101
|
+
/**
|
|
102
|
+
* Converts spherical coordinates to a Cartesian Vec3 (Three.js / OpenGL convention):
|
|
103
|
+
* x = r * sin(phi) * sin(theta)
|
|
104
|
+
* y = r * cos(phi)
|
|
105
|
+
* z = r * sin(phi) * cos(theta)
|
|
106
|
+
*
|
|
107
|
+
* @param out the receiving Vec3
|
|
108
|
+
* @param a the source Spherical
|
|
109
|
+
* @returns out
|
|
110
|
+
*/
|
|
111
|
+
export declare function toVec3(out: Vec3, a: Spherical): Vec3;
|
|
112
|
+
/**
|
|
113
|
+
* Converts a Vec2 (x, z) in the horizontal XZ plane to spherical coordinates.
|
|
114
|
+
* The point is treated as lying on the equator (phi = π/2, y = 0).
|
|
115
|
+
*
|
|
116
|
+
* @param out the receiving Spherical
|
|
117
|
+
* @param v the source Vec2 interpreted as (x, z)
|
|
118
|
+
* @returns out
|
|
119
|
+
*/
|
|
120
|
+
export declare function fromVec2(out: Spherical, v: Vec2): Spherical;
|
|
121
|
+
/**
|
|
122
|
+
* Projects spherical coordinates onto the XZ plane, returning a Vec2 (x, z).
|
|
123
|
+
* Equivalent to taking the horizontal footprint of the 3D point.
|
|
124
|
+
*
|
|
125
|
+
* @param out the receiving Vec2
|
|
126
|
+
* @param a the source Spherical
|
|
127
|
+
* @returns out
|
|
128
|
+
*/
|
|
129
|
+
export declare function toVec2(out: Vec2, a: Spherical): Vec2;
|
|
130
|
+
/**
|
|
131
|
+
* Returns true if two Spherical coordinates are approximately equal,
|
|
132
|
+
* within an absolute/relative tolerance of EPSILON.
|
|
133
|
+
*
|
|
134
|
+
* @param a the first Spherical
|
|
135
|
+
* @param b the second Spherical
|
|
136
|
+
* @returns true if approximately equal
|
|
137
|
+
*/
|
|
138
|
+
export declare function equals(a: Spherical, b: Spherical): boolean;
|
|
139
|
+
/**
|
|
140
|
+
* Returns true if two Spherical coordinates are exactly equal (===).
|
|
141
|
+
*
|
|
142
|
+
* @param a the first Spherical
|
|
143
|
+
* @param b the second Spherical
|
|
144
|
+
* @returns true if exactly equal
|
|
145
|
+
*/
|
|
146
|
+
export declare function exactEquals(a: Spherical, b: Spherical): boolean;
|
|
147
|
+
/**
|
|
148
|
+
* Returns a string representation of a Spherical
|
|
149
|
+
*
|
|
150
|
+
* @param a the source Spherical
|
|
151
|
+
* @returns string representation
|
|
152
|
+
*/
|
|
153
|
+
export declare function str(a: Spherical): string;
|
|
154
|
+
/**
|
|
155
|
+
* Returns the great-circle angle (in radians) between two spherical coordinates,
|
|
156
|
+
* ignoring r. Equivalent to the central angle between the two directions on a
|
|
157
|
+
* unit sphere.
|
|
158
|
+
*
|
|
159
|
+
* Uses the numerically stable haversine formula.
|
|
160
|
+
*
|
|
161
|
+
* @param a the first Spherical
|
|
162
|
+
* @param b the second Spherical
|
|
163
|
+
* @returns angle in radians in [0, π]
|
|
164
|
+
*/
|
|
165
|
+
export declare function angleTo(a: Spherical, b: Spherical): number;
|