Files
cell/docs/api/modules/math.md
2025-02-09 00:07:01 -06:00

2.1 KiB

math

math

dot

Compute the dot product between two numeric arrays, returning a scalar. Extra elements are ignored.

project

Project one vector onto another, returning a new array of the same dimension.

rotate

Rotate a 2D point (or array of length 2) by the given angle (in turns) around an optional pivot.

midpoint

Compute the midpoint of two arrays of numbers. Only the first two entries are used if 2D is intended.

reflect

Reflect a vector across a plane normal. Both arguments must be numeric arrays.

distance

Compute the Euclidean distance between two numeric arrays of matching length.

direction

Compute the normalized direction vector from the first array to the second.

angle

Given a 2D vector, return its angle from the X-axis in radians or some chosen units.

norm

Return a normalized copy of the given numeric array. For 2D/3D/4D or arbitrary length.

angle_between

Compute the angle between two vectors (2D/3D/4D).

lerp

Linear interpolation between two numbers: lerp(a, b, t).

gcd

Compute the greatest common divisor of two integers.

lcm

Compute the least common multiple of two integers.

clamp

Clamp a number between low and high. clamp(value, low, high).

angledist

Compute the signed distance between two angles in 'turn' units, e.g. 0..1 range.

jitter

Apply a random +/- percentage noise to a number. Example: jitter(100, 0.05) -> ~95..105.

mean

Compute the arithmetic mean of an array of numbers.

sum

Sum all elements of an array of numbers.

sigma

Compute standard deviation of an array of numbers.

median

Compute the median of an array of numbers.

length

Return the length of a vector (i.e. sqrt of sum of squares).

from_to

Return an array of points from a start to an end, spaced out by a certain distance.

rand

Return a random float in [0,1).

randi

Return a random 32-bit integer.

srand

Seed the random number generator with the given integer, or with current time if none.

deg2rad(deg)

rad2deg(rad)

turn2rad(x)

rad2turn(x)

turn2deg(x)

deg2turn(x)