Skip to content

Mathematical constants and functions

Constants

In Sidefx houdini we have some predefined math constants that can be used in VEX code. Here is a list of some of the most common ones:

M_E 2.7182818 // Euler's number (approximately 2.7182818)
LN10 2.3025850 // Natural logarithm of 10 (approximately 2.3025850)
LN2 0.6931471 // Natural logarithm of 2 (approximately 0.6931471)
LOG10E 0.4342944 // Base 10 logarithm of Euler's number (approximately 0.4342944)
LOG2E 1.4426950 // Base 2 logarithm of Euler's number (approximately 1.4426950)
PI 3.1415926 // The mathematical constant pi (approximately 3.1415926)
M_TWO_PI 6.2831852 // Twice the value of pi (approximately 6.2831852)
PI_2 1.5707963 // Half the value of pi (approximately 1.5707963)
PI_4 0.7853981 // Quarter of the value of pi (approximately 0.7853981)
SQRT1_2 0.7071067 // Square root of 1/2 (approximately 0.7071067)
SQRT2 1.4142135 // Square root of 2 (approximately 1.4142135)
TOLERANCE 0.0001 // A small tolerance value (approximately 0.0001)

Functions

Additionally to constants VEX has a number of built-in functions that can be used to perform common mathematical operations. Here is a list of some of the most common ones:

abs() // Absolute value (magnitude)
acos() // Arc cosine (inverse cosine)
asin() // Arc sine (inverse sine)
atan() // Arc tangent (inverse tangent)
atan2() // Arc tangent of two variables (y, x)
tan() // Tangent (opposite/adjacent)
ceil() // Smallest integer value not less than the argument (rounds up)
clamp() // Clamps a value to a specified range (min, max)
cos() // Cosine (adjacent/hypotenuse)
cosh() // Hyperbolic cosine (e^x + e^-x)/2
cross() // Cross product (vector product)
sin() // Sine (opposite/hypotenuse)
degrees() // Converts radians to degrees (x * 180/pi)
distance() // Distance between two points (magnitude of the difference)
dot() // Dot product (scalar product)
exp() // Exponential (base e)
exp2() // Base 2 exponential (2^x)
fit() // Fits a value from one range to another (linear interpolation)
floor() // Largest integer value not greater than the argument (rounds down)
length() // Length of a vector (magnitude)
log() // Natural logarithm (base e)
max() // Maximum value (x, y)
min() // Minimum value (x, y)
normalize() // Normalizes a vector (length = 1)
pow() // Power (x^y)
radians() // Converts degrees to radians (x * pi/180)
round() // Rounds to the nearest integer (0.5 rounds up)
sign() // Sign of a number (-1, 0, 1)
sinh() // Hyperbolic sine (e^x - e^-x)/2
sqrt() // Square root (x^0.5)
step() // Step function (returns 0 if x < edge, 1 if x >= edge)