Math

Functions

mix(a,b,t)number

Linearly interpolates between numbers a and b by the mixing factor t.

a
number

The value when t is 0

b
number

The value when t is 1

t
number

The mixing factor

Returns a value between a and b

mixAngles(a,b,t)number
a
number

A normalized angle (in degreees) between 0 and 360

b
number

A normalized angle (in degreees) between 0 and 360

t
number

Returns an interpolation between angles a and b, taking the shortest path

mixCyclic(a,b,t,base)number

Linearly interpolates between numbers a and b by the mixing factor c. Assumes that that interpolation occurs in a closed loop and takes the shortest path from a to b.

This is useful when interpolating cyclic values like "time" in a closed path, or angles.

a
number

The value when t is 0

b
number

The value when t is 1

t
number

The mixing factor

base
number

The size of the cyclic domain. For angles specified in degrees this would be 360.

Returns a value between a and b

clamp(x,min,max)number

Constrains a value to not exceed a maximum and minimum value.

x
number

The value to constrain

min
number

The minimum value to return

max
number

The maximum value to return

Returns a value between min and max

saturate(x)number

Constrains a value to the range 0 to 1.

x
number

The value to constrain

Returns a value between 0 and 1

smoothstep(edge1,edge2,x)number

Smoothly interpolates between 0 and 1 when edge0 < x < edge1.

edge1
number

The value of x where 0 will be returned

edge2
number

The value of x where 1 will be returned

x
number

The value to use for interpolation

Returns a value between 0 and 1

fract(x)number
x
number

Returns the fractional part of the value x

angleDelta(a,b)number
a
number
b
number

Returns the shortest signed angle from a to b in degrees.

Constants

RADIANS_PER_DEGREEnumber

The conversion factor from degrees to radians.

See radiansFromDegrees().

DEGREES_PER_RADIANnumber

The conversion factor from radians to degrees.

See degreesFromRadians().

PInumber

The ratio of a circle's circumference to its diameter. Pi (π) radians equates to a 180° rotation.

TWO_PInumber

Defined to be PI * 2. In radians, this represents a full 360° rotation.

TAUnumber

Equal to TWO_PI. Tau (τ) is the ratio of a circle's circumference to its radius.