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
package/API.md
ADDED
|
@@ -0,0 +1,1605 @@
|
|
|
1
|
+
# math — API reference
|
|
2
|
+
|
|
3
|
+
Complete reference for every export in `math`, grouped by module. For an
|
|
4
|
+
overview, installation, and examples, see the [README](./README.md).
|
|
5
|
+
|
|
6
|
+
## Modules
|
|
7
|
+
|
|
8
|
+
- [`math`](#api-math) — Vectors, quaternions, euler angles & matrices
|
|
9
|
+
- [`math/shapes`](#api-math-shapes) — Shape primitives & spatial queries
|
|
10
|
+
- [`math/geometry`](#api-math-geometry) — Geometric algorithms
|
|
11
|
+
- [`math/time`](#api-math-time) — Easing & spring animation
|
|
12
|
+
- [`math/random`](#api-math-random) — Seeded random number generators
|
|
13
|
+
- [`math/noise`](#api-math-noise) — Perlin, simplex & worley noise, plus fractal helpers
|
|
14
|
+
- [`math/color`](#api-math-color) — Color & colorspace utilities
|
|
15
|
+
- [`math/ik`](#api-math-ik) — Inverse kinematics
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
<a id="api-math"></a>
|
|
20
|
+
|
|
21
|
+
## `math`
|
|
22
|
+
|
|
23
|
+
**Types**
|
|
24
|
+
|
|
25
|
+
- `type MutableArrayLike<T> = { [index: number]: T; length: number; }`
|
|
26
|
+
- `type Vec2 = [ x: number, y: number ]` — A 2D vector
|
|
27
|
+
- `type Vec3 = [ x: number, y: number, z: number ]` — A 3D vector
|
|
28
|
+
- `type Vec4 = [ x: number, y: number, z: number, w: number ]` — A 4D vector
|
|
29
|
+
- `type Euler = [ x: number, y: number, z: number, order?: EulerOrder ]` — A Euler in 3D space, with an optional order (default is 'xyz')
|
|
30
|
+
- `type EulerOrder = 'xyz' | 'xzy' | 'yxz' | 'yzx' | 'zxy' | 'zyx'` — Euler orders
|
|
31
|
+
- `type Quat = [ x: number, y: number, z: number, w: number ]` — A quaternion that represents rotation
|
|
32
|
+
- `type Quat2 = [ x: number, y: number, z: number, w: number, x2: number, y2: number, z2: number, w2: number ]` — A dual quaternion that represents both rotation and translation
|
|
33
|
+
- `type Mat2 = [ e1: number, e2: number, e3: number, e4: number ]` — A 2x2 matrix
|
|
34
|
+
- `type Mat2d = [ e1: number, e2: number, e3: number, e4: number, e5: number, e6: number ]` — A 2D affine transform matrix
|
|
35
|
+
- `type Mat3 = [ e1: number, e2: number, e3: number, e4: number, e5: number, e6: number, e7: number, e8: number, e9: number ]` — A 3x3 matrix
|
|
36
|
+
- `type Mat4 = [ e1: number, e2: number, e3: number, e4: number, e5: number, e6: number, e7: number, e8: number, e9: number, e10: number, e11: number, e12: number, e13: number, e14: number, e15: number, e16: number ]` — A 4x4 matrix
|
|
37
|
+
- `type Spherical = [ r: number, theta: number, phi: number ]` — A point in spherical coordinates [r, theta, phi] (Three.js / OpenGL convention)
|
|
38
|
+
- `type Polar = [ r: number, theta: number ]` — A point in polar coordinates [r, theta]
|
|
39
|
+
|
|
40
|
+
**Operations**
|
|
41
|
+
|
|
42
|
+
- <a id="epsilon"></a>`EPSILON = 0.000001`
|
|
43
|
+
- <a id="round"></a>`round(a: number): number` — Symmetric round
|
|
44
|
+
- <a id="fade"></a>`fade(t: number)` — Ease-in-out, goes to -Infinite before 0 and Infinite after 1
|
|
45
|
+
- <a id="lerp"></a>`lerp(v0: number, v1: number, t: number)`
|
|
46
|
+
- <a id="lagrange"></a>`lagrange(v0: number, v1: number, v2: number, t: number)`
|
|
47
|
+
- <a id="binomial"></a>`binomial(n: number, k: number): number`
|
|
48
|
+
- <a id="clamp"></a>`clamp(value: number, min: number, max: number): number` — Clamp a value between min and max
|
|
49
|
+
- <a id="repeat"></a>`repeat(t: number, length: number): number` — Loops `t` so that it is never larger than `length` and never smaller than 0.
|
|
50
|
+
- <a id="remap"></a>`remap(number: number, inLow: number, inHigh: number, outLow: number, outHigh: number): number` — Remaps a number from one range to another.
|
|
51
|
+
- <a id="remapclamp"></a>`remapClamp(value: number, inLow: number, inHigh: number, outLow: number, outHigh: number): number` — Remaps a number from one range to another, clamping the result to the output range.
|
|
52
|
+
- <a id="degrees_to_radians"></a>`DEGREES_TO_RADIANS`
|
|
53
|
+
- <a id="radians_to_degrees"></a>`RADIANS_TO_DEGREES`
|
|
54
|
+
- <a id="degreestoradians"></a>`degreesToRadians(degrees: number): number` — Converts Degrees To Radians
|
|
55
|
+
- <a id="radianstodegrees"></a>`radiansToDegrees(radians: number): number` — Converts Radians To Degrees
|
|
56
|
+
- <a id="wrapangle"></a>`wrapAngle(a: number): number` — Wraps an angle (in radians) into the range (-π, π].
|
|
57
|
+
- <a id="deltaangle"></a>`deltaAngle(current: number, target: number): number` — Calculates the shortest signed difference between two angles (in radians).
|
|
58
|
+
|
|
59
|
+
**Query**
|
|
60
|
+
|
|
61
|
+
- <a id="equals"></a>`equals(a: number, b: number, epsilon = EPSILON): boolean` — Tests whether or not the arguments have approximately the same value, within an absolute
|
|
62
|
+
|
|
63
|
+
<a id="api-math-vec2"></a>
|
|
64
|
+
|
|
65
|
+
### `vec2`
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
import { vec2 } from 'math';
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
**Create**
|
|
72
|
+
|
|
73
|
+
- `vec2.create(): Vec2` — Creates a new, empty vec2
|
|
74
|
+
- `vec2.clone(a: Vec2): Vec2` — Creates a new vec2 initialized with values from an existing vector
|
|
75
|
+
- `vec2.fromValues(x: number, y: number): Vec2` — Creates a new vec2 initialized with the given values
|
|
76
|
+
- `vec2.copy(out: Vec2, a: Vec2): Vec2` — Copy the values from one vec2 to another
|
|
77
|
+
- `vec2.set(out: Vec2, x: number, y: number): Vec2` — Set the components of a vec2 to the given values
|
|
78
|
+
- `vec2.fromBuffer(out: Vec2, buffer: ArrayLike<number>, startIndex: number): Vec2` — Sets the components of a vec2 from a buffer
|
|
79
|
+
- `vec2.toBuffer(outBuffer: MutableArrayLike<number>, vec: Vec2, startIndex: number): MutableArrayLike<number>` — Writes the components of a vec2 to a buffer
|
|
80
|
+
- `vec2.zero(out: Vec2): Vec2` — Set the components of a vec2 to zero
|
|
81
|
+
- `vec2.str(a: Vec2): string` — Returns a string representation of a vector
|
|
82
|
+
|
|
83
|
+
**Operations**
|
|
84
|
+
|
|
85
|
+
- `vec2.add(out: Vec2, a: Vec2, b: Vec2): Vec2` — Adds two vec2's
|
|
86
|
+
- `vec2.addScalar(out: Vec2, a: Vec2, b: number): Vec2` — Adds a scalar value to all components of a vec2
|
|
87
|
+
- `vec2.subtract(out: Vec2, a: Vec2, b: Vec2): Vec2` — Subtracts vector b from vector a
|
|
88
|
+
- `vec2.subtractScalar(out: Vec2, a: Vec2, b: number): Vec2` — Subtracts a scalar value from all components of a vec2
|
|
89
|
+
- `vec2.multiply(out: Vec2, a: Vec2, b: Vec2): Vec2` — Multiplies two vec2's
|
|
90
|
+
- `vec2.divide(out: Vec2, a: Vec2, b: Vec2): Vec2` — Divides two vec2's
|
|
91
|
+
- `vec2.ceil(out: Vec2, a: Vec2): Vec2` — Math.ceil the components of a vec2
|
|
92
|
+
- `vec2.floor(out: Vec2, a: Vec2): Vec2` — Math.floor the components of a vec2
|
|
93
|
+
- `vec2.min(out: Vec2, a: Vec2, b: Vec2): Vec2` — Returns the minimum of two vec2's
|
|
94
|
+
- `vec2.max(out: Vec2, a: Vec2, b: Vec2): Vec2` — Returns the maximum of two vec2's
|
|
95
|
+
- `vec2.round(out: Vec2, a: Vec2): Vec2` — symmetric round the components of a vec2
|
|
96
|
+
- `vec2.scale(out: Vec2, a: Vec2, b: number): Vec2` — Scales a vec2 by a scalar number
|
|
97
|
+
- `vec2.scaleAndAdd(out: Vec2, a: Vec2, b: Vec2, scale: number): Vec2` — Adds two vec2's after scaling the second operand by a scalar value
|
|
98
|
+
- `vec2.distance(a: Vec2, b: Vec2): number` — Calculates the euclidian distance between two vec2's
|
|
99
|
+
- `vec2.squaredDistance(a: Vec2, b: Vec2): number` — Calculates the squared euclidian distance between two vec2's
|
|
100
|
+
- `vec2.length(a: Vec2): number` — Calculates the length of a vec2
|
|
101
|
+
- `vec2.squaredLength(a: Vec2): number` — Calculates the squared length of a vec2
|
|
102
|
+
- `vec2.negate(out: Vec2, a: Vec2): Vec2` — Negates the components of a vec2
|
|
103
|
+
- `vec2.inverse(out: Vec2, a: Vec2): Vec2` — Returns the inverse of the components of a vec2
|
|
104
|
+
- `vec2.normalize(out: Vec2, a: Vec2): Vec2` — Normalize a vec2
|
|
105
|
+
- `vec2.dot(a: Vec2, b: Vec2): number` — Calculates the dot product of two vec2's
|
|
106
|
+
- `vec2.cross(out: Vec3, a: Vec2, b: Vec2): Vec3` — Computes the cross product of two vec2's
|
|
107
|
+
- `vec2.lerp(out: Vec2, a: Vec2, b: Vec2, t: number): Vec2` — Performs a linear interpolation between two vec2's
|
|
108
|
+
- `vec2.lagrange(out: Vec2, a: Vec2, b: Vec2, c: Vec2, t: number): Vec2` — Quadratic interpolation through three vectors using Lagrange interpolation.
|
|
109
|
+
- `vec2.signedAngle(a: Vec2, b: Vec2): number` — Get the signed angle from `a` to `b`, in the range (-PI, PI].
|
|
110
|
+
|
|
111
|
+
**Transform**
|
|
112
|
+
|
|
113
|
+
- `vec2.transformMat2(out: Vec2, a: Vec2, m: Mat2): Vec2` — Transforms the vec2 with a mat2
|
|
114
|
+
- `vec2.transformMat2d(out: Vec2, a: Vec2, m: Mat2d): Vec2` — Transforms the vec2 with a mat2d
|
|
115
|
+
- `vec2.transformMat3(out: Vec2, a: Vec2, m: Mat3): Vec2` — Transforms the vec2 with a mat3
|
|
116
|
+
- `vec2.transformMat4(out: Vec2, a: Vec2, m: Mat4): Vec2` — Transforms the vec2 with a mat4
|
|
117
|
+
- `vec2.rotate(out: Vec2, a: Vec2, b: Vec2, rad: number): Vec2` — Rotate a 2D vector
|
|
118
|
+
|
|
119
|
+
**Query**
|
|
120
|
+
|
|
121
|
+
- `vec2.angle(a: Vec2, b: Vec2): number` — Get the angle between two 2D vectors
|
|
122
|
+
- `vec2.exactEquals(a: Vec2, b: Vec2): boolean` — Returns whether or not the vectors exactly have the same elements in the same position (when compared with ===)
|
|
123
|
+
- `vec2.equals(a: Vec2, b: Vec2): boolean` — Returns whether or not the vectors have approximately the same elements in the same position.
|
|
124
|
+
- `vec2.finite(a: Vec2): boolean` — Returns whether or not the vector is finite
|
|
125
|
+
|
|
126
|
+
**Aliases**
|
|
127
|
+
|
|
128
|
+
- `vec2.len = length` — Alias for `length`
|
|
129
|
+
- `vec2.sub = subtract` — Alias for `subtract`
|
|
130
|
+
- `vec2.mul = multiply` — Alias for `multiply`
|
|
131
|
+
- `vec2.div = divide` — Alias for `divide`
|
|
132
|
+
- `vec2.dist = distance` — Alias for `distance`
|
|
133
|
+
- `vec2.sqrDist = squaredDistance` — Alias for `squaredDistance`
|
|
134
|
+
- `vec2.sqrLen = squaredLength` — Alias for `squaredLength`
|
|
135
|
+
|
|
136
|
+
<a id="api-math-vec3"></a>
|
|
137
|
+
|
|
138
|
+
### `vec3`
|
|
139
|
+
|
|
140
|
+
```ts
|
|
141
|
+
import { vec3 } from 'math';
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
**Create**
|
|
145
|
+
|
|
146
|
+
- `vec3.create(): Vec3` — Creates a new, empty vec3
|
|
147
|
+
- `vec3.clone(a: Vec3): Vec3` — Creates a new vec3 initialized with values from an existing vector
|
|
148
|
+
- `vec3.fromValues(x: number, y: number, z: number): Vec3` — Creates a new vec3 initialized with the given values
|
|
149
|
+
- `vec3.copy(out: Vec3, a: Vec3): Vec3` — Copy the values from one vec3 to another
|
|
150
|
+
- `vec3.set(out: Vec3, x: number, y: number, z: number): Vec3` — Set the components of a vec3 to the given values
|
|
151
|
+
- `vec3.setScalar(out: Vec3, s: number): Vec3` — Sets all components of a vec3 to the given scalar value
|
|
152
|
+
- `vec3.fromBuffer(out: Vec3, buffer: ArrayLike<number>, startIndex: number): Vec3` — Sets the components of a vec3 from a buffer
|
|
153
|
+
- `vec3.toBuffer(outBuffer: MutableArrayLike<number>, vec: Vec3, startIndex: number): MutableArrayLike<number>` — Writes the components of a vec3 to a buffer
|
|
154
|
+
- `vec3.zero(out: Vec3): Vec3` — Set the components of a vec3 to zero
|
|
155
|
+
- `vec3.str(a: Vec3): string` — Returns a string representation of a vector
|
|
156
|
+
|
|
157
|
+
**Operations**
|
|
158
|
+
|
|
159
|
+
- `vec3.length(a: Vec3): number` — Calculates the length of a vec3
|
|
160
|
+
- `vec3.add(out: Vec3, a: Vec3, b: Vec3): Vec3` — Adds two vec3's
|
|
161
|
+
- `vec3.addScalar(out: Vec3, a: Vec3, b: number): Vec3` — Adds a scalar value to all components of a vec3
|
|
162
|
+
- `vec3.subtract(out: Vec3, a: Vec3, b: Vec3): Vec3` — Subtracts vector b from vector a
|
|
163
|
+
- `vec3.subtractScalar(out: Vec3, a: Vec3, b: number): Vec3` — Subtracts a scalar value from all components of a vec3
|
|
164
|
+
- `vec3.multiply(out: Vec3, a: Vec3, b: Vec3): Vec3` — Multiplies two vec3's
|
|
165
|
+
- `vec3.divide(out: Vec3, a: Vec3, b: Vec3): Vec3` — Divides two vec3's
|
|
166
|
+
- `vec3.ceil(out: Vec3, a: Vec3): Vec3` — Math.ceil the components of a vec3
|
|
167
|
+
- `vec3.floor(out: Vec3, a: Vec3): Vec3` — Math.floor the components of a vec3
|
|
168
|
+
- `vec3.min(out: Vec3, a: Vec3, b: Vec3): Vec3` — Returns the minimum of two vec3's
|
|
169
|
+
- `vec3.max(out: Vec3, a: Vec3, b: Vec3): Vec3` — Returns the maximum of two vec3's
|
|
170
|
+
- `vec3.round(out: Vec3, a: Vec3): Vec3` — symmetric round the components of a vec3
|
|
171
|
+
- `vec3.scale(out: Vec3, a: Vec3, b: number): Vec3` — Scales a vec3 by a scalar number
|
|
172
|
+
- `vec3.scaleAndAdd(out: Vec3, a: Vec3, b: Vec3, scale: number): Vec3` — Adds two vec3's after scaling the second operand by a scalar value
|
|
173
|
+
- `vec3.distance(a: Vec3, b: Vec3): number` — Calculates the euclidian distance between two vec3's
|
|
174
|
+
- `vec3.squaredDistance(a: Vec3, b: Vec3): number` — Calculates the squared euclidian distance between two vec3's
|
|
175
|
+
- `vec3.squaredLength(a: Vec3): number` — Calculates the squared length of a vec3
|
|
176
|
+
- `vec3.negate(out: Vec3, a: Vec3): Vec3` — Negates the components of a vec3
|
|
177
|
+
- `vec3.inverse(out: Vec3, a: Vec3): Vec3` — Returns the inverse of the components of a vec3
|
|
178
|
+
- `vec3.normalize(out: Vec3, a: Vec3): Vec3` — Normalize a vec3
|
|
179
|
+
- `vec3.dot(a: Vec3, b: Vec3): number` — Calculates the dot product of two vec3's
|
|
180
|
+
- `vec3.cross(out: Vec3, a: Vec3, b: Vec3): Vec3` — Computes the cross product of two vec3's
|
|
181
|
+
- `vec3.perpendicular(out: Vec3, a: Vec3): Vec3` — Calculates a normalized perpendicular vector to the given vector.
|
|
182
|
+
- `vec3.lerp(out: Vec3, a: Vec3, b: Vec3, t: number): Vec3` — Performs a linear interpolation between two vec3's
|
|
183
|
+
- `vec3.lagrange(out: Vec3, a: Vec3, b: Vec3, c: Vec3, t: number): Vec3` — Quadratic interpolation through three vectors using Lagrange interpolation.
|
|
184
|
+
- `vec3.slerp(out: Vec3, a: Vec3, b: Vec3, t: number): Vec3` — Performs a spherical linear interpolation between two vec3's
|
|
185
|
+
- `vec3.hermite(out: Vec3, a: Vec3, b: Vec3, c: Vec3, d: Vec3, t: number): Vec3` — Performs a hermite interpolation with two control points
|
|
186
|
+
- `vec3.bezier(out: Vec3, a: Vec3, b: Vec3, c: Vec3, d: Vec3, t: number): Vec3` — Performs a bezier interpolation with two control points
|
|
187
|
+
- `vec3.signedAngle(a: Vec3, b: Vec3, axis: Vec3): number` — Get the signed angle from `a` to `b` measured about `axis`, in the range (-PI, PI].
|
|
188
|
+
|
|
189
|
+
**Transform**
|
|
190
|
+
|
|
191
|
+
- `vec3.transformMat4(out: Vec3, a: Vec3, m: Mat4): Vec3` — Transforms the vec3 with a mat4.
|
|
192
|
+
- `vec3.transformMat3(out: Vec3, a: Vec3, m: Mat3): Vec3` — Transforms the vec3 with a mat3.
|
|
193
|
+
- `vec3.transformQuat(out: Vec3, a: Vec3, q: Quat): Vec3` — Transforms the vec3 with a quat
|
|
194
|
+
- `vec3.rotateX(out: Vec3, a: Vec3, b: Vec3, rad: number): Vec3` — Rotate a 3D vector around the x-axis
|
|
195
|
+
- `vec3.rotateY(out: Vec3, a: Vec3, b: Vec3, rad: number): Vec3` — Rotate a 3D vector around the y-axis
|
|
196
|
+
- `vec3.rotateZ(out: Vec3, a: Vec3, b: Vec3, rad: number): Vec3` — Rotate a 3D vector around the z-axis
|
|
197
|
+
- `vec3.rotateTowards(out: Vec3, from: Vec3, to: Vec3, maxAngle: number): Vec3` — Rotates the unit vector `from` toward the unit vector `to` by at most `maxAngle` radians.
|
|
198
|
+
|
|
199
|
+
**Query**
|
|
200
|
+
|
|
201
|
+
- `vec3.angle(a: Vec3, b: Vec3): number` — Get the angle between two 3D vectors
|
|
202
|
+
- `vec3.exactEquals(a: Vec3, b: Vec3): boolean` — Returns whether or not the vectors have exactly the same elements in the same position (when compared with ===)
|
|
203
|
+
- `vec3.equals(a: Vec3, b: Vec3): boolean` — Returns whether or not the vectors have approximately the same elements in the same position.
|
|
204
|
+
- `vec3.finite(a: Vec3): boolean` — Returns whether or not the vector is finite
|
|
205
|
+
- `vec3.isScaleInsideOut(scale: Vec3): boolean` — Determines if a scale vector represents an inside-out transformation (reflection)
|
|
206
|
+
|
|
207
|
+
**Aliases**
|
|
208
|
+
|
|
209
|
+
- `vec3.sub = subtract` — Alias for `subtract`
|
|
210
|
+
- `vec3.mul = multiply` — Alias for `multiply`
|
|
211
|
+
- `vec3.div = divide` — Alias for `divide`
|
|
212
|
+
- `vec3.dist = distance` — Alias for `distance`
|
|
213
|
+
- `vec3.sqrDist = squaredDistance` — Alias for `squaredDistance`
|
|
214
|
+
- `vec3.len = length` — Alias for `length`
|
|
215
|
+
- `vec3.sqrLen = squaredLength` — Alias for `squaredLength`
|
|
216
|
+
|
|
217
|
+
<a id="api-math-vec4"></a>
|
|
218
|
+
|
|
219
|
+
### `vec4`
|
|
220
|
+
|
|
221
|
+
```ts
|
|
222
|
+
import { vec4 } from 'math';
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
**Create**
|
|
226
|
+
|
|
227
|
+
- `vec4.create(): Vec4` — Creates a new, empty vec4
|
|
228
|
+
- `vec4.clone(a: Vec4): Vec4` — Creates a new vec4 initialized with values from an existing vector
|
|
229
|
+
- `vec4.fromValues(x: number, y: number, z: number, w: number): Vec4` — Creates a new vec4 initialized with the given values
|
|
230
|
+
- `vec4.copy(out: Vec4, a: Vec4): Vec4` — Copy the values from one vec4 to another
|
|
231
|
+
- `vec4.set(out: Vec4, x: number, y: number, z: number, w: number): Vec4` — Set the components of a vec4 to the given values
|
|
232
|
+
- `vec4.fromBuffer(out: Vec4, buffer: ArrayLike<number>, startIndex: number): Vec4` — Sets the components of a vec4 from a buffer
|
|
233
|
+
- `vec4.toBuffer(outBuffer: MutableArrayLike<number>, vec: Vec4, startIndex: number): MutableArrayLike<number>` — Writes the components of a vec4 to a buffer
|
|
234
|
+
- `vec4.zero(out: Vec4): Vec4` — Set the components of a vec4 to zero
|
|
235
|
+
- `vec4.str(a: Vec4): string` — Returns a string representation of a vector
|
|
236
|
+
|
|
237
|
+
**Operations**
|
|
238
|
+
|
|
239
|
+
- `vec4.add(out: Vec4, a: Vec4, b: Vec4): Vec4` — Adds two vec4's
|
|
240
|
+
- `vec4.subtract(out: Vec4, a: Vec4, b: Vec4): Vec4` — Subtracts vector b from vector a
|
|
241
|
+
- `vec4.multiply(out: Vec4, a: Vec4, b: Vec4): Vec4` — Multiplies two vec4's
|
|
242
|
+
- `vec4.divide(out: Vec4, a: Vec4, b: Vec4): Vec4` — Divides two vec4's
|
|
243
|
+
- `vec4.ceil(out: Vec4, a: Vec4): Vec4` — Math.ceil the components of a vec4
|
|
244
|
+
- `vec4.floor(out: Vec4, a: Vec4): Vec4` — Math.floor the components of a vec4
|
|
245
|
+
- `vec4.min(out: Vec4, a: Vec4, b: Vec4): Vec4` — Returns the minimum of two vec4's
|
|
246
|
+
- `vec4.max(out: Vec4, a: Vec4, b: Vec4): Vec4` — Returns the maximum of two vec4's
|
|
247
|
+
- `vec4.round(out: Vec4, a: Vec4): Vec4` — symmetric round the components of a vec4
|
|
248
|
+
- `vec4.scale(out: Vec4, a: Vec4, b: number): Vec4` — Scales a vec4 by a scalar number
|
|
249
|
+
- `vec4.scaleAndAdd(out: Vec4, a: Vec4, b: Vec4, scale: number): Vec4` — Adds two vec4's after scaling the second operand by a scalar value
|
|
250
|
+
- `vec4.distance(a: Vec4, b: Vec4): number` — Calculates the euclidian distance between two vec4's
|
|
251
|
+
- `vec4.squaredDistance(a: Vec4, b: Vec4): number` — Calculates the squared euclidian distance between two vec4's
|
|
252
|
+
- `vec4.length(a: Vec4): number` — Calculates the length of a vec4
|
|
253
|
+
- `vec4.squaredLength(a: Vec4): number` — Calculates the squared length of a vec4
|
|
254
|
+
- `vec4.negate(out: Vec4, a: Vec4): Vec4` — Negates the components of a vec4
|
|
255
|
+
- `vec4.inverse(out: Vec4, a: Vec4): Vec4` — Returns the inverse of the components of a vec4
|
|
256
|
+
- `vec4.normalize(out: Vec4, a: Vec4): Vec4` — Normalize a vec4
|
|
257
|
+
- `vec4.dot(a: Vec4, b: Vec4): number` — Calculates the dot product of two vec4's
|
|
258
|
+
- `vec4.cross(out: Vec4, u: Vec4, v: Vec4, w: Vec4): Vec4` — Returns the cross-product of three vectors in a 4-dimensional space
|
|
259
|
+
- `vec4.lerp(out: Vec4, a: Vec4, b: Vec4, t: number): Vec4` — Performs a linear interpolation between two vec4's
|
|
260
|
+
- `vec4.lagrange(out: Vec4, a: Vec4, b: Vec4, c: Vec4, t: number): Vec4` — Quadratic interpolation through three vectors using Lagrange interpolation.
|
|
261
|
+
|
|
262
|
+
**Transform**
|
|
263
|
+
|
|
264
|
+
- `vec4.transformMat4(out: Vec4, a: Vec4, m: Mat4): Vec4` — Transforms the vec4 with a mat4.
|
|
265
|
+
- `vec4.transformQuat(out: Vec4, a: Vec4, q: Quat): Vec4` — Transforms the vec4 with a quat
|
|
266
|
+
|
|
267
|
+
**Query**
|
|
268
|
+
|
|
269
|
+
- `vec4.exactEquals(a: Vec4, b: Vec4): boolean` — Returns whether or not the vectors have exactly the same elements in the same position (when compared with ===)
|
|
270
|
+
- `vec4.equals(a: Vec4, b: Vec4): boolean` — Returns whether or not the vectors have approximately the same elements in the same position.
|
|
271
|
+
- `vec4.finite(a: Vec4): boolean` — Returns whether or not the vector is finite
|
|
272
|
+
|
|
273
|
+
**Aliases**
|
|
274
|
+
|
|
275
|
+
- `vec4.sub = subtract` — Alias for `subtract`
|
|
276
|
+
- `vec4.mul = multiply` — Alias for `multiply`
|
|
277
|
+
- `vec4.div = divide` — Alias for `divide`
|
|
278
|
+
- `vec4.dist = distance` — Alias for `distance`
|
|
279
|
+
- `vec4.sqrDist = squaredDistance` — Alias for `squaredDistance`
|
|
280
|
+
- `vec4.len = length` — Alias for `length`
|
|
281
|
+
- `vec4.sqrLen = squaredLength` — Alias for `squaredLength`
|
|
282
|
+
|
|
283
|
+
<a id="api-math-euler"></a>
|
|
284
|
+
|
|
285
|
+
### `euler`
|
|
286
|
+
|
|
287
|
+
```ts
|
|
288
|
+
import { euler } from 'math';
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
**Create**
|
|
292
|
+
|
|
293
|
+
- `euler.create(): Euler` — Creates a new Euler with default values (0, 0, 0, 'xyz').
|
|
294
|
+
- `euler.fromValues(x: number, y: number, z: number, order: EulerOrder): Euler` — Creates a new Euler from the given values.
|
|
295
|
+
- `euler.set(out: Euler, x: number, y: number, z: number, order: EulerOrder): Euler` — Sets a given Euler from the given values.
|
|
296
|
+
- `euler.fromDegrees(out: Euler, x: number, y: number, z: number, order: EulerOrder): Euler` — Sets Euler angle radians from given degrees
|
|
297
|
+
- `euler.fromRotationMat4(out: Euler, rotationMatrix: Mat4, order: EulerOrder = out[3] || 'xyz'): Euler` — Sets the Euler angles from a rotation matrix.
|
|
298
|
+
- `euler.fromQuat(out: Euler, q: Quat, order: EulerOrder): Euler` — Sets the Euler angles from a quaternion.
|
|
299
|
+
- `euler.reorder(out: Euler, a: Euler, order: EulerOrder): Euler` — Reorders the Euler based on the specified order.
|
|
300
|
+
|
|
301
|
+
**Query**
|
|
302
|
+
|
|
303
|
+
- `euler.exactEquals(a: Euler, b: Euler): boolean` — Returns whether or not the euler angles have exactly the same elements in the same position (when compared with ===)
|
|
304
|
+
- `euler.equals(a: Euler, b: Euler): boolean` — Returns whether or not the euler angles have approximately the same elements in the same position.
|
|
305
|
+
|
|
306
|
+
<a id="api-math-quat"></a>
|
|
307
|
+
|
|
308
|
+
### `quat`
|
|
309
|
+
|
|
310
|
+
```ts
|
|
311
|
+
import { quat } from 'math';
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
**Create**
|
|
315
|
+
|
|
316
|
+
- `quat.create(): Quat` — Creates a new identity quat
|
|
317
|
+
- `quat.fromBuffer(out: Quat, buffer: ArrayLike<number>, startIndex: number): Quat` — Sets the components of a quat from a buffer
|
|
318
|
+
- `quat.toBuffer(outBuffer: MutableArrayLike<number>, q: Quat, startIndex: number): MutableArrayLike<number>` — Writes the components of a quat to a buffer
|
|
319
|
+
- `quat.identity(out: Quat): Quat` — Set a quat to the identity quaternion
|
|
320
|
+
- `quat.setAxisAngle(out: Quat, axis: Vec3, rad: number): Quat` — Sets a quat from the given angle and rotation axis
|
|
321
|
+
- `quat.calculateW(out: Quat, a: Quat): Quat` — Calculates the W component of a quat from the X, Y, and Z components.
|
|
322
|
+
- `quat.fromMat3(out: Quat, m: Mat3): Quat` — Creates a quaternion from the given 3x3 rotation matrix.
|
|
323
|
+
- `quat.fromMat4(out: Quat, m: Mat4): Quat` — Calculates a quaternion from a 4x4 rotation matrix
|
|
324
|
+
- `quat.fromEuler(out: Quat, euler: Euler): Quat` — Creates a quaternion from the given euler
|
|
325
|
+
- `quat.fromDegrees(out: Quat, x: number, y: number, z: number, order: EulerOrder): Quat` — Creates a quaternion from euler angles specified in degrees.
|
|
326
|
+
- `quat.str(a: Quat): string` — Returns a string representation of a quaternion
|
|
327
|
+
- `quat.clone` — Creates a new quat initialized with values from an existing quaternion
|
|
328
|
+
- `quat.fromValues` — Creates a new quat initialized with the given values
|
|
329
|
+
- `quat.copy` — Copy the values from one quat to another
|
|
330
|
+
- `quat.set` — Set the components of a quat to the given values
|
|
331
|
+
- `quat.setAxes` — Sets the specified quaternion with values corresponding to the given
|
|
332
|
+
|
|
333
|
+
**Operations**
|
|
334
|
+
|
|
335
|
+
- `quat.multiply(out: Quat, a: Quat, b: Quat): Quat` — Multiplies two quat's
|
|
336
|
+
- `quat.exp(out: Quat, a: Quat): Quat` — Calculate the exponential of a unit quaternion.
|
|
337
|
+
- `quat.ln(out: Quat, a: Quat): Quat` — Calculate the natural logarithm of a unit quaternion.
|
|
338
|
+
- `quat.pow(out: Quat, a: Quat, b: number): Quat` — Calculate the scalar power of a unit quaternion.
|
|
339
|
+
- `quat.slerp(out: Quat, a: Quat, b: Quat, t: number): Quat` — Performs a spherical linear interpolation between two quat
|
|
340
|
+
- `quat.invert(out: Quat, a: Quat): Quat` — Calculates the inverse of a quat
|
|
341
|
+
- `quat.conjugate(out: Quat, a: Quat): Quat` — Calculates the conjugate of a quat
|
|
342
|
+
- `quat.add` — Adds two quat's
|
|
343
|
+
- `quat.scale` — Scales a quat by a scalar number
|
|
344
|
+
- `quat.dot` — Calculates the dot product of two quat's
|
|
345
|
+
- `quat.lerp` — Performs a linear interpolation between two quat's
|
|
346
|
+
- `quat.length` — Calculates the length of a quat
|
|
347
|
+
- `quat.squaredLength` — Calculates the squared length of a quat
|
|
348
|
+
- `quat.normalize` — Normalize a quat
|
|
349
|
+
- `quat.rotationTo` — Sets a quaternion to represent the shortest rotation from one
|
|
350
|
+
- `quat.sqlerp` — Performs a spherical linear interpolation with two control points
|
|
351
|
+
|
|
352
|
+
**Transform**
|
|
353
|
+
|
|
354
|
+
- `quat.rotateX(out: Quat, a: Quat, rad: number): Quat` — Rotates a quaternion by the given angle about the X axis
|
|
355
|
+
- `quat.rotateY(out: Quat, a: Quat, rad: number): Quat` — Rotates a quaternion by the given angle about the Y axis
|
|
356
|
+
- `quat.rotateZ(out: Quat, a: Quat, rad: number): Quat` — Rotates a quaternion by the given angle about the Z axis
|
|
357
|
+
|
|
358
|
+
**Query**
|
|
359
|
+
|
|
360
|
+
- `quat.getAxisAngle(out_axis: Vec3, q: Quat): number` — Gets the rotation axis and angle for a given
|
|
361
|
+
- `quat.getAngle(a: Quat, b: Quat): number` — Gets the angular distance between two unit quaternions
|
|
362
|
+
- `quat.exactEquals` — Returns whether or not the quaternions have exactly the same elements in the same position (when compared with ===)
|
|
363
|
+
- `quat.equals(a: Quat, b: Quat): boolean` — Returns whether or not the quaternions have approximately the same elements in the same position.
|
|
364
|
+
|
|
365
|
+
**Aliases**
|
|
366
|
+
|
|
367
|
+
- `quat.len = length` — Alias for `length`
|
|
368
|
+
- `quat.sqrLen = squaredLength` — Alias for `squaredLength`
|
|
369
|
+
- `quat.mul = multiply` — Alias for `multiply`
|
|
370
|
+
|
|
371
|
+
<a id="api-math-quat2"></a>
|
|
372
|
+
|
|
373
|
+
### `quat2`
|
|
374
|
+
|
|
375
|
+
```ts
|
|
376
|
+
import { quat2 } from 'math';
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
**Create**
|
|
380
|
+
|
|
381
|
+
- `quat2.create(): Quat2` — Creates a new identity dual quat
|
|
382
|
+
- `quat2.clone(a: Quat2): Quat2` — Creates a new quat initialized with values from an existing quaternion
|
|
383
|
+
- `quat2.fromValues(x1: number, y1: number, z1: number, w1: number, x2: number, y2: number, z2: number, w2: number): Quat2` — Creates a new dual quat initialized with the given values
|
|
384
|
+
- `quat2.fromRotationTranslationValues(x1: number, y1: number, z1: number, w1: number, x2: number, y2: number, z2: number): Quat2` — Creates a new dual quat from the given values (quat and translation)
|
|
385
|
+
- `quat2.fromRotationTranslation(out: Quat2, q: Quat, t: Vec3): Quat2` — Creates a dual quat from a quaternion and a translation
|
|
386
|
+
- `quat2.fromTranslation(out: Quat2, t: Vec3): Quat2` — Creates a dual quat from a translation
|
|
387
|
+
- `quat2.fromRotation(out: Quat2, q: Quat): Quat2` — Creates a dual quat from a quaternion
|
|
388
|
+
- `quat2.fromMat4(out: Quat2, a: Mat4): Quat2` — Creates a new dual quat from a matrix (4x4)
|
|
389
|
+
- `quat2.copy(out: Quat2, a: Quat2): Quat2` — Copy the values from one dual quat to another
|
|
390
|
+
- `quat2.identity(out: Quat2): Quat2` — Set a dual quat to the identity dual quaternion
|
|
391
|
+
- `quat2.set(out: Quat2, x1: number, y1: number, z1: number, w1: number, x2: number, y2: number, z2: number, w2: number): Quat2` — Set the components of a dual quat to the given values
|
|
392
|
+
- `quat2.setReal(out: Quat2, q: Quat): Quat2` — Set the real component of a dual quat to the given quaternion
|
|
393
|
+
- `quat2.setDual(out: Quat2, q: Quat): Quat2` — Set the dual component of a dual quat to the given quaternion
|
|
394
|
+
- `quat2.str(a: Quat2): string` — Returns a string representation of a dual quaternion
|
|
395
|
+
|
|
396
|
+
**Operations**
|
|
397
|
+
|
|
398
|
+
- `quat2.add(out: Quat2, a: Quat2, b: Quat2): Quat2` — Adds two dual quat's
|
|
399
|
+
- `quat2.multiply(out: Quat2, a: Quat2, b: Quat2): Quat2` — Multiplies two dual quat's
|
|
400
|
+
- `quat2.scale(out: Quat2, a: Quat2, b: number): Quat2` — Scales a dual quat by a scalar number
|
|
401
|
+
- `quat2.dot(a: Quat2, b: Quat2): number` — Calculates the dot product of two dual quat's (The dot product of the real parts)
|
|
402
|
+
- `quat2.lerp(out: Quat2, a: Quat2, b: Quat2, t: number): Quat2` — Performs a linear interpolation between two dual quats's
|
|
403
|
+
- `quat2.invert(out: Quat2, a: Quat2): Quat2` — Calculates the inverse of a dual quat. If they are normalized, conjugate is cheaper
|
|
404
|
+
- `quat2.conjugate(out: Quat2, a: Quat2): Quat2` — Calculates the conjugate of a dual quat
|
|
405
|
+
- `quat2.length(a: Quat2): number` — Calculates the length of a dual quat (the length of its real/rotation part)
|
|
406
|
+
- `quat2.squaredLength(a: Quat2): number` — Calculates the squared length of a dual quat (the squared length of its real/rotation part)
|
|
407
|
+
- `quat2.normalize(out: Quat2, a: Quat2): Quat2` — Normalize a dual quat
|
|
408
|
+
|
|
409
|
+
**Transform**
|
|
410
|
+
|
|
411
|
+
- `quat2.translate(out: Quat2, a: Quat2, v: Vec3): Quat2` — Translates a dual quat by the given vector
|
|
412
|
+
- `quat2.rotateX(out: Quat2, a: Quat2, rad: number): Quat2` — Rotates a dual quat around the X axis
|
|
413
|
+
- `quat2.rotateY(out: Quat2, a: Quat2, rad: number): Quat2` — Rotates a dual quat around the Y axis
|
|
414
|
+
- `quat2.rotateZ(out: Quat2, a: Quat2, rad: number): Quat2` — Rotates a dual quat around the Z axis
|
|
415
|
+
- `quat2.rotateByQuatAppend(out: Quat2, a: Quat2, q: Quat): Quat2` — Rotates a dual quat by a given quaternion (a * q)
|
|
416
|
+
- `quat2.rotateByQuatPrepend(out: Quat2, q: Quat, a: Quat2): Quat2` — Rotates a dual quat by a given quaternion (q * a)
|
|
417
|
+
- `quat2.rotateAroundAxis(out: Quat2, a: Quat2, axis: Vec3, rad: number): Quat2` — Rotates a dual quat around a given axis. Does the normalisation automatically
|
|
418
|
+
|
|
419
|
+
**Query**
|
|
420
|
+
|
|
421
|
+
- `quat2.getReal(out: Quat, a: Quat2): Quat` — Gets the real part of a dual quat
|
|
422
|
+
- `quat2.getDual(out: Quat, a: Quat2): Quat` — Gets the dual part of a dual quat
|
|
423
|
+
- `quat2.getTranslation(out: Vec3, a: Quat2): Vec3` — Gets the translation of a normalized dual quat
|
|
424
|
+
- `quat2.exactEquals(a: Quat2, b: Quat2): boolean` — Returns whether or not the dual quaternions have exactly the same elements in the same position (when compared with ===)
|
|
425
|
+
- `quat2.equals(a: Quat2, b: Quat2): boolean` — Returns whether or not the dual quaternions have approximately the same elements in the same position.
|
|
426
|
+
|
|
427
|
+
**Aliases**
|
|
428
|
+
|
|
429
|
+
- `quat2.mul = multiply` — Alias for `multiply`
|
|
430
|
+
- `quat2.len = length` — Alias for `length`
|
|
431
|
+
- `quat2.sqrLen = squaredLength` — Alias for `squaredLength`
|
|
432
|
+
|
|
433
|
+
<a id="api-math-mat2"></a>
|
|
434
|
+
|
|
435
|
+
### `mat2`
|
|
436
|
+
|
|
437
|
+
```ts
|
|
438
|
+
import { mat2 } from 'math';
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
**Create**
|
|
442
|
+
|
|
443
|
+
- `mat2.create(): Mat2` — Creates a new identity mat2
|
|
444
|
+
- `mat2.clone(a: Mat2): Mat2` — Creates a new mat2 initialized with values from an existing matrix
|
|
445
|
+
- `mat2.copy(out: Mat2, a: Mat2): Mat2` — Copy the values from one mat2 to another
|
|
446
|
+
- `mat2.identity(out: Mat2): Mat2` — Set a mat2 to the identity matrix
|
|
447
|
+
- `mat2.fromValues(m00: number, m01: number, m10: number, m11: number): Mat2` — Create a new mat2 with the given values
|
|
448
|
+
- `mat2.set(out: Mat2, m00: number, m01: number, m10: number, m11: number): Mat2` — Set the components of a mat2 to the given values
|
|
449
|
+
- `mat2.fromRotation(out: Mat2, rad: number): Mat2` — Creates a matrix from a given angle
|
|
450
|
+
- `mat2.fromScaling(out: Mat2, v: Vec2): Mat2` — Creates a matrix from a vector scaling
|
|
451
|
+
- `mat2.str(a: Mat2): string` — Returns a string representation of a mat2
|
|
452
|
+
|
|
453
|
+
**Operations**
|
|
454
|
+
|
|
455
|
+
- `mat2.transpose(out: Mat2, a: Mat2): Mat2` — Transpose the values of a mat2
|
|
456
|
+
- `mat2.invert(out: Mat2, a: Mat2): Mat2 | null` — Inverts a mat2
|
|
457
|
+
- `mat2.adjoint(out: Mat2, a: Mat2): Mat2` — Calculates the adjugate of a mat2
|
|
458
|
+
- `mat2.determinant(a: Mat2): number` — Calculates the determinant of a mat2
|
|
459
|
+
- `mat2.multiply(out: Mat2, a: Mat2, b: Mat2): Mat2` — Multiplies two mat2's
|
|
460
|
+
- `mat2.frob(a: Mat2): number` — Returns Frobenius norm of a mat2
|
|
461
|
+
- `mat2.LDU(L: Mat2, D: Mat2, U: Mat2, a: Mat2): [ Mat2, Mat2, Mat2 ]` — Returns L, D and U matrices (Lower triangular, Diagonal and Upper triangular) by factorizing the input matrix
|
|
462
|
+
- `mat2.add(out: Mat2, a: Mat2, b: Mat2): Mat2` — Adds two mat2's
|
|
463
|
+
- `mat2.subtract(out: Mat2, a: Mat2, b: Mat2): Mat2` — Subtracts matrix b from matrix a
|
|
464
|
+
- `mat2.multiplyScalar(out: Mat2, a: Mat2, b: number): Mat2` — Multiply each element of the matrix by a scalar.
|
|
465
|
+
- `mat2.multiplyScalarAndAdd(out: Mat2, a: Mat2, b: Mat2, scale: number): Mat2` — Adds two mat2's after multiplying each element of the second operand by a scalar value.
|
|
466
|
+
|
|
467
|
+
**Transform**
|
|
468
|
+
|
|
469
|
+
- `mat2.rotate(out: Mat2, a: Mat2, rad: number): Mat2` — Rotates a mat2 by the given angle
|
|
470
|
+
- `mat2.scale(out: Mat2, a: Mat2, v: Vec2): Mat2` — Scales the mat2 by the dimensions in the given vec2
|
|
471
|
+
|
|
472
|
+
**Query**
|
|
473
|
+
|
|
474
|
+
- `mat2.exactEquals(a: Mat2, b: Mat2): boolean` — Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)
|
|
475
|
+
- `mat2.equals(a: Mat2, b: Mat2): boolean` — Returns whether or not the matrices have approximately the same elements in the same position.
|
|
476
|
+
|
|
477
|
+
**Aliases**
|
|
478
|
+
|
|
479
|
+
- `mat2.mul = multiply` — Alias for `multiply`
|
|
480
|
+
- `mat2.sub = subtract` — Alias for `subtract`
|
|
481
|
+
|
|
482
|
+
<a id="api-math-mat2d"></a>
|
|
483
|
+
|
|
484
|
+
### `mat2d`
|
|
485
|
+
|
|
486
|
+
```ts
|
|
487
|
+
import { mat2d } from 'math';
|
|
488
|
+
```
|
|
489
|
+
|
|
490
|
+
**Create**
|
|
491
|
+
|
|
492
|
+
- `mat2d.create(): Mat2d` — Creates a new identity mat2d
|
|
493
|
+
- `mat2d.clone(a: Mat2d): Mat2d` — Creates a new mat2d initialized with values from an existing matrix
|
|
494
|
+
- `mat2d.copy(out: Mat2d, a: Mat2d): Mat2d` — Copy the values from one mat2d to another
|
|
495
|
+
- `mat2d.identity(out: Mat2d): Mat2d` — Set a mat2d to the identity matrix
|
|
496
|
+
- `mat2d.fromValues(a: number, b: number, c: number, d: number, tx: number, ty: number): Mat2d` — Create a new mat2d with the given values
|
|
497
|
+
- `mat2d.set(out: Mat2d, a: number, b: number, c: number, d: number, tx: number, ty: number): Mat2d` — Set the components of a mat2d to the given values
|
|
498
|
+
- `mat2d.fromRotation(out: Mat2d, rad: number): Mat2d` — Creates a matrix from a given angle
|
|
499
|
+
- `mat2d.fromScaling(out: Mat2d, v: Vec2): Mat2d` — Creates a matrix from a vector scaling
|
|
500
|
+
- `mat2d.fromTranslation(out: Mat2d, v: Vec2): Mat2d` — Creates a matrix from a vector translation
|
|
501
|
+
- `mat2d.str(a: Mat2d): string` — Returns a string representation of a mat2d
|
|
502
|
+
|
|
503
|
+
**Operations**
|
|
504
|
+
|
|
505
|
+
- `mat2d.invert(out: Mat2d, a: Mat2d): Mat2d | null` — Inverts a mat2d
|
|
506
|
+
- `mat2d.determinant(a: Mat2d): number` — Calculates the determinant of a mat2d
|
|
507
|
+
- `mat2d.multiply(out: Mat2d, a: Mat2d, b: Mat2d): Mat2d` — Multiplies two mat2d's
|
|
508
|
+
- `mat2d.frob(a: Mat2d): number` — Returns Frobenius norm of a mat2d
|
|
509
|
+
- `mat2d.add(out: Mat2d, a: Mat2d, b: Mat2d): Mat2d` — Adds two mat2d's
|
|
510
|
+
- `mat2d.subtract(out: Mat2d, a: Mat2d, b: Mat2d): Mat2d` — Subtracts matrix b from matrix a
|
|
511
|
+
- `mat2d.multiplyScalar(out: Mat2d, a: Mat2d, b: number): Mat2d` — Multiply each element of the matrix by a scalar.
|
|
512
|
+
- `mat2d.multiplyScalarAndAdd(out: Mat2d, a: Mat2d, b: Mat2d, scale: number): Mat2d` — Adds two mat2d's after multiplying each element of the second operand by a scalar value.
|
|
513
|
+
|
|
514
|
+
**Transform**
|
|
515
|
+
|
|
516
|
+
- `mat2d.rotate(out: Mat2d, a: Mat2d, rad: number): Mat2d` — Rotates a mat2d by the given angle
|
|
517
|
+
- `mat2d.scale(out: Mat2d, a: Mat2d, v: Vec2): Mat2d` — Scales the mat2d by the dimensions in the given vec2
|
|
518
|
+
- `mat2d.translate(out: Mat2d, a: Mat2d, v: Vec2): Mat2d` — Translates the mat2d by the dimensions in the given vec2
|
|
519
|
+
|
|
520
|
+
**Query**
|
|
521
|
+
|
|
522
|
+
- `mat2d.exactEquals(a: Mat2d, b: Mat2d): boolean` — Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)
|
|
523
|
+
- `mat2d.equals(a: Mat2d, b: Mat2d): boolean` — Returns whether or not the matrices have approximately the same elements in the same position.
|
|
524
|
+
|
|
525
|
+
**Aliases**
|
|
526
|
+
|
|
527
|
+
- `mat2d.mul = multiply` — Alias for `multiply`
|
|
528
|
+
- `mat2d.sub = subtract` — Alias for `subtract`
|
|
529
|
+
|
|
530
|
+
<a id="api-math-mat3"></a>
|
|
531
|
+
|
|
532
|
+
### `mat3`
|
|
533
|
+
|
|
534
|
+
```ts
|
|
535
|
+
import { mat3 } from 'math';
|
|
536
|
+
```
|
|
537
|
+
|
|
538
|
+
**Create**
|
|
539
|
+
|
|
540
|
+
- `mat3.create(): Mat3` — Creates a new identity mat3
|
|
541
|
+
- `mat3.fromMat4(out: Mat3, a: Mat4): Mat3` — Copies the upper-left 3x3 values into the given mat3.
|
|
542
|
+
- `mat3.clone(a: Mat3): Mat3` — Creates a new mat3 initialized with values from an existing matrix
|
|
543
|
+
- `mat3.copy(out: Mat3, a: Mat3): Mat3` — Copy the values from one mat3 to another
|
|
544
|
+
- `mat3.fromValues(m00: number, m01: number, m02: number, m10: number, m11: number, m12: number, m20: number, m21: number, m22: number): Mat3` — Create a new mat3 with the given values
|
|
545
|
+
- `mat3.set(out: Mat3, m00: number, m01: number, m02: number, m10: number, m11: number, m12: number, m20: number, m21: number, m22: number): Mat3` — Set the components of a mat3 to the given values
|
|
546
|
+
- `mat3.identity(out: Mat3): Mat3` — Set a mat3 to the identity matrix
|
|
547
|
+
- `mat3.zero(out: Mat3): Mat3` — Set a mat3 to the zero matrix
|
|
548
|
+
- `mat3.fromTranslation(out: Mat3, v: Vec2): Mat3` — Creates a matrix from a vector translation
|
|
549
|
+
- `mat3.fromRotation(out: Mat3, rad: number): Mat3` — Creates a matrix from a given angle
|
|
550
|
+
- `mat3.fromScaling(out: Mat3, v: Vec2): Mat3` — Creates a matrix from a vector scaling
|
|
551
|
+
- `mat3.fromMat2d(out: Mat3, a: Mat2d): Mat3` — Copies the values from a mat2d into a mat3
|
|
552
|
+
- `mat3.fromQuat(out: Mat3, q: Quat): Mat3` — Calculates a 3x3 matrix from the given quaternion
|
|
553
|
+
- `mat3.projection(out: Mat3, width: number, height: number): Mat3` — Generates a 2D projection matrix with the given bounds
|
|
554
|
+
- `mat3.str(a: Mat3): string` — Returns a string representation of a mat3
|
|
555
|
+
|
|
556
|
+
**Operations**
|
|
557
|
+
|
|
558
|
+
- `mat3.transpose(out: Mat3, a: Mat3): Mat3` — Transpose the values of a mat3
|
|
559
|
+
- `mat3.invert(out: Mat3, a: Mat3): Mat3 | null` — Inverts a mat3
|
|
560
|
+
- `mat3.adjoint(out: Mat3, a: Mat3): Mat3` — Calculates the adjugate of a mat3
|
|
561
|
+
- `mat3.determinant(a: Mat3): number` — Calculates the determinant of a mat3
|
|
562
|
+
- `mat3.multiply(out: Mat3, a: Mat3, b: Mat3): Mat3` — Multiplies two mat3's
|
|
563
|
+
- `mat3.normalFromMat4(out: Mat3, a: Mat4): Mat3 | null` — Calculates a 3x3 normal matrix (transpose inverse) from the 4x4 matrix
|
|
564
|
+
- `mat3.frob(a: Mat3): number` — Returns Frobenius norm of a mat3
|
|
565
|
+
- `mat3.add(out: Mat3, a: Mat3, b: Mat3): Mat3` — Adds two mat3's
|
|
566
|
+
- `mat3.subtract(out: Mat3, a: Mat3, b: Mat3): Mat3` — Subtracts matrix b from matrix a
|
|
567
|
+
- `mat3.multiplyScalar(out: Mat3, a: Mat3, b: number): Mat3` — Multiply each element of the matrix by a scalar.
|
|
568
|
+
- `mat3.multiplyScalarAndAdd(out: Mat3, a: Mat3, b: Mat3, scale: number): Mat3` — Adds two mat3's after multiplying each element of the second operand by a scalar value.
|
|
569
|
+
|
|
570
|
+
**Transform**
|
|
571
|
+
|
|
572
|
+
- `mat3.translate(out: Mat3, a: Mat3, v: Vec2): Mat3` — Translate a mat3 by the given vector
|
|
573
|
+
- `mat3.rotate(out: Mat3, a: Mat3, rad: number): Mat3` — Rotates a mat3 by the given angle
|
|
574
|
+
- `mat3.scale(out: Mat3, a: Mat3, v: Vec2): Mat3` — Scales the mat3 by the dimensions in the given vec2
|
|
575
|
+
|
|
576
|
+
**Query**
|
|
577
|
+
|
|
578
|
+
- `mat3.exactEquals(a: Mat3, b: Mat3): boolean` — Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)
|
|
579
|
+
- `mat3.equals(a: Mat3, b: Mat3): boolean` — Returns whether or not the matrices have approximately the same elements in the same position.
|
|
580
|
+
|
|
581
|
+
**Aliases**
|
|
582
|
+
|
|
583
|
+
- `mat3.mul = multiply` — Alias for `multiply`
|
|
584
|
+
- `mat3.sub = subtract` — Alias for `subtract`
|
|
585
|
+
|
|
586
|
+
<a id="api-math-mat4"></a>
|
|
587
|
+
|
|
588
|
+
### `mat4`
|
|
589
|
+
|
|
590
|
+
```ts
|
|
591
|
+
import { mat4 } from 'math';
|
|
592
|
+
```
|
|
593
|
+
|
|
594
|
+
**Create**
|
|
595
|
+
|
|
596
|
+
- `mat4.create(): Mat4` — Creates a new identity mat4
|
|
597
|
+
- `mat4.clone(a: Mat4): Mat4` — Creates a new mat4 initialized with values from an existing matrix
|
|
598
|
+
- `mat4.copy(out: Mat4, a: Mat4): Mat4` — Copy the values from one mat4 to another
|
|
599
|
+
- `mat4.fromValues(m00: number, m01: number, m02: number, m03: number, m10: number, m11: number, m12: number, m13: number, m20: number, m21: number, m22: number, m23: number, m30: number, m31: number, m32: number, m33: number): Mat4` — Create a new mat4 with the given values
|
|
600
|
+
- `mat4.set(out: Mat4, m00: number, m01: number, m02: number, m03: number, m10: number, m11: number, m12: number, m13: number, m20: number, m21: number, m22: number, m23: number, m30: number, m31: number, m32: number, m33: number): Mat4` — Set the components of a mat4 to the given values
|
|
601
|
+
- `mat4.identity(out: Mat4): Mat4` — Set a mat4 to the identity matrix
|
|
602
|
+
- `mat4.zero(out: Mat4): Mat4` — Set a mat4 to the zero matrix
|
|
603
|
+
- `mat4.fromTranslation(out: Mat4, v: Vec3): Mat4` — Creates a matrix from a vector translation
|
|
604
|
+
- `mat4.fromScaling(out: Mat4, v: Vec3): Mat4` — Creates a matrix from a vector scaling
|
|
605
|
+
- `mat4.fromRotation(out: Mat4, rad: number, axis: Vec3): Mat4 | null` — Creates a matrix from a given angle around a given axis
|
|
606
|
+
- `mat4.fromXRotation(out: Mat4, rad: number): Mat4` — Creates a matrix from the given angle around the X axis
|
|
607
|
+
- `mat4.fromYRotation(out: Mat4, rad: number): Mat4` — Creates a matrix from the given angle around the Y axis
|
|
608
|
+
- `mat4.fromZRotation(out: Mat4, rad: number): Mat4` — Creates a matrix from the given angle around the Z axis
|
|
609
|
+
- `mat4.fromRotationTranslation(out: Mat4, q: Quat | Quat2, v: Vec3): Mat4` — Creates a matrix from a quaternion rotation and vector translation
|
|
610
|
+
- `mat4.fromQuat2(out: Mat4, a: Quat2): Mat4` — Creates a new mat4 from a dual quat.
|
|
611
|
+
- `mat4.fromRotationTranslationScale(out: Mat4, q: Quat, v: Vec3, s: Vec3): Mat4` — Creates a matrix from a quaternion rotation, vector translation and vector scale
|
|
612
|
+
- `mat4.fromRotationTranslationScaleOrigin(out: Mat4, q: Quat, v: Vec3, s: Vec3, o: Vec3): Mat4` — Creates a matrix from a quaternion rotation, vector translation and vector scale, rotating and scaling around the given origin
|
|
613
|
+
- `mat4.fromQuat(out: Mat4, q: Quat): Mat4` — Calculates a 4x4 matrix from the given quaternion
|
|
614
|
+
- `mat4.frustumNO(out: Mat4, left: number, right: number, bottom: number, top: number, near: number, far: number): Mat4` — Generates a frustum matrix with the given bounds.
|
|
615
|
+
- `mat4.frustumZO(out: Mat4, left: number, right: number, bottom: number, top: number, near: number, far: number): Mat4` — Generates a frustum matrix with the given bounds, suitable for WebGPU.
|
|
616
|
+
- `mat4.perspectiveNO(out: Mat4, fovy: number, aspect: number, near: number, far: number): Mat4` — Generates a perspective projection matrix with the given bounds.
|
|
617
|
+
- `mat4.perspectiveZO(out: Mat4, fovy: number, aspect: number, near: number, far: number): Mat4` — Generates a perspective projection matrix suitable for WebGPU with the given bounds.
|
|
618
|
+
- `mat4.perspectiveFromFieldOfViewNO(out: Mat4, fov: { upDegrees: number; downDegrees: number; leftDegrees: number; rightDegrees: number; }, near: number, far: number): Mat4` — Generates a perspective projection matrix with the given field of view.
|
|
619
|
+
- `mat4.perspectiveFromFieldOfViewZO(out: Mat4, fov: { upDegrees: number; downDegrees: number; leftDegrees: number; rightDegrees: number; }, near: number, far: number): Mat4` — Generates a perspective projection matrix with the given field of view, suitable for WebGPU.
|
|
620
|
+
- `mat4.orthoNO(out: Mat4, left: number, right: number, bottom: number, top: number, near: number, far: number): Mat4` — Generates a orthogonal projection matrix with the given bounds.
|
|
621
|
+
- `mat4.orthoZO(out: Mat4, left: number, right: number, bottom: number, top: number, near: number, far: number): Mat4` — Generates a orthogonal projection matrix with the given bounds.
|
|
622
|
+
- `mat4.lookAt(out: Mat4, eye: Vec3, center: Vec3, up: Vec3): Mat4` — Generates a look-at matrix with the given eye position, focal point, and up axis.
|
|
623
|
+
- `mat4.targetTo(out: Mat4, eye: Vec3, target: Vec3, up: Vec3): Mat4` — Generates a matrix that makes something look at something else.
|
|
624
|
+
- `mat4.str(a: Mat4): string` — Returns a string representation of a mat4
|
|
625
|
+
|
|
626
|
+
**Operations**
|
|
627
|
+
|
|
628
|
+
- `mat4.transpose(out: Mat4, a: Mat4): Mat4` — Transpose the values of a mat4
|
|
629
|
+
- `mat4.invert(out: Mat4, a: Mat4): Mat4 | null` — Inverts a mat4
|
|
630
|
+
- `mat4.invert3x3(out: Mat4, a: Mat4): Mat4 | null` — Inverts only the 3x3 rotation part of a mat4.
|
|
631
|
+
- `mat4.adjoint(out: Mat4, a: Mat4): Mat4` — Calculates the adjugate of a mat4
|
|
632
|
+
- `mat4.determinant(a: Mat4): number` — Calculates the determinant of a mat4
|
|
633
|
+
- `mat4.multiply(out: Mat4, a: Mat4, b: Mat4): Mat4` — Multiplies two mat4s
|
|
634
|
+
- `mat4.multiply3x3(out: Mat4, a: Mat4, b: Mat4): Mat4` — Multiplies two mat4s treating them as 3x3 rotation matrices.
|
|
635
|
+
- `mat4.multiply3x3RightTransposed(out: Mat4, a: Mat4, b: Mat4): Mat4` — Multiplies a mat4 by the transpose of another mat4
|
|
636
|
+
- `mat4.multiply3x3TransposedVec(out: Vec3, mat: Mat4, vec: Vec3): Vec3` — Transform a Vec3 by the transpose of the 3x3 rotation part.
|
|
637
|
+
- `mat4.multiply3x3Vec(out: Vec3, mat: Mat4, vec: Vec3): Vec3` — Transform a Vec3 by only the 3x3 rotation part of a Mat4.
|
|
638
|
+
- `mat4.decompose(out_r: Quat, out_t: Vec3, out_s: Vec3, mat: Mat4): Quat` — Decomposes a transformation matrix into its rotation, translation
|
|
639
|
+
- `mat4.frob(a: Mat4): number` — Returns Frobenius norm of a mat4
|
|
640
|
+
- `mat4.add(out: Mat4, a: Mat4, b: Mat4): Mat4` — Adds two mat4's
|
|
641
|
+
- `mat4.subtract(out: Mat4, a: Mat4, b: Mat4): Mat4` — Subtracts matrix b from matrix a
|
|
642
|
+
- `mat4.multiplyScalar(out: Mat4, a: Mat4, b: number): Mat4` — Multiply each element of the matrix by a scalar.
|
|
643
|
+
- `mat4.multiplyScalarAndAdd(out: Mat4, a: Mat4, b: Mat4, scale: number): Mat4` — Adds two mat4's after multiplying each element of the second operand by a scalar value.
|
|
644
|
+
|
|
645
|
+
**Transform**
|
|
646
|
+
|
|
647
|
+
- `mat4.crossProductMatrix(out: Mat4, v: Vec3): Mat4` — Cross product matrix (skew-symmetric matrix).
|
|
648
|
+
- `mat4.translate(out: Mat4, a: Mat4, v: Vec3): Mat4` — Translate a mat4 by the given vector
|
|
649
|
+
- `mat4.scale(out: Mat4, a: Mat4, v: Vec3): Mat4` — Scales the mat4 by the dimensions in the given vec3 not using vectorization
|
|
650
|
+
- `mat4.rotate(out: Mat4, a: Mat4, rad: number, axis: Vec3): Mat4 | null` — Rotates a mat4 by the given angle around the given axis
|
|
651
|
+
- `mat4.rotateX(out: Mat4, a: Mat4, rad: number): Mat4` — Rotates a matrix by the given angle around the X axis
|
|
652
|
+
- `mat4.rotateY(out: Mat4, a: Mat4, rad: number): Mat4` — Rotates a matrix by the given angle around the Y axis
|
|
653
|
+
- `mat4.rotateZ(out: Mat4, a: Mat4, rad: number): Mat4` — Rotates a matrix by the given angle around the Z axis
|
|
654
|
+
|
|
655
|
+
**Query**
|
|
656
|
+
|
|
657
|
+
- `mat4.getTranslation(out: Vec3, mat: Mat4): Vec3` — Returns the translation vector component of a transformation
|
|
658
|
+
- `mat4.getScaling(out: Vec3, mat: Mat4): Vec3` — Returns the scaling factor component of a transformation
|
|
659
|
+
- `mat4.getRotation(out: Quat, mat: Mat4): Quat` — Returns a quaternion representing the rotational component
|
|
660
|
+
- `mat4.exactEquals(a: Mat4, b: Mat4): boolean` — Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)
|
|
661
|
+
- `mat4.equals(a: Mat4, b: Mat4): boolean` — Returns whether or not the matrices have approximately the same elements in the same position.
|
|
662
|
+
|
|
663
|
+
**Aliases**
|
|
664
|
+
|
|
665
|
+
- `mat4.mul = multiply` — Alias for `multiply`
|
|
666
|
+
- `mat4.sub = subtract` — Alias for `subtract`
|
|
667
|
+
|
|
668
|
+
<a id="api-math-spherical"></a>
|
|
669
|
+
|
|
670
|
+
### `spherical`
|
|
671
|
+
|
|
672
|
+
```ts
|
|
673
|
+
import { spherical } from 'math';
|
|
674
|
+
```
|
|
675
|
+
|
|
676
|
+
**Create**
|
|
677
|
+
|
|
678
|
+
- `spherical.create(): Spherical` — Creates a new spherical coordinate at r=1, theta=0, phi=0
|
|
679
|
+
- `spherical.fromValues(r: number, theta: number, phi: number): Spherical` — Creates a new Spherical initialized with the given values
|
|
680
|
+
- `spherical.clone(a: Spherical): Spherical` — Creates a new Spherical initialized with values from an existing one
|
|
681
|
+
- `spherical.copy(out: Spherical, a: Spherical): Spherical` — Copies values from one Spherical to another
|
|
682
|
+
- `spherical.set(out: Spherical, r: number, theta: number, phi: number): Spherical` — Sets the components of a Spherical
|
|
683
|
+
- `spherical.setFromVec3(out: Spherical, v: Vec3): Spherical` — Sets a Spherical from Cartesian Vec3 coordinates (Three.js / OpenGL convention)
|
|
684
|
+
- `spherical.makeSafe(out: Spherical, a: Spherical): Spherical` — Clamps phi to the range [EPSILON, π - EPSILON] to avoid coordinate
|
|
685
|
+
- `spherical.toVec3(out: Vec3, a: Spherical): Vec3` — Converts spherical coordinates to a Cartesian Vec3 (Three.js / OpenGL convention)
|
|
686
|
+
- `spherical.fromVec2(out: Spherical, v: Vec2): Spherical` — Converts a Vec2 (x, z) in the horizontal XZ plane to spherical coordinates.
|
|
687
|
+
- `spherical.toVec2(out: Vec2, a: Spherical): Vec2` — Projects spherical coordinates onto the XZ plane, returning a Vec2 (x, z).
|
|
688
|
+
- `spherical.str(a: Spherical): string` — Returns a string representation of a Spherical
|
|
689
|
+
|
|
690
|
+
**Operations**
|
|
691
|
+
|
|
692
|
+
- `spherical.normalize(out: Spherical, a: Spherical): Spherical` — Sets r=1, preserving the angles. No-op if r is already zero.
|
|
693
|
+
- `spherical.scale(out: Spherical, a: Spherical, s: number): Spherical` — Scales the radial distance r by a scalar
|
|
694
|
+
- `spherical.lerp(out: Spherical, a: Spherical, b: Spherical, t: number): Spherical` — Linearly interpolates between two Spherical coordinates taking the shortest
|
|
695
|
+
|
|
696
|
+
**Query**
|
|
697
|
+
|
|
698
|
+
- `spherical.equals(a: Spherical, b: Spherical): boolean` — Returns true if two Spherical coordinates are approximately equal
|
|
699
|
+
- `spherical.exactEquals(a: Spherical, b: Spherical): boolean` — Returns true if two Spherical coordinates are exactly equal (===).
|
|
700
|
+
- `spherical.angleTo(a: Spherical, b: Spherical): number` — Returns the great-circle angle (in radians) between two spherical coordinates
|
|
701
|
+
|
|
702
|
+
**Aliases**
|
|
703
|
+
|
|
704
|
+
- `spherical.fromVec3 = setFromVec3` — Alias for `setFromVec3`
|
|
705
|
+
|
|
706
|
+
<a id="api-math-polar"></a>
|
|
707
|
+
|
|
708
|
+
### `polar`
|
|
709
|
+
|
|
710
|
+
```ts
|
|
711
|
+
import { polar } from 'math';
|
|
712
|
+
```
|
|
713
|
+
|
|
714
|
+
**Create**
|
|
715
|
+
|
|
716
|
+
- `polar.create(): Polar` — Creates a new polar coordinate at r=1, theta=0
|
|
717
|
+
- `polar.fromValues(r: number, theta: number): Polar` — Creates a new Polar initialized with the given values
|
|
718
|
+
- `polar.clone(a: Polar): Polar` — Creates a new Polar initialized with values from an existing one
|
|
719
|
+
- `polar.copy(out: Polar, a: Polar): Polar` — Copies values from one Polar to another
|
|
720
|
+
- `polar.set(out: Polar, r: number, theta: number): Polar` — Sets the components of a Polar
|
|
721
|
+
- `polar.setFromVec2(out: Polar, v: Vec2): Polar` — Sets a Polar from Cartesian Vec2 coordinates
|
|
722
|
+
- `polar.toVec2(out: Vec2, a: Polar): Vec2` — Converts polar coordinates to a Cartesian Vec2
|
|
723
|
+
- `polar.str(a: Polar): string` — Returns a string representation of a Polar
|
|
724
|
+
|
|
725
|
+
**Operations**
|
|
726
|
+
|
|
727
|
+
- `polar.normalize(out: Polar, a: Polar): Polar` — Sets r=1, preserving the angle. No-op on the angle if r is already zero.
|
|
728
|
+
- `polar.scale(out: Polar, a: Polar, s: number): Polar` — Scales the radial distance r by a scalar
|
|
729
|
+
- `polar.lerp(out: Polar, a: Polar, b: Polar, t: number): Polar` — Linearly interpolates between two Polar coordinates, taking the shortest
|
|
730
|
+
- `polar.distance(a: Polar, b: Polar): number` — Returns the straight-line (chord) distance between two polar coordinates
|
|
731
|
+
|
|
732
|
+
**Transform**
|
|
733
|
+
|
|
734
|
+
- `polar.rotate(out: Polar, a: Polar, rad: number): Polar` — Rotates a Polar by an angle (in radians), wrapping theta into (-pi, pi].
|
|
735
|
+
|
|
736
|
+
**Query**
|
|
737
|
+
|
|
738
|
+
- `polar.angleTo(a: Polar, b: Polar): number` — Returns the smallest angle (in radians) between two polar directions
|
|
739
|
+
- `polar.equals(a: Polar, b: Polar): boolean` — Returns true if two Polar coordinates are approximately equal
|
|
740
|
+
- `polar.exactEquals(a: Polar, b: Polar): boolean` — Returns true if two Polar coordinates are exactly equal (===).
|
|
741
|
+
|
|
742
|
+
**Aliases**
|
|
743
|
+
|
|
744
|
+
- `polar.fromVec2 = setFromVec2` — Alias for `setFromVec2`
|
|
745
|
+
|
|
746
|
+
<a id="api-math-shapes"></a>
|
|
747
|
+
|
|
748
|
+
## `math/shapes`
|
|
749
|
+
|
|
750
|
+
- `type Box2 = [ minX: number, minY: number, maxX: number, maxY: number ]` — An axis-aligned box in 2D space, as [minX, minY, maxX, maxY]
|
|
751
|
+
- `type Box3 = [ minX: number, minY: number, minZ: number, maxX: number, maxY: number, maxZ: number ]` — A box in 3D space
|
|
752
|
+
- `type OBB3 = { center: Vec3; halfExtents: Vec3; rotation: Mat3; }` — An oriented bounding box in 3D space
|
|
753
|
+
- `type Plane3 = { normal: Vec3; constant: number; }` — A plane in 3D space
|
|
754
|
+
- `type Sphere = { center: Vec3; radius: number; }` — A sphere in 3D space
|
|
755
|
+
- `type Circle = { center: Vec2; radius: number; }` — A circle in 2D space
|
|
756
|
+
- `type Frustum = [ Plane3, Plane3, Plane3, Plane3, Plane3, Plane3 ]` — A view frustum, represented as the six bounding planes of a camera's view volume.
|
|
757
|
+
- `type FrustumCorners = [ Vec3, Vec3, Vec3, Vec3, Vec3, Vec3, Vec3, Vec3 ]` — The eight corners of a frustum, as returned by corners.
|
|
758
|
+
|
|
759
|
+
<a id="api-math-shapes-box2"></a>
|
|
760
|
+
|
|
761
|
+
### `box2`
|
|
762
|
+
|
|
763
|
+
```ts
|
|
764
|
+
import { box2 } from 'math/shapes';
|
|
765
|
+
```
|
|
766
|
+
|
|
767
|
+
**Create**
|
|
768
|
+
|
|
769
|
+
- `box2.create(): Box2` — Create a new empty Box2 with "min" set to positive infinity and "max" set to negative infinity
|
|
770
|
+
- `box2.clone(box: Box2): Box2` — Clones a Box2
|
|
771
|
+
- `box2.copy(out: Box2, box: Box2): Box2` — Copies a Box2 to another Box2
|
|
772
|
+
- `box2.set(out: Box2, minX: number, minY: number, maxX: number, maxY: number): Box2` — Sets the min and max values of a Box2
|
|
773
|
+
- `box2.setFromVectors(out: Box2, min: Vec2, max: Vec2): Box2` — Sets the min and max values of a Box2 from Vec2 vectors
|
|
774
|
+
- `box2.setFromCenterAndSize(out: Box2, center: Vec2, size: Vec2): Box2` — Sets the box from a center point and size
|
|
775
|
+
|
|
776
|
+
**Operations**
|
|
777
|
+
|
|
778
|
+
- `box2.min(out: Vec2, box: Box2): Vec2` — Extracts the minimum corner of a Box2
|
|
779
|
+
- `box2.max(out: Vec2, box: Box2): Vec2` — Extracts the maximum corner of a Box2
|
|
780
|
+
- `box2.empty(out: Box2): Box2` — Set a Box2 to empty (min to positive infinity, max to negative infinity)
|
|
781
|
+
- `box2.expandByPoint(out: Box2, box: Box2, point: Vec2): Box2` — Expands a Box2 to include a point
|
|
782
|
+
- `box2.expandByExtents(out: Box2, box: Box2, vector: Vec2): Box2` — Widens a Box2 by a vector on both sides
|
|
783
|
+
- `box2.expandByMargin(out: Box2, box: Box2, margin: number): Box2` — Expands a Box2 uniformly by a scalar margin on all sides
|
|
784
|
+
- `box2.union(out: Box2, boxA: Box2, boxB: Box2): Box2` — Computes the union of two bounding boxes
|
|
785
|
+
- `box2.center(out: Vec2, box: Box2): Vec2` — Calculate the center point of a bounding box
|
|
786
|
+
- `box2.extents(out: Vec2, box: Box2): Vec2` — Calculate the extents (half-size) of a bounding box
|
|
787
|
+
- `box2.size(out: Vec2, box: Box2): Vec2` — Calculate the size (dimensions) of a bounding box
|
|
788
|
+
- `box2.area(box: Box2): number` — Calculate the area of a bounding box
|
|
789
|
+
- `box2.scale(out: Box2, box: Box2, scale: Vec2): Box2` — Scale a bounding box by a vector, handling non-uniform and negative scaling
|
|
790
|
+
|
|
791
|
+
**Query**
|
|
792
|
+
|
|
793
|
+
- `box2.exactEquals(a: Box2, b: Box2): boolean` — Returns whether or not the boxes have exactly the same elements in the same position (when compared with ===)
|
|
794
|
+
- `box2.equals(a: Box2, b: Box2): boolean` — Returns whether or not the boxes have approximately the same elements in the same position
|
|
795
|
+
- `box2.containsPoint(box: Box2, point: Vec2): boolean` — Test if a point is contained within the bounding box
|
|
796
|
+
- `box2.containsBox2(container: Box2, contained: Box2): boolean` — Test if one Box2 completely contains another Box2
|
|
797
|
+
- `box2.intersectsBox2(boxA: Box2, boxB: Box2): boolean` — Check whether two bounding boxes intersect
|
|
798
|
+
- `box2.intersectsCircle(box: Box2, circle: Circle): boolean` — Test intersection between an axis-aligned bounding box and a circle.
|
|
799
|
+
|
|
800
|
+
<a id="api-math-shapes-box3"></a>
|
|
801
|
+
|
|
802
|
+
### `box3`
|
|
803
|
+
|
|
804
|
+
```ts
|
|
805
|
+
import { box3 } from 'math/shapes';
|
|
806
|
+
```
|
|
807
|
+
|
|
808
|
+
**Create**
|
|
809
|
+
|
|
810
|
+
- `box3.create(): Box3` — Create a new empty Box3 with "min" set to positive infinity and "max" set to negative infinity
|
|
811
|
+
- `box3.clone(box: Box3): Box3` — Clones a Box3
|
|
812
|
+
- `box3.copy(out: Box3, box: Box3): Box3` — Copies a Box3 to another Box3
|
|
813
|
+
- `box3.set(out: Box3, minX: number, minY: number, minZ: number, maxX: number, maxY: number, maxZ: number): Box3` — Sets the min and max values of a Box3
|
|
814
|
+
- `box3.setFromVectors(out: Box3, min: Vec3, max: Vec3): Box3` — Sets the min and max values of a Box3 from Vec3 vectors
|
|
815
|
+
- `box3.setFromCenterAndSize(out: Box3, center: Vec3, size: Vec3): Box3` — Sets the box from a center point and size
|
|
816
|
+
|
|
817
|
+
**Operations**
|
|
818
|
+
|
|
819
|
+
- `box3.min(out: Vec3, box: Box3): Vec3` — Extracts the minimum corner of a Box3
|
|
820
|
+
- `box3.max(out: Vec3, box: Box3): Vec3` — Extracts the maximum corner of a Box3
|
|
821
|
+
- `box3.empty(out: Box3): Box3` — Set a Box3 to empty (min to positive infinity, max to negative infinity)
|
|
822
|
+
- `box3.expandByPoint(out: Box3, box: Box3, point: Vec3): Box3` — Expands a Box3 to include a point
|
|
823
|
+
- `box3.expandByExtents(out: Box3, box: Box3, vector: Vec3): Box3` — Widens a Box3 by a vector on both sides
|
|
824
|
+
- `box3.expandByMargin(out: Box3, box: Box3, margin: number): Box3` — Expands a Box3 uniformly by a scalar margin on all sides
|
|
825
|
+
- `box3.union(out: Box3, boxA: Box3, boxB: Box3): Box3` — Computes the union of two bounding boxes
|
|
826
|
+
- `box3.center(out: Vec3, box: Box3): Vec3` — Calculate the center point of a bounding box
|
|
827
|
+
- `box3.extents(out: Vec3, box: Box3): Vec3` — Calculate the extents (half-size) of a bounding box
|
|
828
|
+
- `box3.size(out: Vec3, box: Box3): Vec3` — Calculate the size (dimensions) of a bounding box
|
|
829
|
+
- `box3.surfaceArea(box: Box3): number` — Calculate the surface area of a bounding box
|
|
830
|
+
- `box3.scale(out: Box3, box: Box3, scale: Vec3): Box3` — Scale a bounding box by a vector, handling non-uniform and negative scaling
|
|
831
|
+
|
|
832
|
+
**Transform**
|
|
833
|
+
|
|
834
|
+
- `box3.transformMat4(out: Box3, box: Box3, mat: Mat4): Box3` — Transform a bounding box by a 4x4 matrix.
|
|
835
|
+
|
|
836
|
+
**Query**
|
|
837
|
+
|
|
838
|
+
- `box3.exactEquals(a: Box3, b: Box3): boolean` — Returns whether or not the boxes have exactly the same elements in the same position (when compared with ===)
|
|
839
|
+
- `box3.equals(a: Box3, b: Box3): boolean` — Returns whether or not the boxes have approximately the same elements in the same position
|
|
840
|
+
- `box3.containsPoint(box: Box3, point: Vec3): boolean` — Test if a point is contained within the bounding box
|
|
841
|
+
- `box3.containsBox3(container: Box3, contained: Box3): boolean` — Test if one Box3 completely contains another Box3
|
|
842
|
+
- `box3.intersectsBox3(boxA: Box3, boxB: Box3): boolean` — Check whether two bounding boxes intersect
|
|
843
|
+
- `box3.intersectsTriangle3(box: Box3, a: Vec3, b: Vec3, c: Vec3): boolean` — Test whether an axis-aligned bounding box intersects a triangle, via the
|
|
844
|
+
- `box3.intersectsSphere(box: Box3, sphere: Sphere): boolean` — Test intersection between axis-aligned bounding box and a sphere.
|
|
845
|
+
- `box3.intersectsPlane3(box: Box3, plane: Plane3): boolean` — Test intersection between axis-aligned bounding box and plane.
|
|
846
|
+
|
|
847
|
+
<a id="api-math-shapes-obb3"></a>
|
|
848
|
+
|
|
849
|
+
### `obb3`
|
|
850
|
+
|
|
851
|
+
```ts
|
|
852
|
+
import { obb3 } from 'math/shapes';
|
|
853
|
+
```
|
|
854
|
+
|
|
855
|
+
**Create**
|
|
856
|
+
|
|
857
|
+
- `obb3.create(): OBB3`
|
|
858
|
+
- `obb3.clone(a: OBB3): OBB3`
|
|
859
|
+
- `obb3.copy(out: OBB3, a: OBB3): OBB3`
|
|
860
|
+
- `obb3.set(out: OBB3, center: Vec3, halfExtents: Vec3, rotation: Mat3): OBB3` — Sets an OBB from center, half extents, and a rotation matrix.
|
|
861
|
+
- `obb3.setFromCenterHalfExtentsQuaternion(out: OBB3, center: Vec3, halfExtents: Vec3, q: Quat): OBB3` — Sets an OBB from center, half extents, and a quaternion.
|
|
862
|
+
- `obb3.setFromBox3(out: OBB3, aabb: Box3): OBB3` — Creates an OBB from an axis-aligned bounding box (AABB).
|
|
863
|
+
|
|
864
|
+
**Operations**
|
|
865
|
+
|
|
866
|
+
- `obb3.clampPoint(out: Vec3, obb: OBB3, point: Vec3): Vec3` — Clamps a point to the surface or interior of an OBB.
|
|
867
|
+
|
|
868
|
+
**Transform**
|
|
869
|
+
|
|
870
|
+
- `obb3.applyMatrix4(out: OBB3, obb: OBB3, matrix: Mat4): OBB3` — Applies a 4x4 transformation matrix to an OBB.
|
|
871
|
+
|
|
872
|
+
**Query**
|
|
873
|
+
|
|
874
|
+
- `obb3.containsPoint(obb: OBB3, point: Vec3): boolean` — Tests whether a point is contained within an OBB.
|
|
875
|
+
- `obb3.intersectsOBB3(a: OBB3, b: OBB3, epsilon = EPSILON): boolean` — Tests whether an OBB intersects with another OBB using the Separating Axis Theorem.
|
|
876
|
+
- `obb3.intersectsBox3(obb: OBB3, aabb: Box3): boolean` — Tests whether an OBB intersects with an AABB.
|
|
877
|
+
|
|
878
|
+
<a id="api-math-shapes-plane3"></a>
|
|
879
|
+
|
|
880
|
+
### `plane3`
|
|
881
|
+
|
|
882
|
+
```ts
|
|
883
|
+
import { plane3 } from 'math/shapes';
|
|
884
|
+
```
|
|
885
|
+
|
|
886
|
+
**Create**
|
|
887
|
+
|
|
888
|
+
- `plane3.create(): Plane3` — Creates a new plane with normal (0, 1, 0) and constant 0
|
|
889
|
+
- `plane3.fromNormalAndConstant(out: Plane3, normal: Vec3, constant: number): Plane3` — Creates a plane from a normal and constant
|
|
890
|
+
- `plane3.fromNormalAndPoint(out: Plane3, normal: Vec3, point: Vec3): Plane3` — Creates a plane from a normal and a point on the plane
|
|
891
|
+
- `plane3.fromCoplanarPoints(out: Plane3, a: Vec3, b: Vec3, c: Vec3): Plane3` — Creates a plane from three coplanar points
|
|
892
|
+
- `plane3.clone(plane: Plane3): Plane3` — Clones a plane
|
|
893
|
+
- `plane3.copy(out: Plane3, plane: Plane3): Plane3` — Copies one plane to another
|
|
894
|
+
|
|
895
|
+
**Operations**
|
|
896
|
+
|
|
897
|
+
- `plane3.normalize(out: Plane3, plane: Plane3): Plane3` — Normalizes a plane (ensures the normal vector is unit length)
|
|
898
|
+
- `plane3.negate(out: Plane3, plane: Plane3): Plane3` — Negates a plane (flips the normal and constant)
|
|
899
|
+
- `plane3.offset(out: Plane3, plane: Plane3, distance: number): Plane3` — Offsets a plane by a distance along its normal
|
|
900
|
+
- `plane3.distanceToPoint(plane: Plane3, point: Vec3): number` — Calculates the signed distance from a point to the plane
|
|
901
|
+
- `plane3.projectPoint(out: Vec3, plane: Plane3, point: Vec3): Vec3` — Projects a point onto the plane
|
|
902
|
+
- `plane3.intersect(out: Vec3, p1: Plane3, p2: Plane3, p3: Plane3): boolean` — Finds the intersection point of three planes
|
|
903
|
+
|
|
904
|
+
**Transform**
|
|
905
|
+
|
|
906
|
+
- `plane3.transform(out: Plane3, plane: Plane3, matrix: Mat4): Plane3` — Transforms a plane by a 4x4 matrix
|
|
907
|
+
|
|
908
|
+
**Query**
|
|
909
|
+
|
|
910
|
+
- `plane3.intersectsSphere(plane: Plane3, sphere: Sphere): boolean` — Tests if a sphere intersects the plane
|
|
911
|
+
- `plane3.exactEquals(a: Plane3, b: Plane3): boolean` — Tests if two planes are exactly equal
|
|
912
|
+
- `plane3.equals(a: Plane3, b: Plane3): boolean` — Tests if two planes are equal
|
|
913
|
+
|
|
914
|
+
<a id="api-math-shapes-sphere"></a>
|
|
915
|
+
|
|
916
|
+
### `sphere`
|
|
917
|
+
|
|
918
|
+
```ts
|
|
919
|
+
import { sphere } from 'math/shapes';
|
|
920
|
+
```
|
|
921
|
+
|
|
922
|
+
**Create**
|
|
923
|
+
|
|
924
|
+
- `sphere.create(): Sphere` — Creates a new sphere with a default center 0,0,0 and radius 1
|
|
925
|
+
|
|
926
|
+
**Query**
|
|
927
|
+
|
|
928
|
+
- `sphere.containsPoint(sphere: Sphere, point: Vec3): boolean` — Returns true if a point lies inside (or on the surface of) the sphere.
|
|
929
|
+
|
|
930
|
+
<a id="api-math-shapes-circle"></a>
|
|
931
|
+
|
|
932
|
+
### `circle`
|
|
933
|
+
|
|
934
|
+
```ts
|
|
935
|
+
import { circle } from 'math/shapes';
|
|
936
|
+
```
|
|
937
|
+
|
|
938
|
+
- `circle.create(): Circle`
|
|
939
|
+
|
|
940
|
+
<a id="api-math-shapes-segment2"></a>
|
|
941
|
+
|
|
942
|
+
### `segment2`
|
|
943
|
+
|
|
944
|
+
```ts
|
|
945
|
+
import { segment2 } from 'math/shapes';
|
|
946
|
+
```
|
|
947
|
+
|
|
948
|
+
- `segment2.closestPoint(out: Vec2, point: Vec2, a: Vec2, b: Vec2): Vec2` — Calculates the closest point on a line segment to a given point
|
|
949
|
+
- `segment2.intersects(a: Vec2, b: Vec2, c: Vec2, d: Vec2): boolean` — Tests whether the two closed segments a-b and c-d intersect. Collinear
|
|
950
|
+
- `segment2.intersection(out: Vec2, a: Vec2, b: Vec2, c: Vec2, d: Vec2): Vec2 | null` — Computes the intersection point of the two closed segments a-b and c-d
|
|
951
|
+
|
|
952
|
+
<a id="api-math-shapes-polygon2"></a>
|
|
953
|
+
|
|
954
|
+
### `polygon2`
|
|
955
|
+
|
|
956
|
+
```ts
|
|
957
|
+
import { polygon2 } from 'math/shapes';
|
|
958
|
+
```
|
|
959
|
+
|
|
960
|
+
**Operations**
|
|
961
|
+
|
|
962
|
+
- `polygon2.signedArea(vertices: number[], n: number): number` — Returns the signed area of the polygon using the shoelace formula.
|
|
963
|
+
- `polygon2.area(vertices: number[], n: number): number` — Returns the (non-negative) area of the polygon.
|
|
964
|
+
- `polygon2.centroid(out: Vec2, vertices: number[], n: number): Vec2` — Computes the area-weighted centroid (center of mass) of the polygon.
|
|
965
|
+
- `polygon2.perimeter(vertices: number[], n: number): number` — Returns the perimeter (sum of edge lengths) of the polygon.
|
|
966
|
+
- `polygon2.winding(vertices: number[], n: number): number` — Returns the winding order of the polygon from the sign of its signed area
|
|
967
|
+
- `polygon2.reverse(out: number[], vertices: number[], n: number): number[]` — Reverses the winding order of the polygon, writing the result into `out`.
|
|
968
|
+
- `polygon2.bounds(out: Box2, vertices: number[], n: number): Box2` — Writes the axis-aligned bounding box of the polygon into `out` as a Box2
|
|
969
|
+
- `polygon2.closestPoint(out: Vec2, vertices: number[], n: number, point: Vec2): Vec2` — Finds the point on the polygon's boundary closest to `point` and writes it to
|
|
970
|
+
- `polygon2.signedDistance(vertices: number[], n: number, point: Vec2): number` — Returns the distance from `point` to the polygon's boundary, signed so that
|
|
971
|
+
- `polygon2.overlapConvex(verticesA: number[], numA: number, verticesB: number[], numB: number): boolean` — Tests whether two convex polygons overlap, using the separating axis theorem.
|
|
972
|
+
|
|
973
|
+
**Query**
|
|
974
|
+
|
|
975
|
+
- `polygon2.containsPoint(vertices: number[], n: number, point: Vec2): boolean` — Tests whether a point lies inside the polygon. Works for both convex and
|
|
976
|
+
- `polygon2.isConvex(vertices: number[], n: number): boolean` — Tests whether the polygon is convex. Works for both winding orders. Assumes a
|
|
977
|
+
- `polygon2.isReflexVertex(vertices: number[], n: number, i: number): boolean` — Tests whether vertex `i` is a reflex (concave) vertex of the polygon — the
|
|
978
|
+
- `polygon2.intersectsSegment(vertices: number[], n: number, a: Vec2, b: Vec2): boolean` — Tests whether the segment `a`-`b` intersects the polygon, i.e. it has an
|
|
979
|
+
|
|
980
|
+
<a id="api-math-shapes-triangle2"></a>
|
|
981
|
+
|
|
982
|
+
### `triangle2`
|
|
983
|
+
|
|
984
|
+
```ts
|
|
985
|
+
import { triangle2 } from 'math/shapes';
|
|
986
|
+
```
|
|
987
|
+
|
|
988
|
+
**Operations**
|
|
989
|
+
|
|
990
|
+
- `triangle2.signedArea(a: Vec2, b: Vec2, c: Vec2): number` — Returns the signed area of the triangle (a, b, c). The result is positive when
|
|
991
|
+
- `triangle2.area(a: Vec2, b: Vec2, c: Vec2): number` — Returns the (non-negative) area of the triangle (a, b, c).
|
|
992
|
+
- `triangle2.centroid(out: Vec2, a: Vec2, b: Vec2, c: Vec2): Vec2` — Computes the centroid of the triangle (a, b, c).
|
|
993
|
+
- `triangle2.bounds(out: Box2, a: Vec2, b: Vec2, c: Vec2): Box2` — Computes the axis-aligned bounding box of the triangle (a, b, c).
|
|
994
|
+
|
|
995
|
+
**Query**
|
|
996
|
+
|
|
997
|
+
- `triangle2.containsPoint(a: Vec2, b: Vec2, c: Vec2, point: Vec2): boolean` — Tests whether a point lies inside the triangle (a, b, c). Works for either
|
|
998
|
+
|
|
999
|
+
<a id="api-math-shapes-triangle3"></a>
|
|
1000
|
+
|
|
1001
|
+
### `triangle3`
|
|
1002
|
+
|
|
1003
|
+
```ts
|
|
1004
|
+
import { triangle3 } from 'math/shapes';
|
|
1005
|
+
```
|
|
1006
|
+
|
|
1007
|
+
- `triangle3.bounds(out: Box3, a: Vec3, b: Vec3, c: Vec3): Box3` — Computes the axis-aligned bounding box of a triangle defined by three vertices.
|
|
1008
|
+
- `triangle3.normal(out: Vec3, a: Vec3, b: Vec3, c: Vec3): Vec3` — Computes the normal vector of a triangle defined by three vertices.
|
|
1009
|
+
- `triangle3.centroid(out: Vec3, a: Vec3, b: Vec3, c: Vec3): Vec3` — Computes the centroid of a triangle defined by three vertices.
|
|
1010
|
+
|
|
1011
|
+
<a id="api-math-shapes-raycast3"></a>
|
|
1012
|
+
|
|
1013
|
+
### `raycast3`
|
|
1014
|
+
|
|
1015
|
+
```ts
|
|
1016
|
+
import { raycast3 } from 'math/shapes';
|
|
1017
|
+
```
|
|
1018
|
+
|
|
1019
|
+
**Types**
|
|
1020
|
+
|
|
1021
|
+
- `type IntersectsTriangleResult = { fraction: number; hit: boolean; frontFacing: boolean; }` — Result of a ray-triangle intersection test
|
|
1022
|
+
|
|
1023
|
+
**Operations**
|
|
1024
|
+
|
|
1025
|
+
- `raycast3.createIntersectsTriangleResult(): IntersectsTriangleResult` — Creates a new IntersectsTriangleResult with default values.
|
|
1026
|
+
|
|
1027
|
+
**Query**
|
|
1028
|
+
|
|
1029
|
+
- `raycast3.intersectsTriangle(out: IntersectsTriangleResult, origin: Vec3, direction: Vec3, length: number, a: Vec3, b: Vec3, c: Vec3, backfaceCulling: boolean): void` — Ray-triangle intersection test.
|
|
1030
|
+
- `raycast3.intersectsBox3(origin: Vec3, direction: Vec3, length: number, aabb: Box3): boolean` — Test if a ray intersects an axis-aligned bounding box.
|
|
1031
|
+
|
|
1032
|
+
<a id="api-math-shapes-frustum"></a>
|
|
1033
|
+
|
|
1034
|
+
### `frustum`
|
|
1035
|
+
|
|
1036
|
+
```ts
|
|
1037
|
+
import { frustum } from 'math/shapes';
|
|
1038
|
+
```
|
|
1039
|
+
|
|
1040
|
+
**Create**
|
|
1041
|
+
|
|
1042
|
+
- `frustum.create(): Frustum` — Creates a new frustum of zeroed planes.
|
|
1043
|
+
- `frustum.clone(f: Frustum): Frustum` — Clones a frustum.
|
|
1044
|
+
- `frustum.copy(out: Frustum, f: Frustum): Frustum` — Copies one frustum to another.
|
|
1045
|
+
- `frustum.setFromViewProjectionMatrixNO(out: Frustum, proj: Mat4, view: Mat4): Frustum` — Extracts the six planes of a view frustum from a projection and view matrix, using the
|
|
1046
|
+
- `frustum.setFromViewProjectionMatrixZO(out: Frustum, proj: Mat4, view: Mat4): Frustum` — Extracts the six planes of a view frustum from a projection and view matrix, using the
|
|
1047
|
+
- `frustum.setFromViewProjectionMatrixSides(out: Frustum, proj: Mat4, view: Mat4): Frustum` — Extracts only the four lateral planes (left, right, bottom, top) of a view frustum from a
|
|
1048
|
+
|
|
1049
|
+
**Operations**
|
|
1050
|
+
|
|
1051
|
+
- `frustum.sidesIntersectsSphere(f: Frustum, s: Sphere): boolean` — Tests if a sphere intersects the lateral planes of a sides-only frustum, skipping near and far.
|
|
1052
|
+
- `frustum.sidesIntersectsBox3(f: Frustum, box: Box3): boolean` — Tests if an axis-aligned box intersects the lateral planes of a sides-only frustum, using the
|
|
1053
|
+
- `frustum.sidesContainsPoint(f: Frustum, p: Vec3): boolean` — Tests if a point is inside the lateral planes of a sides-only frustum, skipping near and far.
|
|
1054
|
+
- `frustum.sidesIntersectsRay(f: Frustum, origin: Vec3, direction: Vec3): boolean` — Tests if a ray intersects the lateral planes of a sides-only frustum, using a slab test over the
|
|
1055
|
+
- `frustum.corners(out: FrustumCorners, f: Frustum): FrustumCorners` — Computes the eight corners of the frustum by intersecting three planes each.
|
|
1056
|
+
|
|
1057
|
+
**Query**
|
|
1058
|
+
|
|
1059
|
+
- `frustum.intersectsSphere(f: Frustum, s: Sphere): boolean` — Tests if a sphere intersects the frustum.
|
|
1060
|
+
- `frustum.intersectsBox3(f: Frustum, box: Box3): boolean` — Tests if an axis-aligned box intersects the frustum, using the p-vertex test.
|
|
1061
|
+
- `frustum.containsPoint(f: Frustum, p: Vec3): boolean` — Tests if a point is inside the frustum.
|
|
1062
|
+
- `frustum.intersectsRay(f: Frustum, origin: Vec3, direction: Vec3): boolean` — Tests if a ray intersects the frustum, using a slab test over the planes.
|
|
1063
|
+
|
|
1064
|
+
<a id="api-math-geometry"></a>
|
|
1065
|
+
|
|
1066
|
+
## `math/geometry`
|
|
1067
|
+
|
|
1068
|
+
- <a id="circumcircle"></a>`circumcircle(out: Circle, a: Vec2, b: Vec2, c: Vec2): Circle` — Calculates the circumcircle of three points and stores the center in the output parameter.
|
|
1069
|
+
- <a id="decomposepolygon2quick"></a>`decomposePolygon2Quick(vertices: number[], n: number): number[][]` — Decomposes a simple polygon into convex sub-polygons using Bayazit's fast
|
|
1070
|
+
- <a id="decomposepolygon2quality"></a>`decomposePolygon2Quality(vertices: number[], n: number): number[][]` — Decomposes a simple polygon into the (near-)minimum number of convex
|
|
1071
|
+
- <a id="triangulatepolygon2"></a>`triangulatePolygon2(out: number[], vertices: number[], n: number): number` — Triangulates a simple polygon by ear clipping, writing triangle indices into
|
|
1072
|
+
- <a id="quickhull2"></a>`quickhull2(points: number[]): number[]` — Computes the convex hull of a set of 2D points using the QuickHull algorithm.
|
|
1073
|
+
- <a id="quickhull3"></a>`quickhull3(points: number[]): number[]` — Computes the convex hull of a set of 3D points using an incremental QuickHull algorithm.
|
|
1074
|
+
|
|
1075
|
+
<a id="api-math-time"></a>
|
|
1076
|
+
|
|
1077
|
+
## `math/time`
|
|
1078
|
+
|
|
1079
|
+
- `type Spring<T> = { value: T; velocity: T; }` — Spring state: a `value` and its `velocity`, of matching rank
|
|
1080
|
+
|
|
1081
|
+
<a id="api-math-time-easing"></a>
|
|
1082
|
+
|
|
1083
|
+
### `easing`
|
|
1084
|
+
|
|
1085
|
+
```ts
|
|
1086
|
+
import { easing } from 'math/time';
|
|
1087
|
+
```
|
|
1088
|
+
|
|
1089
|
+
- `easing.exp(t: number)`
|
|
1090
|
+
- `easing.linear(t: number)`
|
|
1091
|
+
- `easing.sineIn(x: number)`
|
|
1092
|
+
- `easing.sineOut(x: number)`
|
|
1093
|
+
- `easing.sineInOut(x: number)`
|
|
1094
|
+
- `easing.cubicIn(x: number)`
|
|
1095
|
+
- `easing.cubicOut(x: number)`
|
|
1096
|
+
- `easing.cubicInOut(x: number)`
|
|
1097
|
+
- `easing.quintIn(x: number)`
|
|
1098
|
+
- `easing.quintOut(x: number)`
|
|
1099
|
+
- `easing.quintInOut(x: number)`
|
|
1100
|
+
- `easing.circIn(x: number)`
|
|
1101
|
+
- `easing.circOut(x: number)`
|
|
1102
|
+
- `easing.circInOut(x: number)`
|
|
1103
|
+
- `easing.quartIn(t: number)`
|
|
1104
|
+
- `easing.quartOut(t: number)`
|
|
1105
|
+
- `easing.quartInOut(t: number)`
|
|
1106
|
+
- `easing.expoIn(x: number)`
|
|
1107
|
+
- `easing.expoOut(x: number)`
|
|
1108
|
+
- `easing.expoInOut(x: number)`
|
|
1109
|
+
- `easing.rsqw(t: number, delta = 0.01, a = 1, f = 1 / (2 * Math.PI))`
|
|
1110
|
+
|
|
1111
|
+
<a id="api-math-time-spring"></a>
|
|
1112
|
+
|
|
1113
|
+
### `spring`
|
|
1114
|
+
|
|
1115
|
+
```ts
|
|
1116
|
+
import { spring } from 'math/time';
|
|
1117
|
+
```
|
|
1118
|
+
|
|
1119
|
+
**Create**
|
|
1120
|
+
|
|
1121
|
+
- `spring.create(value = 0): Spring<number>` — Creates a scalar spring at `value`, at rest.
|
|
1122
|
+
- `spring.fromResponse(response: number): number` — Converts a SwiftUI-style `response` — the spring's natural period, in seconds
|
|
1123
|
+
|
|
1124
|
+
**Operations**
|
|
1125
|
+
|
|
1126
|
+
- `spring.update(state: Spring<number>, target: number, smoothTime: number, dampingRatio: number, delta: number): Spring<number>` — Springs `state.value` toward `target`, mutating `state` in place. Returns it.
|
|
1127
|
+
- `spring.damp(state: Spring<number>, target: number, smoothTime: number, delta: number): Spring<number>` — Critically-damped update (dampingRatio = 1): moves toward `target` as
|
|
1128
|
+
- `spring.dampAngle(state: Spring<number>, target: number, smoothTime: number, delta: number): Spring<number>` — Like damp, but takes the shortest angular path to `target` (radians)
|
|
1129
|
+
|
|
1130
|
+
<a id="api-math-time-spring2"></a>
|
|
1131
|
+
|
|
1132
|
+
### `spring2`
|
|
1133
|
+
|
|
1134
|
+
```ts
|
|
1135
|
+
import { spring2 } from 'math/time';
|
|
1136
|
+
```
|
|
1137
|
+
|
|
1138
|
+
**Create**
|
|
1139
|
+
|
|
1140
|
+
- `spring2.create(value: Vec2 = [0, 0]): Spring<Vec2>` — Creates a Vec2 spring at `value` (copied), at rest.
|
|
1141
|
+
|
|
1142
|
+
**Operations**
|
|
1143
|
+
|
|
1144
|
+
- `spring2.update(state: Spring<Vec2>, target: Vec2, smoothTime: number, dampingRatio: number, delta: number): Spring<Vec2>` — Springs `state.value` toward `target`, mutating `state` in place. Returns it.
|
|
1145
|
+
- `spring2.damp(state: Spring<Vec2>, target: Vec2, smoothTime: number, delta: number): Spring<Vec2>` — Critically-damped Vec2 spring (dampingRatio = 1). See update.
|
|
1146
|
+
|
|
1147
|
+
<a id="api-math-time-spring3"></a>
|
|
1148
|
+
|
|
1149
|
+
### `spring3`
|
|
1150
|
+
|
|
1151
|
+
```ts
|
|
1152
|
+
import { spring3 } from 'math/time';
|
|
1153
|
+
```
|
|
1154
|
+
|
|
1155
|
+
**Create**
|
|
1156
|
+
|
|
1157
|
+
- `spring3.create(value: Vec3 = [0, 0, 0]): Spring<Vec3>` — Creates a Vec3 spring at `value` (copied), at rest.
|
|
1158
|
+
|
|
1159
|
+
**Operations**
|
|
1160
|
+
|
|
1161
|
+
- `spring3.update(state: Spring<Vec3>, target: Vec3, smoothTime: number, dampingRatio: number, delta: number): Spring<Vec3>` — Springs `state.value` toward `target`, mutating `state` in place. Returns it.
|
|
1162
|
+
- `spring3.damp(state: Spring<Vec3>, target: Vec3, smoothTime: number, delta: number): Spring<Vec3>` — Critically-damped Vec3 spring (dampingRatio = 1). See update.
|
|
1163
|
+
|
|
1164
|
+
<a id="api-math-time-spring4"></a>
|
|
1165
|
+
|
|
1166
|
+
### `spring4`
|
|
1167
|
+
|
|
1168
|
+
```ts
|
|
1169
|
+
import { spring4 } from 'math/time';
|
|
1170
|
+
```
|
|
1171
|
+
|
|
1172
|
+
**Create**
|
|
1173
|
+
|
|
1174
|
+
- `spring4.create(value: Vec4 = [0, 0, 0, 0]): Spring<Vec4>` — Creates a Vec4 spring at `value` (copied), at rest.
|
|
1175
|
+
|
|
1176
|
+
**Operations**
|
|
1177
|
+
|
|
1178
|
+
- `spring4.update(state: Spring<Vec4>, target: Vec4, smoothTime: number, dampingRatio: number, delta: number): Spring<Vec4>` — Springs `state.value` toward `target`, mutating `state` in place. Returns it.
|
|
1179
|
+
- `spring4.damp(state: Spring<Vec4>, target: Vec4, smoothTime: number, delta: number): Spring<Vec4>` — Critically-damped Vec4 spring (dampingRatio = 1). See update.
|
|
1180
|
+
|
|
1181
|
+
<a id="api-math-random"></a>
|
|
1182
|
+
|
|
1183
|
+
## `math/random`
|
|
1184
|
+
|
|
1185
|
+
- `type Isaac32 = { m: Uint32Array; r: Uint32Array; a: number; b: number; c: number; i: number; }` — State of an ISAAC-32 PRNG: two 256-word arrays plus three accumulators and a
|
|
1186
|
+
- `type Isaac64 = { mHi: Uint32Array; mLo: Uint32Array; rHi: Uint32Array; rLo: Uint32Array; aHi: number; aLo: number; bHi: number; bLo: number; cHi: number; cLo: number; i: number; }` — State of an ISAAC64 PRNG. Create one with create.
|
|
1187
|
+
- `type Mulberry32 = { a: number; }` — State of a Mulberry32 PRNG: a single 32-bit accumulator that sample
|
|
1188
|
+
- `type RandomGenerator = () => number` — A function that returns a random number in the range [0, 1).
|
|
1189
|
+
|
|
1190
|
+
<a id="api-math-random-isaac32"></a>
|
|
1191
|
+
|
|
1192
|
+
### `isaac32`
|
|
1193
|
+
|
|
1194
|
+
```ts
|
|
1195
|
+
import { isaac32 } from 'math/random';
|
|
1196
|
+
```
|
|
1197
|
+
|
|
1198
|
+
**Create**
|
|
1199
|
+
|
|
1200
|
+
- `isaac32.create(seed = 0): Isaac32` — Creates ISAAC-32 PRNG state seeded with `seed`.
|
|
1201
|
+
|
|
1202
|
+
**Operations**
|
|
1203
|
+
|
|
1204
|
+
- `isaac32.next(state: Isaac32): number` — Advances `state` and returns the next raw 32-bit unsigned integer.
|
|
1205
|
+
- `isaac32.sample(state: Isaac32): number` — Advances `state` and returns the next number in the range [0, 1).
|
|
1206
|
+
- `isaac32.seed(): number` — Generates a random 32-bit unsigned integer seed, suitable for use with
|
|
1207
|
+
|
|
1208
|
+
<a id="api-math-random-isaac64"></a>
|
|
1209
|
+
|
|
1210
|
+
### `isaac64`
|
|
1211
|
+
|
|
1212
|
+
```ts
|
|
1213
|
+
import { isaac64 } from 'math/random';
|
|
1214
|
+
```
|
|
1215
|
+
|
|
1216
|
+
**Create**
|
|
1217
|
+
|
|
1218
|
+
- `isaac64.create(seed: bigint = 0n): Isaac64` — Creates ISAAC64 PRNG state seeded with `seed`.
|
|
1219
|
+
|
|
1220
|
+
**Operations**
|
|
1221
|
+
|
|
1222
|
+
- `isaac64.next(state: Isaac64): bigint` — Advances `state` and returns the next raw 64-bit unsigned integer.
|
|
1223
|
+
- `isaac64.sample(state: Isaac64): number` — Advances `state` and returns the next number in the range [0, 1).
|
|
1224
|
+
- `isaac64.seed(): bigint` — Generates a random 64-bit unsigned integer seed, suitable for use with
|
|
1225
|
+
|
|
1226
|
+
<a id="api-math-random-mulberry32"></a>
|
|
1227
|
+
|
|
1228
|
+
### `mulberry32`
|
|
1229
|
+
|
|
1230
|
+
```ts
|
|
1231
|
+
import { mulberry32 } from 'math/random';
|
|
1232
|
+
```
|
|
1233
|
+
|
|
1234
|
+
**Create**
|
|
1235
|
+
|
|
1236
|
+
- `mulberry32.create(seed: number): Mulberry32` — Creates Mulberry32 PRNG state seeded with `seed`.
|
|
1237
|
+
|
|
1238
|
+
**Operations**
|
|
1239
|
+
|
|
1240
|
+
- `mulberry32.next(state: Mulberry32): number` — Advances `state` and returns the next raw 32-bit unsigned integer.
|
|
1241
|
+
- `mulberry32.sample(state: Mulberry32): number` — Advances `state` and returns the next number in the range [0, 1).
|
|
1242
|
+
- `mulberry32.seed(): number` — Generates a random 32-bit unsigned integer seed, suitable for use with
|
|
1243
|
+
|
|
1244
|
+
<a id="api-math-random-random"></a>
|
|
1245
|
+
|
|
1246
|
+
### `random`
|
|
1247
|
+
|
|
1248
|
+
```ts
|
|
1249
|
+
import { random } from 'math/random';
|
|
1250
|
+
```
|
|
1251
|
+
|
|
1252
|
+
- `random.float(random: RandomGenerator, min: number, max: number): number` — Returns a random float in the range [min, max).
|
|
1253
|
+
- `random.int(random: RandomGenerator, min: number, max: number): number` — Returns a random integer in the range [min, max] (inclusive).
|
|
1254
|
+
- `random.bool(random: RandomGenerator, chance = 0.5): boolean` — Returns a random boolean.
|
|
1255
|
+
- `random.sign(random: RandomGenerator, plusChance = 0.5): number` — Returns a random sign, either 1 or -1.
|
|
1256
|
+
- `random.choice<T>(random: RandomGenerator, items: T[]): T` — Returns a random item from an array.
|
|
1257
|
+
- `random.vec2(out: Vec2, random: RandomGenerator): Vec2` — Writes a random unit-length Vec2 into out.
|
|
1258
|
+
- `random.vec3(out: Vec3, random: RandomGenerator): Vec3` — Writes a random unit-length Vec3 into out.
|
|
1259
|
+
- `random.vec4(out: Vec4, random: RandomGenerator): Vec4` — Writes a random unit-length Vec4 into out.
|
|
1260
|
+
- `random.quat(out: Quat, random: RandomGenerator): Quat` — Writes a random unit quaternion into out.
|
|
1261
|
+
|
|
1262
|
+
<a id="api-math-noise"></a>
|
|
1263
|
+
|
|
1264
|
+
## `math/noise`
|
|
1265
|
+
|
|
1266
|
+
**Types**
|
|
1267
|
+
|
|
1268
|
+
- `type Permutation = { perm: Uint8Array; grad3: Float64Array; grad4: Float64Array; }` — Seeded permutation and gradient tables that back a noise generator.
|
|
1269
|
+
|
|
1270
|
+
**Operations**
|
|
1271
|
+
|
|
1272
|
+
- <a id="fbm"></a>`fbm(sample: (frequency: number) => number, octaves: number, lacunarity: number, gain: number): number` — Fractional Brownian motion: sums octaves of a noise source at increasing
|
|
1273
|
+
- <a id="ridged"></a>`ridged(sample: (frequency: number) => number, octaves: number, lacunarity: number, gain: number): number` — Ridged multifractal: like fbm, but each octave is folded to
|
|
1274
|
+
- <a id="billow"></a>`billow(sample: (frequency: number) => number, octaves: number, lacunarity: number, gain: number): number` — Billow noise: like fbm, but each octave is folded to `2*abs(noise) - 1`
|
|
1275
|
+
- <a id="domainwarp2"></a>`domainWarp2(out: Vec2, sample: (x: number, y: number) => number, x: number, y: number, amount = 1): Vec2` — Domain warping (2D): offsets a point by a noise-derived vector, so feeding the
|
|
1276
|
+
- <a id="domainwarp3"></a>`domainWarp3(out: Vec3, sample: (x: number, y: number, z: number) => number, x: number, y: number, z: number, amount = 1): Vec3` — Domain warping (3D): offsets a point by a noise-derived vector so a noise
|
|
1277
|
+
- <a id="curl2"></a>`curl2(out: Vec2, sample: (x: number, y: number) => number, x: number, y: number, eps = 1e-4): Vec2` — Curl of a 2D scalar noise potential - a divergence-free (incompressible) flow
|
|
1278
|
+
- <a id="curl3"></a>`curl3(out: Vec3, sample: (x: number, y: number, z: number) => number, x: number, y: number, z: number, eps = 1e-4): Vec3` — Curl of a 3D noise vector potential - a divergence-free 3D flow field for
|
|
1279
|
+
|
|
1280
|
+
<a id="api-math-noise-perlin2d"></a>
|
|
1281
|
+
|
|
1282
|
+
### `perlin2d`
|
|
1283
|
+
|
|
1284
|
+
```ts
|
|
1285
|
+
import { perlin2d } from 'math/noise';
|
|
1286
|
+
```
|
|
1287
|
+
|
|
1288
|
+
**Types**
|
|
1289
|
+
|
|
1290
|
+
- `type Perlin2DGenerator = Permutation` — A seeded 2D Perlin noise generator. Create one with create.
|
|
1291
|
+
|
|
1292
|
+
**Create**
|
|
1293
|
+
|
|
1294
|
+
- `perlin2d.create(seed: number): Perlin2DGenerator` — Creates a 2D Perlin noise generator with the given seed.
|
|
1295
|
+
|
|
1296
|
+
**Operations**
|
|
1297
|
+
|
|
1298
|
+
- `perlin2d.sample({ perm, grad3 }: Perlin2DGenerator, x: number, y: number): number` — Samples 2D Perlin noise.
|
|
1299
|
+
|
|
1300
|
+
<a id="api-math-noise-perlin3d"></a>
|
|
1301
|
+
|
|
1302
|
+
### `perlin3d`
|
|
1303
|
+
|
|
1304
|
+
```ts
|
|
1305
|
+
import { perlin3d } from 'math/noise';
|
|
1306
|
+
```
|
|
1307
|
+
|
|
1308
|
+
**Types**
|
|
1309
|
+
|
|
1310
|
+
- `type Perlin3DGenerator = Permutation` — A seeded 3D Perlin noise generator. Create one with create.
|
|
1311
|
+
|
|
1312
|
+
**Create**
|
|
1313
|
+
|
|
1314
|
+
- `perlin3d.create(seed: number): Perlin3DGenerator` — Creates a 3D Perlin noise generator with the given seed.
|
|
1315
|
+
|
|
1316
|
+
**Operations**
|
|
1317
|
+
|
|
1318
|
+
- `perlin3d.sample({ perm, grad3 }: Perlin3DGenerator, x: number, y: number, z: number): number` — Samples 3D Perlin noise.
|
|
1319
|
+
|
|
1320
|
+
<a id="api-math-noise-simplex2d"></a>
|
|
1321
|
+
|
|
1322
|
+
### `simplex2d`
|
|
1323
|
+
|
|
1324
|
+
```ts
|
|
1325
|
+
import { simplex2d } from 'math/noise';
|
|
1326
|
+
```
|
|
1327
|
+
|
|
1328
|
+
**Types**
|
|
1329
|
+
|
|
1330
|
+
- `type Simplex2DGenerator = Permutation` — A seeded 2D simplex noise generator. Create one with create.
|
|
1331
|
+
|
|
1332
|
+
**Create**
|
|
1333
|
+
|
|
1334
|
+
- `simplex2d.create(seed: number): Simplex2DGenerator` — Creates a 2D simplex noise generator with the given seed.
|
|
1335
|
+
|
|
1336
|
+
**Operations**
|
|
1337
|
+
|
|
1338
|
+
- `simplex2d.sample({ perm, grad3 }: Simplex2DGenerator, x: number, y: number): number` — Samples 2D simplex noise, returning a value in the interval [-1, 1].
|
|
1339
|
+
|
|
1340
|
+
<a id="api-math-noise-simplex3d"></a>
|
|
1341
|
+
|
|
1342
|
+
### `simplex3d`
|
|
1343
|
+
|
|
1344
|
+
```ts
|
|
1345
|
+
import { simplex3d } from 'math/noise';
|
|
1346
|
+
```
|
|
1347
|
+
|
|
1348
|
+
**Types**
|
|
1349
|
+
|
|
1350
|
+
- `type Simplex3DGenerator = Permutation` — A seeded 3D simplex noise generator. Create one with create.
|
|
1351
|
+
|
|
1352
|
+
**Create**
|
|
1353
|
+
|
|
1354
|
+
- `simplex3d.create(seed: number): Simplex3DGenerator` — Creates a 3D simplex noise generator with the given seed.
|
|
1355
|
+
|
|
1356
|
+
**Operations**
|
|
1357
|
+
|
|
1358
|
+
- `simplex3d.sample({ perm, grad3 }: Simplex3DGenerator, x: number, y: number, z: number): number` — Samples 3D simplex noise, returning a value in the interval [-1, 1].
|
|
1359
|
+
|
|
1360
|
+
<a id="api-math-noise-simplex4d"></a>
|
|
1361
|
+
|
|
1362
|
+
### `simplex4d`
|
|
1363
|
+
|
|
1364
|
+
```ts
|
|
1365
|
+
import { simplex4d } from 'math/noise';
|
|
1366
|
+
```
|
|
1367
|
+
|
|
1368
|
+
**Types**
|
|
1369
|
+
|
|
1370
|
+
- `type Simplex4DGenerator = Permutation` — A seeded 4D simplex noise generator. Create one with create.
|
|
1371
|
+
|
|
1372
|
+
**Create**
|
|
1373
|
+
|
|
1374
|
+
- `simplex4d.create(seed: number): Simplex4DGenerator` — Creates a 4D simplex noise generator with the given seed.
|
|
1375
|
+
|
|
1376
|
+
**Operations**
|
|
1377
|
+
|
|
1378
|
+
- `simplex4d.sample({ perm, grad4 }: Simplex4DGenerator, x: number, y: number, z: number, w: number): number` — Samples 4D simplex noise, returning a value in the interval [-1, 1].
|
|
1379
|
+
|
|
1380
|
+
<a id="api-math-noise-worley2d"></a>
|
|
1381
|
+
|
|
1382
|
+
### `worley2d`
|
|
1383
|
+
|
|
1384
|
+
```ts
|
|
1385
|
+
import { worley2d } from 'math/noise';
|
|
1386
|
+
```
|
|
1387
|
+
|
|
1388
|
+
**Types**
|
|
1389
|
+
|
|
1390
|
+
- `type Worley2DGenerator = Permutation` — A seeded 2D Worley (cellular) noise generator. Create one with create.
|
|
1391
|
+
|
|
1392
|
+
**Create**
|
|
1393
|
+
|
|
1394
|
+
- `worley2d.create(seed: number): Worley2DGenerator` — Creates a 2D Worley noise generator with the given seed.
|
|
1395
|
+
|
|
1396
|
+
**Operations**
|
|
1397
|
+
|
|
1398
|
+
- `worley2d.sample({ perm }: Worley2DGenerator, x: number, y: number): number` — Samples 2D Worley (cellular) noise: the Euclidean distance to the nearest of a
|
|
1399
|
+
|
|
1400
|
+
<a id="api-math-noise-worley3d"></a>
|
|
1401
|
+
|
|
1402
|
+
### `worley3d`
|
|
1403
|
+
|
|
1404
|
+
```ts
|
|
1405
|
+
import { worley3d } from 'math/noise';
|
|
1406
|
+
```
|
|
1407
|
+
|
|
1408
|
+
**Types**
|
|
1409
|
+
|
|
1410
|
+
- `type Worley3DGenerator = Permutation` — A seeded 3D Worley (cellular) noise generator. Create one with create.
|
|
1411
|
+
|
|
1412
|
+
**Create**
|
|
1413
|
+
|
|
1414
|
+
- `worley3d.create(seed: number): Worley3DGenerator` — Creates a 3D Worley noise generator with the given seed.
|
|
1415
|
+
|
|
1416
|
+
**Operations**
|
|
1417
|
+
|
|
1418
|
+
- `worley3d.sample({ perm }: Worley3DGenerator, x: number, y: number, z: number): number` — Samples 3D Worley (cellular) noise: the Euclidean distance to the nearest of a
|
|
1419
|
+
|
|
1420
|
+
<a id="api-math-color"></a>
|
|
1421
|
+
|
|
1422
|
+
## `math/color`
|
|
1423
|
+
|
|
1424
|
+
- `type Color = [ r: number, g: number, b: number ]` — A linear-sRGB color: [r, g, b] floats in [0, 1].
|
|
1425
|
+
- `type ColorInput = string | number | [ number, number, number ]` — Accepted input types for creating or parsing a Color.
|
|
1426
|
+
- `type HSL = [ hue: number, saturation: number, lightness: number ]` — A hue-saturation-lightness color: [h, s, l], all in [0, 1] (hue wraps).
|
|
1427
|
+
|
|
1428
|
+
<a id="api-math-color-color"></a>
|
|
1429
|
+
|
|
1430
|
+
### `color`
|
|
1431
|
+
|
|
1432
|
+
```ts
|
|
1433
|
+
import { color } from 'math/color';
|
|
1434
|
+
```
|
|
1435
|
+
|
|
1436
|
+
**Create**
|
|
1437
|
+
|
|
1438
|
+
- `color.create(): Color` — Create a new Color initialized to black [0, 0, 0].
|
|
1439
|
+
- `color.fromValues(r: number, g: number, b: number): Color` — Create a new Color with the given linear r, g, b values.
|
|
1440
|
+
- `color.clone(c: Color): Color` — Create a new Color that is a copy of `c`.
|
|
1441
|
+
- `color.copy(out: Color, src: Color): Color` — Copy the values from `src` into `out`. Returns `out`.
|
|
1442
|
+
- `color.set(out: Color, r: number, g: number, b: number): Color` — Set the linear r, g, b components of `out` directly. Returns `out`.
|
|
1443
|
+
- `color.setScalar(out: Color, s: number): Color` — Set all three channels of `out` to the same linear value `s` (a gray). Returns `out`.
|
|
1444
|
+
- `color.setFromSRGB(out: Color, srgb: [ number, number, number ]): Color` — Set `out` from an sRGB gamma-encoded [r, g, b] array with values in [0, 1].
|
|
1445
|
+
- `color.fromSRGB(srgb: [ number, number, number ]): Color` — Create a new Color from an sRGB gamma-encoded [r, g, b] array with values in [0, 1].
|
|
1446
|
+
- `color.toSRGB(out: [ number, number, number ], c: Color): [ number, number, number ]` — Write the sRGB gamma-encoded [r, g, b] of a linear Color into `out` (values [0, 1]).
|
|
1447
|
+
- `color.toCSS(c: Color): string` — Create a CSS `rgb(...)` string in sRGB gamma space (for HTML/canvas use).
|
|
1448
|
+
- `color.toHex(c: Color): number` — Convert to a 0xRRGGBB integer in sRGB gamma space.
|
|
1449
|
+
- `color.toHexString(c: Color): string` — Convert to a 6-digit sRGB hex string without a leading '#', e.g. 'ff8800'.
|
|
1450
|
+
|
|
1451
|
+
**Operations**
|
|
1452
|
+
|
|
1453
|
+
- `color.add(out: Color, a: Color, b: Color): Color` — Add `a + b` component-wise into `out`. Returns `out`.
|
|
1454
|
+
- `color.addScalar(out: Color, a: Color, s: number): Color` — Add scalar `s` to each channel of `a` into `out`. Returns `out`.
|
|
1455
|
+
- `color.sub(out: Color, a: Color, b: Color): Color` — Subtract `a - b` component-wise into `out`. Returns `out`.
|
|
1456
|
+
- `color.multiply(out: Color, a: Color, b: Color): Color` — Multiply `a * b` component-wise into `out` (tinting). Returns `out`.
|
|
1457
|
+
- `color.multiplyScalar(out: Color, a: Color, s: number): Color` — Scale each channel of `a` by `s` into `out` (brightness). Returns `out`.
|
|
1458
|
+
- `color.lerp(out: Color, a: Color, b: Color, t: number): Color` — Linearly interpolate from `a` to `b` by `t` into `out` (physically-correct blend). Returns `out`.
|
|
1459
|
+
- `color.clamp(out: Color, c: Color): Color` — Clamp each channel of `c` to [0, 1] into `out`. Returns `out`.
|
|
1460
|
+
|
|
1461
|
+
**Query**
|
|
1462
|
+
|
|
1463
|
+
- `color.equals(a: Color, b: Color, epsilon = 0): boolean` — Whether `a` and `b` are equal, within an optional per-channel `epsilon` (default exact).
|
|
1464
|
+
- `color.luminance(c: Color): number` — Relative luminance in [0, 1] (Rec. 709 weights, on linear light).
|
|
1465
|
+
|
|
1466
|
+
<a id="api-math-color-colorspace"></a>
|
|
1467
|
+
|
|
1468
|
+
### `colorspace`
|
|
1469
|
+
|
|
1470
|
+
```ts
|
|
1471
|
+
import { colorspace } from 'math/color';
|
|
1472
|
+
```
|
|
1473
|
+
|
|
1474
|
+
- `colorspace.srgbToLinear(c: number): number` — Convert a single sRGB gamma-encoded channel [0, 1] to linear light [0, 1].
|
|
1475
|
+
- `colorspace.linearToSrgb(c: number): number` — Convert a single linear light channel [0, 1] to sRGB gamma-encoded [0, 1].
|
|
1476
|
+
- `colorspace.linearSrgbToLinearDisplayP3(out: Color, c: Color): Color` — Convert a linear-sRGB Color to linear Display-P3 primaries, into `out`. Returns `out`.
|
|
1477
|
+
- `colorspace.linearDisplayP3ToLinearSrgb(out: Color, c: Color): Color` — Convert a linear Display-P3 Color to linear-sRGB primaries, into `out`. Returns `out`.
|
|
1478
|
+
|
|
1479
|
+
<a id="api-math-color-hsl"></a>
|
|
1480
|
+
|
|
1481
|
+
### `hsl`
|
|
1482
|
+
|
|
1483
|
+
```ts
|
|
1484
|
+
import { hsl } from 'math/color';
|
|
1485
|
+
```
|
|
1486
|
+
|
|
1487
|
+
**Create**
|
|
1488
|
+
|
|
1489
|
+
- `hsl.create(): HSL` — Create a new HSL initialized to [0, 0, 0] (black).
|
|
1490
|
+
- `hsl.fromValues(h: number, s: number, l: number): HSL` — Create a new HSL with the given h, s, l values (all in [0, 1]).
|
|
1491
|
+
- `hsl.clone(a: HSL): HSL` — Create a new HSL that is a copy of `a`.
|
|
1492
|
+
- `hsl.copy(out: HSL, src: HSL): HSL` — Copy the values from `src` into `out`. Returns `out`.
|
|
1493
|
+
- `hsl.set(out: HSL, h: number, s: number, l: number): HSL` — Set the h, s, l components of `out` directly. Returns `out`.
|
|
1494
|
+
- `hsl.fromColor(out: HSL, c: Color): HSL` — Write the HSL of a linear Color into `out`. Returns `out`.
|
|
1495
|
+
- `hsl.toColor(out: Color, a: HSL): Color` — Write the linear Color of an HSL into `out`. Returns `out`.
|
|
1496
|
+
|
|
1497
|
+
**Operations**
|
|
1498
|
+
|
|
1499
|
+
- `hsl.lerp(out: HSL, a: HSL, b: HSL, t: number): HSL` — Interpolate from `a` to `b` by `t` into `out`, taking the shortest path around
|
|
1500
|
+
- `hsl.offset(out: HSL, a: HSL, dh: number, ds: number, dl: number): HSL` — Offset `a` by (dh, ds, dl) into `out`: hue wraps into [0, 1), saturation and
|
|
1501
|
+
|
|
1502
|
+
<a id="api-math-ik"></a>
|
|
1503
|
+
|
|
1504
|
+
## `math/ik`
|
|
1505
|
+
|
|
1506
|
+
<a id="api-math-ik-fabrik2"></a>
|
|
1507
|
+
|
|
1508
|
+
### `fabrik2`
|
|
1509
|
+
|
|
1510
|
+
```ts
|
|
1511
|
+
import { fabrik2 } from 'math/ik';
|
|
1512
|
+
```
|
|
1513
|
+
|
|
1514
|
+
**Types**
|
|
1515
|
+
|
|
1516
|
+
- `enum ConstraintCoordinateSystem = LOCAL | GLOBAL` — What a joint's clockwise and anticlockwise limits are measured from.
|
|
1517
|
+
- `enum BaseboneConstraintType = NONE | GLOBAL_ABSOLUTE | LOCAL_RELATIVE | LOCAL_ABSOLUTE` — How the first bone in a chain is constrained.
|
|
1518
|
+
- `enum BoneConnectionPoint = START | END` — Which end of a host bone a connected chain hangs off.
|
|
1519
|
+
- `type Joint2 = { clockwise: number; anticlockwise: number; coordinateSystem: ConstraintCoordinateSystem; globalAxis: Vec2; }` — A joint's rotational limits: a wedge about a baseline.
|
|
1520
|
+
- `type Bone2 = { start: Vec2; end: Vec2; length: number; joint: Joint2; }` — A single bone: two points, the fixed distance between them, and how it may rotate.
|
|
1521
|
+
- `type Chain2 = { bones: Bone2[]; length: number; base: Vec2; fixedBase: boolean; baseboneConstraintType: BaseboneConstraintType; baseboneAxis: Vec2; baseboneWorldAxis: Vec2; baseboneClockwise: number; baseboneAnticlockwise: number; embeddedTarget: Vec2; useEmbeddedTarget: boolean; maxIterations: number; solveDistanceThreshold: number; minIterationChange: number; solveDistance: number; bestSolution: number[]; }` — A chain of bones, from the base (index 0) to the end effector (the last bone's `end`).
|
|
1522
|
+
- `type Connection = { hostChain: number; hostBone: number; point: BoneConnectionPoint; }` — A chain's attachment to a bone in another chain of the same structure.
|
|
1523
|
+
- `type Structure2 = { chains: Chain2[]; connections: Connection[]; }` — A set of chains, each optionally hanging off a bone of another.
|
|
1524
|
+
|
|
1525
|
+
**Create**
|
|
1526
|
+
|
|
1527
|
+
- `fabrik2.setLocalJoint(joint: Joint2, clockwise: number, anticlockwise: number): Joint2` — Sets a joint's limits relative to the previous bone's direction, which is the usual case.
|
|
1528
|
+
- `fabrik2.setGlobalJoint(joint: Joint2, axis: Vec2, clockwise: number, anticlockwise: number): Joint2` — Sets a joint's limits relative to a fixed world direction, pinning the bone's absolute heading
|
|
1529
|
+
- `fabrik2.setBaseboneConstraint(chain: Chain2, type: BaseboneConstraintType, axis: Vec2, clockwise: number, anticlockwise: number): Chain2` — Constrains the first bone to a wedge about `axis`.
|
|
1530
|
+
- `fabrik2.setBaseLocation(chain: Chain2, base: Vec2): Chain2` — Moves the chain's pinned base, without moving the bones.
|
|
1531
|
+
|
|
1532
|
+
**Operations**
|
|
1533
|
+
|
|
1534
|
+
- `fabrik2.createJoint2(): Joint2` — Creates an unconstrained joint.
|
|
1535
|
+
- `fabrik2.createChain2(): Chain2` — Creates an empty chain with a fixed base at the origin and no basebone constraint.
|
|
1536
|
+
- `fabrik2.addBone(chain: Chain2, start: Vec2, end: Vec2, joint: Joint2 = createJoint2()): Bone2` — Appends a bone spanning `start` to `end`, copying both.
|
|
1537
|
+
- `fabrik2.addConsecutiveBone(chain: Chain2, direction: Vec2, length: number, joint: Joint2 = createJoint2()): Bone2` — Appends a bone starting where the chain currently ends, running `length` along `direction`.
|
|
1538
|
+
- `fabrik2.addBoneAtBase(chain: Chain2, direction: Vec2, length: number, joint: Joint2 = createJoint2()): Bone2` — Prepends a bone at the base end, extending the chain backward.
|
|
1539
|
+
- `fabrik2.straighten(chain: Chain2, direction: Vec2): Chain2` — Lays the chain out straight from its base along `direction`, discarding the current pose.
|
|
1540
|
+
- `fabrik2.forward(chain: Chain2, target: Vec2): Chain2` — The forward pass: snaps the end effector onto `target` and drags the rest of the chain after it.
|
|
1541
|
+
- `fabrik2.backward(chain: Chain2, base: Vec2): Chain2` — The backward pass: pins the base and pushes each bone outward from it. The basebone constraint
|
|
1542
|
+
- `fabrik2.iterate(chain: Chain2, target: Vec2): number` — One full FABRIK iteration - forward then backward.
|
|
1543
|
+
- `fabrik2.solve(chain: Chain2, target: Vec2): number` — Solves the chain for `target`, iterating until it is close enough, stops improving, or runs out
|
|
1544
|
+
- `fabrik2.createStructure2(): Structure2` — Creates an empty structure.
|
|
1545
|
+
- `fabrik2.addChain(structure: Structure2, chain: Chain2): number` — Adds a chain that hangs off nothing, solving directly for the structure's target.
|
|
1546
|
+
- `fabrik2.connectChain(structure: Structure2, chain: Chain2, hostChain: number, hostBone: number, point: BoneConnectionPoint): number` — Adds a chain whose base is pinned to one end of a bone in a chain already in the structure.
|
|
1547
|
+
- `fabrik2.solveStructure(structure: Structure2, target: Vec2): void` — Solves every chain in the structure.
|
|
1548
|
+
|
|
1549
|
+
**Query**
|
|
1550
|
+
|
|
1551
|
+
- `fabrik2.getEffector(out: Vec2, chain: Chain2): Vec2` — Writes the end effector's position - the last bone's end - into `out`.
|
|
1552
|
+
- `fabrik2.getBoneDirection(out: Vec2, chain: Chain2, index: number): Vec2` — Writes the unit direction of bone `index`, from its start toward its end, into `out`.
|
|
1553
|
+
- `fabrik2.getBoneAngle(chain: Chain2, index: number): number` — The angle of bone `index`, in radians, measured counter-clockwise from the +X axis.
|
|
1554
|
+
- `fabrik2.isReachable(chain: Chain2, target: Vec2): boolean` — Whether `target` is within reach of the chain's base, so a solve can place the effector exactly on it.
|
|
1555
|
+
|
|
1556
|
+
<a id="api-math-ik-fabrik3"></a>
|
|
1557
|
+
|
|
1558
|
+
### `fabrik3`
|
|
1559
|
+
|
|
1560
|
+
```ts
|
|
1561
|
+
import { fabrik3 } from 'math/ik';
|
|
1562
|
+
```
|
|
1563
|
+
|
|
1564
|
+
**Types**
|
|
1565
|
+
|
|
1566
|
+
- `enum JointType = BALL | GLOBAL_HINGE | LOCAL_HINGE` — How a joint may rotate relative to the bone before it.
|
|
1567
|
+
- `enum BaseboneConstraintType = NONE | GLOBAL_ROTOR | LOCAL_ROTOR | GLOBAL_HINGE | LOCAL_HINGE` — How the first bone in a chain is constrained.
|
|
1568
|
+
- `enum BoneConnectionPoint = START | END` — Which end of a host bone a connected chain hangs off.
|
|
1569
|
+
- `type Joint3 = { type: JointType; rotor: number; clockwise: number; anticlockwise: number; rotationAxis: Vec3; referenceAxis: Vec3; }` — A joint's rotational limits.
|
|
1570
|
+
- `type Bone3 = { start: Vec3; end: Vec3; length: number; joint: Joint3; }` — A single bone: two points, the fixed distance between them, and how it may rotate.
|
|
1571
|
+
- `type Chain3 = { bones: Bone3[]; length: number; base: Vec3; fixedBase: boolean; baseboneConstraintType: BaseboneConstraintType; baseboneAxis: Vec3; baseboneReferenceAxis: Vec3; baseboneWorldAxis: Vec3; baseboneWorldReferenceAxis: Vec3; baseboneRotor: number; baseboneClockwise: number; baseboneAnticlockwise: number; embeddedTarget: Vec3; useEmbeddedTarget: boolean; maxIterations: number; solveDistanceThreshold: number; minIterationChange: number; solveDistance: number; bestSolution: number[]; }` — A chain of bones, from the base (index 0) to the end effector (the last bone's `end`).
|
|
1572
|
+
- `type Connection = { hostChain: number; hostBone: number; point: BoneConnectionPoint; }` — A chain's attachment to a bone in another chain of the same structure.
|
|
1573
|
+
- `type Structure3 = { chains: Chain3[]; connections: Connection[]; }` — A set of chains, each optionally hanging off a bone of another.
|
|
1574
|
+
|
|
1575
|
+
**Create**
|
|
1576
|
+
|
|
1577
|
+
- `fabrik3.setBallJoint(joint: Joint3, rotor: number): Joint3` — Sets a ball-joint constraint: the bone may rotate within a cone of `rotor` radians about the
|
|
1578
|
+
- `fabrik3.setHingeJoint(joint: Joint3, type: JointType.GLOBAL_HINGE | JointType.LOCAL_HINGE, rotationAxis: Vec3, clockwise: number, anticlockwise: number, referenceAxis: Vec3): Joint3` — Sets a hinge constraint: the bone may only rotate in the plane perpendicular to `rotationAxis`
|
|
1579
|
+
- `fabrik3.setBaseboneRotorConstraint(chain: Chain3, type: BaseboneConstraintType.GLOBAL_ROTOR | BaseboneConstraintType.LOCAL_ROTOR, axis: Vec3, rotor: number): Chain3` — Confines the first bone to a cone of `rotor` radians about `axis`.
|
|
1580
|
+
- `fabrik3.setBaseboneHingeConstraint(chain: Chain3, type: BaseboneConstraintType.GLOBAL_HINGE | BaseboneConstraintType.LOCAL_HINGE, rotationAxis: Vec3, clockwise: number, anticlockwise: number, referenceAxis: Vec3): Chain3` — Confines the first bone to the plane perpendicular to `rotationAxis`, within `clockwise` /
|
|
1581
|
+
- `fabrik3.setBaseLocation(chain: Chain3, base: Vec3): Chain3` — Moves the chain's pinned base, without moving the bones.
|
|
1582
|
+
|
|
1583
|
+
**Operations**
|
|
1584
|
+
|
|
1585
|
+
- `fabrik3.createJoint3(): Joint3` — Creates an unconstrained joint.
|
|
1586
|
+
- `fabrik3.createChain3(): Chain3` — Creates an empty chain with a fixed base at the origin and no basebone constraint.
|
|
1587
|
+
- `fabrik3.addBone(chain: Chain3, start: Vec3, end: Vec3, joint: Joint3 = createJoint3()): Bone3` — Appends a bone spanning `start` to `end`, copying both.
|
|
1588
|
+
- `fabrik3.addConsecutiveBone(chain: Chain3, direction: Vec3, length: number, joint: Joint3 = createJoint3()): Bone3` — Appends a bone starting where the chain currently ends, running `length` along `direction`.
|
|
1589
|
+
- `fabrik3.addBoneAtBase(chain: Chain3, direction: Vec3, length: number, joint: Joint3 = createJoint3()): Bone3` — Prepends a bone at the base end, extending the chain backward.
|
|
1590
|
+
- `fabrik3.straighten(chain: Chain3, direction: Vec3): Chain3` — Lays the chain out straight from its base along `direction`, discarding the current pose.
|
|
1591
|
+
- `fabrik3.forward(chain: Chain3, target: Vec3): Chain3` — The forward pass: snaps the end effector onto `target` and drags the rest of the chain after it.
|
|
1592
|
+
- `fabrik3.backward(chain: Chain3, base: Vec3): Chain3` — The backward pass: pins the base and pushes each bone outward from it.
|
|
1593
|
+
- `fabrik3.iterate(chain: Chain3, target: Vec3): number` — One full FABRIK iteration - forward then backward. Often enough on its own for an
|
|
1594
|
+
- `fabrik3.solve(chain: Chain3, target: Vec3): number` — Solves the chain for `target`, iterating until it is close enough, stops improving, or runs out
|
|
1595
|
+
- `fabrik3.createStructure3(): Structure3` — Creates an empty structure.
|
|
1596
|
+
- `fabrik3.addChain(structure: Structure3, chain: Chain3): number` — Adds a chain that hangs off nothing, solving directly for the structure's target.
|
|
1597
|
+
- `fabrik3.connectChain(structure: Structure3, chain: Chain3, hostChain: number, hostBone: number, point: BoneConnectionPoint): number` — Adds a chain whose base is pinned to one end of a bone in a chain already in the structure.
|
|
1598
|
+
- `fabrik3.solveStructure(structure: Structure3, target: Vec3): void` — Solves every chain in the structure.
|
|
1599
|
+
|
|
1600
|
+
**Query**
|
|
1601
|
+
|
|
1602
|
+
- `fabrik3.getEffector(out: Vec3, chain: Chain3): Vec3` — Writes the end effector's position - the last bone's end - into `out`.
|
|
1603
|
+
- `fabrik3.getBoneDirection(out: Vec3, chain: Chain3, index: number): Vec3` — Writes the unit direction of bone `index`, from its start toward its end, into `out`.
|
|
1604
|
+
- `fabrik3.getBoneRotation(out: Quat, chain: Chain3, index: number, up: Vec3): Quat` — Writes the rotation taking `up` onto the direction of bone `index` into `out`.
|
|
1605
|
+
- `fabrik3.isReachable(chain: Chain3, target: Vec3): boolean` — Whether `target` is within reach of the chain's base, so a solve can place the effector exactly on it.
|