Standard Library#
A standard library of mathematics and printing for server side functions, and of the colors other services use.
Note
Vectors are position and direction tuples, and rotations are unit quaternion tuples in the order x, y, z, w the SpaceCenter service uses. Angles are in radians unless stated otherwise.
- pi: number#
The constant pi.
- Attribute:
Read-only, cannot be set
- Return type:
number
- e: number#
The constant e, the base of the natural logarithm.
- Attribute:
Read-only, cannot be set
- Return type:
number
- static abs(x)#
The absolute value of a number.
- Parameters:
x (
number) – The number.- Return type:
number
- static sign(x)#
The sign of a number: -1 if it is negative, 1 if it is positive, and 0 if it is zero or not a number.
- Parameters:
x (
number) – The number.- Return type:
number
- static copy_sign(x, y)#
The magnitude of the first number with the sign of the second.
- Parameters:
x (
number) – The number giving the magnitude.y (
number) – The number giving the sign.
- Return type:
number
- static is_nan(x)#
Whether a number is not a number.
- Parameters:
x (
number) – The number.- Return type:
boolean
- static is_finite(x)#
Whether a number is neither infinite nor not a number.
- Parameters:
x (
number) – The number.- Return type:
boolean
- static floor(x)#
The largest whole number less than or equal to the given number.
- Parameters:
x (
number) – The number.- Return type:
number
- static ceiling(x)#
The smallest whole number greater than or equal to the given number.
- Parameters:
x (
number) – The number.- Return type:
number
- static round(x[, digits = 0])#
The given number rounded to the given number of decimal places, with a halfway value rounded to the nearer even number.
- Parameters:
x (
number) – The number.digits (
number) – The number of decimal places to round to. Negative to round to tens, hundreds and beyond.
- Return type:
number
Note
Throws an exception if the rounded value is too large for a double.
- static round_half_away_from_zero(x[, digits = 0])#
The given number rounded to the given number of decimal places, with a halfway value rounded away from zero.
- Parameters:
x (
number) – The number.digits (
number) – The number of decimal places to round to. Negative to round to tens, hundreds and beyond.
- Return type:
number
Note
Throws an exception if the rounded value is too large for a double.
- static round_half_up(x[, digits = 0])#
The given number rounded to the given number of decimal places, with a halfway value rounded toward positive infinity.
- Parameters:
x (
number) – The number.digits (
number) – The number of decimal places to round to. Negative to round to tens, hundreds and beyond.
- Return type:
number
Note
Throws an exception if the rounded value is too large for a double.
- static sqrt(x)#
The square root of a number.
- Parameters:
x (
number) – The number.- Return type:
number
- static hypot(x, y)#
The length of the hypotenuse of a right triangle with the given sides.
- Parameters:
x (
number) – The first side.y (
number) – The second side.
- Return type:
number
- static sin(x)#
The sine of an angle, in radians.
- Parameters:
x (
number) – The angle.- Return type:
number
- static cos(x)#
The cosine of an angle, in radians.
- Parameters:
x (
number) – The angle.- Return type:
number
- static tan(x)#
The tangent of an angle, in radians.
- Parameters:
x (
number) – The angle.- Return type:
number
- static asin(x)#
The angle, in radians, whose sine is the given number.
- Parameters:
x (
number) – The number.- Return type:
number
- static acos(x)#
The angle, in radians, whose cosine is the given number.
- Parameters:
x (
number) – The number.- Return type:
number
- static atan(x)#
The angle, in radians, whose tangent is the given number.
- Parameters:
x (
number) – The number.- Return type:
number
- static atan2(y, x)#
The angle, in radians, between the positive x axis and the point (x, y).
- Parameters:
y (
number) – The y coordinate.x (
number) – The x coordinate.
- Return type:
number
- static log(x[, new_base = 2.718281828459045])#
The logarithm of a number, natural unless another base is given.
- Parameters:
x (
number) – The number.new_base (
number) – The base of the logarithm.
- Return type:
number
- static log10(x)#
The base 10 logarithm of a number.
- Parameters:
x (
number) – The number.- Return type:
number
- static exp(x)#
The number e raised to the given power.
- Parameters:
x (
number) – The power.- Return type:
number
- static min(x, y)#
The smaller of two numbers.
- Parameters:
x (
number) – The first number.y (
number) – The second number.
- Return type:
number
- static max(x, y)#
The larger of two numbers.
- Parameters:
x (
number) – The first number.y (
number) – The second number.
- Return type:
number
- static clamp(x, min, max)#
The given number limited to the given range.
- Parameters:
x (
number) – The number.min (
number) – The minimum of the range.max (
number) – The maximum of the range.
- Return type:
number
Note
Throws an exception if the minimum is greater than the maximum.
- static lerp(a, b, t)#
Linear interpolation between two numbers.
- Parameters:
a (
number) – The number when t is 0.b (
number) – The number when t is 1.t (
number) – The interpolation parameter.
- Return type:
number
Note
The parameter is not limited to the range 0 to 1, and a value outside it extrapolates.
- static inverse_lerp(a, b, x)#
The interpolation parameter of a number between two others, limited to the range 0 to 1.
- Parameters:
a (
number) – The number at 0.b (
number) – The number at 1.x (
number) – The number.
- Return type:
number
Note
Returns 0 if the two numbers are equal.
- static degrees_to_radians(x)#
The angle in radians of an angle in degrees.
- Parameters:
x (
number) – The angle in degrees.- Return type:
number
- static radians_to_degrees(x)#
The angle in degrees of an angle in radians.
- Parameters:
x (
number) – The angle in radians.- Return type:
number
- static vector_add(u, v)#
The sum of two vectors.
- Parameters:
u (
Tuple) – The first vector.v (
Tuple) – The second vector.
- Return type:
Tuple
- static vector_subtract(u, v)#
The difference of two vectors.
- Parameters:
u (
Tuple) – The first vector.v (
Tuple) – The second vector.
- Return type:
Tuple
- static vector_scale(v, scale)#
A vector scaled by a number.
- Parameters:
v (
Tuple) – The vector.scale (
number) – The scaling factor.
- Return type:
Tuple
- static vector_dot(u, v)#
The dot product of two vectors.
- Parameters:
u (
Tuple) – The first vector.v (
Tuple) – The second vector.
- Return type:
number
- static vector_cross(u, v)#
The cross product of two vectors.
- Parameters:
u (
Tuple) – The first vector.v (
Tuple) – The second vector.
- Return type:
Tuple
- static vector_magnitude(v)#
The magnitude (length) of a vector.
- Parameters:
v (
Tuple) – The vector.- Return type:
number
- static vector_normalize(v)#
A vector scaled to a magnitude of 1.
- Parameters:
v (
Tuple) – The vector.- Return type:
Tuple
Note
Throws an exception if the vector is zero.
- static vector_distance(u, v)#
The distance between two positions.
- Parameters:
u (
Tuple) – The first position.v (
Tuple) – The second position.
- Return type:
number
- static vector_angle(u, v)#
The angle between two vectors, in radians, between 0 and pi.
- Parameters:
u (
Tuple) – The first vector.v (
Tuple) – The second vector.
- Return type:
number
Note
Throws an exception if either vector is zero.
- static vector_lerp(u, v, t)#
Linear interpolation between two vectors.
- Parameters:
u (
Tuple) – The vector when t is 0.v (
Tuple) – The vector when t is 1.t (
number) – The interpolation parameter.
- Return type:
Tuple
Note
The parameter is not limited to the range 0 to 1, and a value outside it extrapolates.
- static quaternion_multiply(q, r)#
The composition of two rotations: the rotation r followed by the rotation q.
- Parameters:
q (
Tuple) – The second rotation.r (
Tuple) – The first rotation.
- Return type:
Tuple
Note
Throws an exception if either quaternion is zero.
- static quaternion_inverse(q)#
The inverse of a rotation.
- Parameters:
q (
Tuple) – The rotation.- Return type:
Tuple
Note
Throws an exception if the quaternion is zero.
- static quaternion_rotate_vector(q, v)#
A vector rotated by a rotation.
- Parameters:
q (
Tuple) – The rotation.v (
Tuple) – The vector.
- Return type:
Tuple
Note
Throws an exception if the quaternion is zero.
- static quaternion_from_axis_angle(axis, angle)#
The rotation about an axis by an angle.
- Parameters:
axis (
Tuple) – The axis of rotation.angle (
number) – The angle of rotation, in radians.
- Return type:
Tuple
Note
Throws an exception if the axis is zero.
- static quaternion_to_axis_angle(q)#
The axis and angle of a rotation.
- Parameters:
q (
Tuple) – The rotation.- Return type:
Note
Throws an exception if the quaternion is zero.
- static quaternion_from_to_rotation(u, v)#
The shortest rotation that takes one direction onto another.
- Parameters:
u (
Tuple) – The direction to rotate from.v (
Tuple) – The direction to rotate to.
- Return type:
Tuple
Note
Opposite directions give a half turn about an arbitrary perpendicular axis. Throws an exception if either vector is zero.
- static quaternion_look_rotation(forward, up)#
The rotation that takes the z axis onto a forward direction, and the y axis toward an up direction.
- Parameters:
forward (
Tuple) – The direction of the z axis.up (
Tuple) – The direction the y axis points toward.
- Return type:
Tuple
Note
The up direction need not be perpendicular to the forward direction. Throws an exception if either vector is zero, or if they are parallel.
- static quaternion_angle(q, r)#
The angle of the rotation that takes one rotation to another, in radians, between 0 and pi.
- Parameters:
q (
Tuple) – The first rotation.r (
Tuple) – The second rotation.
- Return type:
number
Note
Throws an exception if either quaternion is zero.
- static quaternion_slerp(q, r, t)#
Spherical linear interpolation between two rotations.
- Parameters:
q (
Tuple) – The rotation when t is 0.r (
Tuple) – The rotation when t is 1.t (
number) – The interpolation parameter.
- Return type:
Tuple
Note
The parameter is not limited to the range 0 to 1, and a value outside it extrapolates. Throws an exception if either quaternion is zero.
- static print(message)#
Writes a message to the game’s log, for debugging.
- Parameters:
message (
string) – The message.
Note
A function evaluated by a stream or an event prints on every update. The message is written at the Info level, so a server log level of Warning or Error hides it.
- class StdLib.AxisAngle#
A rotation as an axis and an angle.
Note
- axis: Tuple#
The axis of the rotation, as a unit vector, or zero for no rotation.
- Return type:
Tuple
- angle: number#
The angle of the rotation, in radians between 0 and pi.
- Return type:
number
- class StdLib.ColorRGB#
A color, as red, green and blue components between 0 and 1.
- r: number#
The red component.
- Return type:
number
- g: number#
The green component.
- Return type:
number
- b: number#
The blue component.
- Return type:
number
- class StdLib.ColorRGBA#
A color, as red, green, blue and alpha components between 0 and 1.
Note
An alpha of 0 is fully transparent and 1 is fully opaque.
- r: number#
The red component.
- Return type:
number
- g: number#
The green component.
- Return type:
number
- b: number#
The blue component.
- Return type:
number
- a: number#
The alpha component.
- Return type:
number