Files
cell/docs/api/modules/math.md
2025-02-10 09:48:59 -06:00

116 lines
2.8 KiB
Markdown

# math
### dot() <sub>function</sub>
Compute the dot product between two numeric arrays, returning a scalar. Extra elements are ignored.
### project() <sub>function</sub>
Project one vector onto another, returning a new array of the same dimension.
### rotate() <sub>function</sub>
Rotate a 2D point (or array of length 2) by the given angle (in turns) around an optional pivot.
### midpoint() <sub>function</sub>
Compute the midpoint of two arrays of numbers. Only the first two entries are used if 2D is intended.
### reflect() <sub>function</sub>
Reflect a vector across a plane normal. Both arguments must be numeric arrays.
### distance() <sub>function</sub>
Compute the Euclidean distance between two numeric arrays of matching length.
### direction() <sub>function</sub>
Compute the normalized direction vector from the first array to the second.
### angle() <sub>function</sub>
Given a 2D vector, return its angle from the X-axis in radians or some chosen units.
### norm() <sub>function</sub>
Return a normalized copy of the given numeric array. For 2D/3D/4D or arbitrary length.
### angle_between() <sub>function</sub>
Compute the angle between two vectors (2D/3D/4D).
### lerp() <sub>function</sub>
Linear interpolation between two numbers: lerp(a, b, t).
### gcd() <sub>function</sub>
Compute the greatest common divisor of two integers.
### lcm() <sub>function</sub>
Compute the least common multiple of two integers.
### clamp() <sub>function</sub>
Clamp a number between low and high. clamp(value, low, high).
### angledist() <sub>function</sub>
Compute the signed distance between two angles in 'turn' units, e.g. 0..1 range.
### jitter() <sub>function</sub>
Apply a random +/- percentage noise to a number. Example: jitter(100, 0.05) -> ~95..105.
### mean() <sub>function</sub>
Compute the arithmetic mean of an array of numbers.
### sum() <sub>function</sub>
Sum all elements of an array of numbers.
### sigma() <sub>function</sub>
Compute standard deviation of an array of numbers.
### median() <sub>function</sub>
Compute the median of an array of numbers.
### length() <sub>function</sub>
Return the length of a vector (i.e. sqrt of sum of squares).
### from_to() <sub>function</sub>
Return an array of points from a start to an end, spaced out by a certain distance.
### rand() <sub>function</sub>
Return a random float in [0,1).
### randi() <sub>function</sub>
Return a random 32-bit integer.
### srand() <sub>function</sub>
Seed the random number generator with the given integer, or with current time if none.
### TAU <sub>number</sub>
### deg2rad(deg) <sub>function</sub>
### rad2deg(rad) <sub>function</sub>
### turn2rad(x) <sub>function</sub>
### rad2turn(x) <sub>function</sub>
### turn2deg(x) <sub>function</sub>
### deg2turn(x) <sub>function</sub>