Euler's number.
let E = 2.7182818284590452
Monocurl
std.math
Reference for the symbols exported by math.mcl.
Euler's number.
let E = 2.7182818284590452Pi in radians.
let PI = 3.1415926535897932Full circle constant, equal to 2 * PI.
let TAU = 6.2831853071795864let wave = |x| sin(x * TAU)Origin point [0, 0, 0].
let ORIGIN = [0, 0, 0]Zero vector [0, 0, 0].
let ZERO_V = [0, 0, 0]Vector with all components equal to 1.
let ONE_V = [1, 1, 1]Unit vector pointing left in scene coordinates.
let LEFT = 1lUnit vector pointing right in scene coordinates.
let RIGHT = 1rmesh dot = center{RIGHT * 2} Circle(0.2)Unit vector pointing up in scene coordinates.
let UP = 1uUnit vector pointing down in scene coordinates.
let DOWN = 1dUnit vector pointing forward; with the default camera this is negative z.
let FORWARD = 1fUnit vector pointing backward; with the default camera this is positive z, from the origin toward the camera.
let BACKWARD = 1bSquare root.
let sqrt = |x| ...Cube root.
let cbrt = |x| ...Exponential function e^x.
let exp = |x| ...Natural logarithm.
let ln = |x| ...Logarithm with optional base, defaulting to E.
let log = |x, base = E| ln(x) / ln(base)Base-2 logarithm.
let log2 = |x| log(x, 2)Base-10 logarithm.
let log10 = |x| log(x, 10)Sine of an angle in radians.
let sin = |x| ...Cosine of an angle in radians.
let cos = |x| ...Tangent of an angle in radians.
let tan = |x| ...Cotangent of an angle in radians.
let cot = |x| 1 / tan(x)Secant of an angle in radians.
let sec = |x| 1 / cos(x)Cosecant of an angle in radians.
let csc = |x| 1 / sin(x)Inverse sine, returning radians.
let arcsin = |x| ...Inverse cosine, returning radians.
let arccos = |x| ...Inverse tangent, returning radians.
let arctan = |x| ...Two-argument inverse tangent, returning radians.
let arctan2 = |y, x| ...Hyperbolic sine.
let sinh = |x| ...Hyperbolic cosine.
let cosh = |x| ...Hyperbolic tangent.
let tanh = |x| ...Absolute value.
let abs = |x| ...Sign of a number: -1, 0, or 1.
let sign = |x| ...Largest integer not greater than x.
let floor = |x| ...Smallest integer not less than x.
let ceil = |x| ...Round to the nearest integer.
let round = |x| ...Truncate fractional part.
let trunc = |x| ...Euclidean remainder of n divided by m.
The result has the sign of the divisor, so mod(-1, 4) returns 3.
let mod = |n, m| ...Pairwise minimum of two numbers.
let min = |a, b| ...Pairwise maximum of two numbers.
let max = |a, b| ...Pin x to the inclusive range [low, high].
let clamp = |low, x, high| min(high, max(low, x))let opacity = clamp(0, raw_opacity, 1)Rectified linear unit, max(0, x).
let relu = |x| max(0, x)Logistic sigmoid.
let sigmoid = |x| 1 / (1 + exp(-x))Deterministic scene random float in [low, high].
Random helpers advance executor state and are only allowed in the root frame, not inside lambdas or default arguments. Re-running the same scene uses the same deterministic sequence.
let random = |low = 0, high = 1| ...let jitter = random(-0.1, 0.1)Deterministic scene random integer in [low, high).
high is exclusive and must be greater than low. Like random, this can only be called from the root frame.
let randint = |low, high| ...Factorial of a non-negative integer.
let factorial = |n| ...Number of ways to choose r items from n.
Returns 0 when r < 0 or r > n.
let choose = |n, r| ...Number of ordered arrangements of r items from n.
Returns 0 when r < 0 or r > n.
let permute = |n, r| ...Greatest common divisor.
let gcd = |n, m| ...Least common multiple.
let lcm = |n, m| ...Test whether n is prime.
let is_prime = |n| ...A random-looking float in [0, 1) that depends only on its arguments.
Unlike random, this is a pure function: the same seed and salt always give the same value, and it can be used anywhere, including inside lambdas evaluated per vertex, pixel or particle. Pass an index as the seed and a different salt for each quantity you need.
let seeded_random = |seed, salt = 0| mod(sin(seed * 12.9898 + salt * 78.233) * 43758.5453, 1)let Star = |i| {
let u = seeded_random(i)
let v = seeded_random(i, 1)
...
}Dot product of two vectors.
let dot = |u, v| ...Cross product of two 3-D vectors.
let cross = |u, v| ...Euclidean length of a vector.
let norm = |v| sqrt(dot(v, v))Unit vector in the same direction as v.
Does not guard against the zero vector.
let normalize = |v| v * (1 / norm(v))Projection of vector u onto vector v.
let proj = |u, v| v * (dot(u, v) / dot(v, v))Angle between two vectors, in radians.
let angle_between = |u, v| arccos(dot(u, v) / (norm(u) * norm(v)))Interpolate between values according to Monocurl's value interpolation rules.
Rules are applied in order: equal values return the first value unchanged; numbers and complex numbers blend linearly; invoked operators are matched by operator-stack depth, with deeper chains peeled through their operator embed; matching invoked operators must use the same operator and labels, then lerp the operand and labeled arguments; matching live functions must call the same lambda with the same labels, then lerp labeled arguments and rerun the function; lists require equal length and maps require equal keys, then lerp elementwise. Differing unlabeled call arguments and unrelated non-numeric values are interpolation errors.
let lerp = |a, b, t| ...let midway = lerp(LEFT, RIGHT, 0.5)
let purple = lerp(BLUE, MAGENTA, 0.5)Piecewise interpolation through keyed values.
Keyframes must be a map from numeric times to values. Entries are sorted by numeric key, and values outside the first/last keyframe clamp to the endpoint value.
let keyframe_lerp = |keyframes, t| ...keyframes | map of t -> value pairs |
t | normalized lookup point |
let col = keyframe_lerp([0 -> BLUE, 0.5 -> CYAN, 1 -> WHITE], phase)Remap x linearly from one interval into another.
let map_range = |x, in_min, in_max, out_min, out_max| out_min + (x - in_min) / (in_max - in_min) * (out_max - out_min)let opacity = map_range(frame, 0, 30, 0, 1)Convert degrees to radians.
Numeric literals can use the dg suffix; use this for runtime values.
let deg_to_rad = |x| x * (PI / 180)Convert radians to degrees.
let rad_to_deg = |x| x * (180 / PI)