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.
- GET /std-lib/pi#
The constant pi.
- Response JSON Object:
value (double)
- GET /std-lib/e#
The constant e, the base of the natural logarithm.
- Response JSON Object:
value (double)
- POST /std-lib/abs#
The absolute value of a number.
- Request JSON Object:
x (double) – The number.
- Response JSON Object:
value (double)
- POST /std-lib/sign#
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.
- Request JSON Object:
x (double) – The number.
- Response JSON Object:
value (int32)
- POST /std-lib/copy-sign#
The magnitude of the first number with the sign of the second.
- Request JSON Object:
x (double) – The number giving the magnitude.
y (double) – The number giving the sign.
- Response JSON Object:
value (double)
- POST /std-lib/is-nan#
Whether a number is not a number.
- Request JSON Object:
x (double) – The number.
- Response JSON Object:
value (bool)
- POST /std-lib/is-finite#
Whether a number is neither infinite nor not a number.
- Request JSON Object:
x (double) – The number.
- Response JSON Object:
value (bool)
- POST /std-lib/floor#
The largest whole number less than or equal to the given number.
- Request JSON Object:
x (double) – The number.
- Response JSON Object:
value (double)
- POST /std-lib/ceiling#
The smallest whole number greater than or equal to the given number.
- Request JSON Object:
x (double) – The number.
- Response JSON Object:
value (double)
- POST /std-lib/round#
The given number rounded to the given number of decimal places, with a halfway value rounded to the nearer even number.
Note
Throws an exception if the rounded value is too large for a double.
- Request JSON Object:
x (double) – The number.
digits (int32) – The number of decimal places to round to. Negative to round to tens, hundreds and beyond. Optional, defaults to
0.
- Response JSON Object:
value (double)
- POST /std-lib/round-half-away-from-zero#
The given number rounded to the given number of decimal places, with a halfway value rounded away from zero.
Note
Throws an exception if the rounded value is too large for a double.
- Request JSON Object:
x (double) – The number.
digits (int32) – The number of decimal places to round to. Negative to round to tens, hundreds and beyond. Optional, defaults to
0.
- Response JSON Object:
value (double)
- POST /std-lib/round-half-up#
The given number rounded to the given number of decimal places, with a halfway value rounded toward positive infinity.
Note
Throws an exception if the rounded value is too large for a double.
- Request JSON Object:
x (double) – The number.
digits (int32) – The number of decimal places to round to. Negative to round to tens, hundreds and beyond. Optional, defaults to
0.
- Response JSON Object:
value (double)
- POST /std-lib/sqrt#
The square root of a number.
- Request JSON Object:
x (double) – The number.
- Response JSON Object:
value (double)
- POST /std-lib/hypot#
The length of the hypotenuse of a right triangle with the given sides.
- Request JSON Object:
x (double) – The first side.
y (double) – The second side.
- Response JSON Object:
value (double)
- POST /std-lib/sin#
The sine of an angle, in radians.
- Request JSON Object:
x (double) – The angle.
- Response JSON Object:
value (double)
- POST /std-lib/cos#
The cosine of an angle, in radians.
- Request JSON Object:
x (double) – The angle.
- Response JSON Object:
value (double)
- POST /std-lib/tan#
The tangent of an angle, in radians.
- Request JSON Object:
x (double) – The angle.
- Response JSON Object:
value (double)
- POST /std-lib/asin#
The angle, in radians, whose sine is the given number.
- Request JSON Object:
x (double) – The number.
- Response JSON Object:
value (double)
- POST /std-lib/acos#
The angle, in radians, whose cosine is the given number.
- Request JSON Object:
x (double) – The number.
- Response JSON Object:
value (double)
- POST /std-lib/atan#
The angle, in radians, whose tangent is the given number.
- Request JSON Object:
x (double) – The number.
- Response JSON Object:
value (double)
- POST /std-lib/atan2#
The angle, in radians, between the positive x axis and the point
(x, y).- Request JSON Object:
y (double) – The y coordinate.
x (double) – The x coordinate.
- Response JSON Object:
value (double)
- POST /std-lib/log#
The logarithm of a number, natural unless another base is given.
- Request JSON Object:
x (double) – The number.
new_base (double) – The base of the logarithm. Optional, defaults to
2.718281828459045.
- Response JSON Object:
value (double)
- POST /std-lib/log10#
The base 10 logarithm of a number.
- Request JSON Object:
x (double) – The number.
- Response JSON Object:
value (double)
- POST /std-lib/exp#
The number e raised to the given power.
- Request JSON Object:
x (double) – The power.
- Response JSON Object:
value (double)
- POST /std-lib/min#
The smaller of two numbers.
- Request JSON Object:
x (double) – The first number.
y (double) – The second number.
- Response JSON Object:
value (double)
- POST /std-lib/max#
The larger of two numbers.
- Request JSON Object:
x (double) – The first number.
y (double) – The second number.
- Response JSON Object:
value (double)
- POST /std-lib/clamp#
The given number limited to the given range.
Note
Throws an exception if the minimum is greater than the maximum.
- Request JSON Object:
x (double) – The number.
min (double) – The minimum of the range.
max (double) – The maximum of the range.
- Response JSON Object:
value (double)
- POST /std-lib/lerp#
Linear interpolation between two numbers.
Note
The parameter is not limited to the range 0 to 1, and a value outside it extrapolates.
- Request JSON Object:
a (double) – The number when t is 0.
b (double) – The number when t is 1.
t (double) – The interpolation parameter.
- Response JSON Object:
value (double)
- POST /std-lib/inverse-lerp#
The interpolation parameter of a number between two others, limited to the range 0 to 1.
Note
Returns 0 if the two numbers are equal.
- Request JSON Object:
a (double) – The number at 0.
b (double) – The number at 1.
x (double) – The number.
- Response JSON Object:
value (double)
- POST /std-lib/degrees-to-radians#
The angle in radians of an angle in degrees.
- Request JSON Object:
x (double) – The angle in degrees.
- Response JSON Object:
value (double)
- POST /std-lib/radians-to-degrees#
The angle in degrees of an angle in radians.
- Request JSON Object:
x (double) – The angle in radians.
- Response JSON Object:
value (double)
- POST /std-lib/vector-add#
The sum of two vectors.
- Request JSON Object:
u (tuple<double, double, double>) – The first vector.
v (tuple<double, double, double>) – The second vector.
- Response JSON Object:
value (tuple<double, double, double>)
- POST /std-lib/vector-subtract#
The difference of two vectors.
- Request JSON Object:
u (tuple<double, double, double>) – The first vector.
v (tuple<double, double, double>) – The second vector.
- Response JSON Object:
value (tuple<double, double, double>)
- POST /std-lib/vector-scale#
A vector scaled by a number.
- Request JSON Object:
v (tuple<double, double, double>) – The vector.
scale (double) – The scaling factor.
- Response JSON Object:
value (tuple<double, double, double>)
- POST /std-lib/vector-dot#
The dot product of two vectors.
- Request JSON Object:
u (tuple<double, double, double>) – The first vector.
v (tuple<double, double, double>) – The second vector.
- Response JSON Object:
value (double)
- POST /std-lib/vector-cross#
The cross product of two vectors.
- Request JSON Object:
u (tuple<double, double, double>) – The first vector.
v (tuple<double, double, double>) – The second vector.
- Response JSON Object:
value (tuple<double, double, double>)
- POST /std-lib/vector-magnitude#
The magnitude (length) of a vector.
- Request JSON Object:
v (tuple<double, double, double>) – The vector.
- Response JSON Object:
value (double)
- POST /std-lib/vector-normalize#
A vector scaled to a magnitude of 1.
Note
Throws an exception if the vector is zero.
- Request JSON Object:
v (tuple<double, double, double>) – The vector.
- Response JSON Object:
value (tuple<double, double, double>)
- POST /std-lib/vector-distance#
The distance between two positions.
- Request JSON Object:
u (tuple<double, double, double>) – The first position.
v (tuple<double, double, double>) – The second position.
- Response JSON Object:
value (double)
- POST /std-lib/vector-angle#
The angle between two vectors, in radians, between 0 and \(\pi\).
Note
Throws an exception if either vector is zero.
- Request JSON Object:
u (tuple<double, double, double>) – The first vector.
v (tuple<double, double, double>) – The second vector.
- Response JSON Object:
value (double)
- POST /std-lib/vector-lerp#
Linear interpolation between two vectors.
Note
The parameter is not limited to the range 0 to 1, and a value outside it extrapolates.
- Request JSON Object:
u (tuple<double, double, double>) – The vector when t is 0.
v (tuple<double, double, double>) – The vector when t is 1.
t (double) – The interpolation parameter.
- Response JSON Object:
value (tuple<double, double, double>)
- POST /std-lib/quaternion-multiply#
The composition of two rotations: the rotation r followed by the rotation q.
Note
Throws an exception if either quaternion is zero.
- Request JSON Object:
q (tuple<double, double, double, double>) – The second rotation.
r (tuple<double, double, double, double>) – The first rotation.
- Response JSON Object:
value (tuple<double, double, double, double>)
- POST /std-lib/quaternion-inverse#
The inverse of a rotation.
Note
Throws an exception if the quaternion is zero.
- Request JSON Object:
q (tuple<double, double, double, double>) – The rotation.
- Response JSON Object:
value (tuple<double, double, double, double>)
- POST /std-lib/quaternion-rotate-vector#
A vector rotated by a rotation.
Note
Throws an exception if the quaternion is zero.
- Request JSON Object:
q (tuple<double, double, double, double>) – The rotation.
v (tuple<double, double, double>) – The vector.
- Response JSON Object:
value (tuple<double, double, double>)
- POST /std-lib/quaternion-from-axis-angle#
The rotation about an axis by an angle.
Note
Throws an exception if the axis is zero.
- Request JSON Object:
axis (tuple<double, double, double>) – The axis of rotation.
angle (double) – The angle of rotation, in radians.
- Response JSON Object:
value (tuple<double, double, double, double>)
- POST /std-lib/quaternion-to-axis-angle#
The axis and angle of a rotation.
Note
Throws an exception if the quaternion is zero.
- Request JSON Object:
q (tuple<double, double, double, double>) – The rotation.
- Response JSON Object:
value (StdLib.AxisAngle)
- POST /std-lib/quaternion-from-to-rotation#
The shortest rotation that takes one direction onto another.
Note
Opposite directions give a half turn about an arbitrary perpendicular axis. Throws an exception if either vector is zero.
- Request JSON Object:
u (tuple<double, double, double>) – The direction to rotate from.
v (tuple<double, double, double>) – The direction to rotate to.
- Response JSON Object:
value (tuple<double, double, double, double>)
- POST /std-lib/quaternion-look-rotation#
The rotation that takes the z axis onto a forward direction, and the y axis toward an up direction.
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.
- Request JSON Object:
forward (tuple<double, double, double>) – The direction of the z axis.
up (tuple<double, double, double>) – The direction the y axis points toward.
- Response JSON Object:
value (tuple<double, double, double, double>)
- POST /std-lib/quaternion-angle#
The angle of the rotation that takes one rotation to another, in radians, between 0 and \(\pi\).
Note
Throws an exception if either quaternion is zero.
- Request JSON Object:
q (tuple<double, double, double, double>) – The first rotation.
r (tuple<double, double, double, double>) – The second rotation.
- Response JSON Object:
value (double)
- POST /std-lib/quaternion-slerp#
Spherical linear interpolation between two rotations.
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.
- Request JSON Object:
q (tuple<double, double, double, double>) – The rotation when t is 0.
r (tuple<double, double, double, double>) – The rotation when t is 1.
t (double) – The interpolation parameter.
- Response JSON Object:
value (tuple<double, double, double, double>)
- POST /std-lib/print#
Writes a message to the game’s log, for debugging.
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.
- Request JSON Object:
message (string) – The message.
AxisAngle
A rotation as an axis and an angle.
Note
Passed and returned as an object with these fields:
axis(tuple<double, double, double>)The axis of the rotation, as a unit vector, or zero for no rotation.
angle(double)The angle of the rotation, in radians between 0 and \(\pi\).
ColorRGB
A color, as red, green and blue components between 0 and 1.
Passed and returned as an object with these fields:
r(float)The red component.
g(float)The green component.
b(float)The blue component.
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.
Passed and returned as an object with these fields:
r(float)The red component.
g(float)The green component.
b(float)The blue component.
a(float)The alpha component.
ImageFormat
The file format of an image.
Passed and returned as the name of one of its values:
"png"PNG, which is lossless.
"jpeg"JPEG, which is lossy, and smaller and faster to encode than PNG.