Standard Library#
- public class StdLib#
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.
- double getPi()#
The constant pi.
- double getE()#
The constant e, the base of the natural logarithm.
- double abs(double x)#
The absolute value of a number.
- Parameters:
x (
double) – The number.
- int sign(double 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 (
double) – The number.
- double copySign(double x, double y)#
The magnitude of the first number with the sign of the second.
- Parameters:
x (
double) – The number giving the magnitude.y (
double) – The number giving the sign.
- boolean isNan(double x)#
Whether a number is not a number.
- Parameters:
x (
double) – The number.
- boolean isFinite(double x)#
Whether a number is neither infinite nor not a number.
- Parameters:
x (
double) – The number.
- double floor(double x)#
The largest whole number less than or equal to the given number.
- Parameters:
x (
double) – The number.
- double ceiling(double x)#
The smallest whole number greater than or equal to the given number.
- Parameters:
x (
double) – The number.
- double round(double x, int digits)#
The given number rounded to the given number of decimal places, with a halfway value rounded to the nearer even number.
- Parameters:
x (
double) – The number.digits (
int) – The number of decimal places to round to. Negative to round to tens, hundreds and beyond.
Note
Throws an exception if the rounded value is too large for a double.
- double roundHalfAwayFromZero(double x, int digits)#
The given number rounded to the given number of decimal places, with a halfway value rounded away from zero.
- Parameters:
x (
double) – The number.digits (
int) – The number of decimal places to round to. Negative to round to tens, hundreds and beyond.
Note
Throws an exception if the rounded value is too large for a double.
- double roundHalfUp(double x, int digits)#
The given number rounded to the given number of decimal places, with a halfway value rounded toward positive infinity.
- Parameters:
x (
double) – The number.digits (
int) – The number of decimal places to round to. Negative to round to tens, hundreds and beyond.
Note
Throws an exception if the rounded value is too large for a double.
- double sqrt(double x)#
The square root of a number.
- Parameters:
x (
double) – The number.
- double hypot(double x, double y)#
The length of the hypotenuse of a right triangle with the given sides.
- Parameters:
x (
double) – The first side.y (
double) – The second side.
- double sin(double x)#
The sine of an angle, in radians.
- Parameters:
x (
double) – The angle.
- double cos(double x)#
The cosine of an angle, in radians.
- Parameters:
x (
double) – The angle.
- double tan(double x)#
The tangent of an angle, in radians.
- Parameters:
x (
double) – The angle.
- double asin(double x)#
The angle, in radians, whose sine is the given number.
- Parameters:
x (
double) – The number.
- double acos(double x)#
The angle, in radians, whose cosine is the given number.
- Parameters:
x (
double) – The number.
- double atan(double x)#
The angle, in radians, whose tangent is the given number.
- Parameters:
x (
double) – The number.
- double atan2(double y, double x)#
The angle, in radians, between the positive x axis and the point (x, y).
- Parameters:
y (
double) – The y coordinate.x (
double) – The x coordinate.
- double log(double x, double newBase)#
The logarithm of a number, natural unless another base is given.
- Parameters:
x (
double) – The number.newBase (
double) – The base of the logarithm.
- double log10(double x)#
The base 10 logarithm of a number.
- Parameters:
x (
double) – The number.
- double exp(double x)#
The number e raised to the given power.
- Parameters:
x (
double) – The power.
- double min(double x, double y)#
The smaller of two numbers.
- Parameters:
x (
double) – The first number.y (
double) – The second number.
- double max(double x, double y)#
The larger of two numbers.
- Parameters:
x (
double) – The first number.y (
double) – The second number.
- double clamp(double x, double min, double max)#
The given number limited to the given range.
- Parameters:
x (
double) – The number.min (
double) – The minimum of the range.max (
double) – The maximum of the range.
Note
Throws an exception if the minimum is greater than the maximum.
- double lerp(double a, double b, double t)#
Linear interpolation between two numbers.
- Parameters:
a (
double) – The number when t is 0.b (
double) – The number when t is 1.t (
double) – The interpolation parameter.
Note
The parameter is not limited to the range 0 to 1, and a value outside it extrapolates.
- double inverseLerp(double a, double b, double x)#
The interpolation parameter of a number between two others, limited to the range 0 to 1.
- Parameters:
a (
double) – The number at 0.b (
double) – The number at 1.x (
double) – The number.
Note
Returns 0 if the two numbers are equal.
- double degreesToRadians(double x)#
The angle in radians of an angle in degrees.
- Parameters:
x (
double) – The angle in degrees.
- double radiansToDegrees(double x)#
The angle in degrees of an angle in radians.
- Parameters:
x (
double) – The angle in radians.
- org.javatuples.Triplet<Double, Double, Double> vectorAdd(org.javatuples.Triplet<Double, Double, Double> u, org.javatuples.Triplet<Double, Double, Double> v)#
The sum of two vectors.
- Parameters:
u (
org.javatuples.Triplet) – The first vector.v (
org.javatuples.Triplet) – The second vector.
- org.javatuples.Triplet<Double, Double, Double> vectorSubtract(org.javatuples.Triplet<Double, Double, Double> u, org.javatuples.Triplet<Double, Double, Double> v)#
The difference of two vectors.
- Parameters:
u (
org.javatuples.Triplet) – The first vector.v (
org.javatuples.Triplet) – The second vector.
- org.javatuples.Triplet<Double, Double, Double> vectorScale(org.javatuples.Triplet<Double, Double, Double> v, double scale)#
A vector scaled by a number.
- Parameters:
v (
org.javatuples.Triplet) – The vector.scale (
double) – The scaling factor.
- double vectorDot(org.javatuples.Triplet<Double, Double, Double> u, org.javatuples.Triplet<Double, Double, Double> v)#
The dot product of two vectors.
- Parameters:
u (
org.javatuples.Triplet) – The first vector.v (
org.javatuples.Triplet) – The second vector.
- org.javatuples.Triplet<Double, Double, Double> vectorCross(org.javatuples.Triplet<Double, Double, Double> u, org.javatuples.Triplet<Double, Double, Double> v)#
The cross product of two vectors.
- Parameters:
u (
org.javatuples.Triplet) – The first vector.v (
org.javatuples.Triplet) – The second vector.
- double vectorMagnitude(org.javatuples.Triplet<Double, Double, Double> v)#
The magnitude (length) of a vector.
- Parameters:
v (
org.javatuples.Triplet) – The vector.
- org.javatuples.Triplet<Double, Double, Double> vectorNormalize(org.javatuples.Triplet<Double, Double, Double> v)#
A vector scaled to a magnitude of 1.
- Parameters:
v (
org.javatuples.Triplet) – The vector.
Note
Throws an exception if the vector is zero.
- double vectorDistance(org.javatuples.Triplet<Double, Double, Double> u, org.javatuples.Triplet<Double, Double, Double> v)#
The distance between two positions.
- Parameters:
u (
org.javatuples.Triplet) – The first position.v (
org.javatuples.Triplet) – The second position.
- double vectorAngle(org.javatuples.Triplet<Double, Double, Double> u, org.javatuples.Triplet<Double, Double, Double> v)#
The angle between two vectors, in radians, between 0 and pi.
- Parameters:
u (
org.javatuples.Triplet) – The first vector.v (
org.javatuples.Triplet) – The second vector.
Note
Throws an exception if either vector is zero.
- org.javatuples.Triplet<Double, Double, Double> vectorLerp(org.javatuples.Triplet<Double, Double, Double> u, org.javatuples.Triplet<Double, Double, Double> v, double t)#
Linear interpolation between two vectors.
- Parameters:
u (
org.javatuples.Triplet) – The vector when t is 0.v (
org.javatuples.Triplet) – The vector when t is 1.t (
double) – The interpolation parameter.
Note
The parameter is not limited to the range 0 to 1, and a value outside it extrapolates.
- org.javatuples.Quartet<Double, Double, Double, Double> quaternionMultiply(org.javatuples.Quartet<Double, Double, Double, Double> q, org.javatuples.Quartet<Double, Double, Double, Double> r)#
The composition of two rotations: the rotation r followed by the rotation q.
- Parameters:
q (
org.javatuples.Quartet) – The second rotation.r (
org.javatuples.Quartet) – The first rotation.
Note
Throws an exception if either quaternion is zero.
- org.javatuples.Quartet<Double, Double, Double, Double> quaternionInverse(org.javatuples.Quartet<Double, Double, Double, Double> q)#
The inverse of a rotation.
- Parameters:
q (
org.javatuples.Quartet) – The rotation.
Note
Throws an exception if the quaternion is zero.
- org.javatuples.Triplet<Double, Double, Double> quaternionRotateVector(org.javatuples.Quartet<Double, Double, Double, Double> q, org.javatuples.Triplet<Double, Double, Double> v)#
A vector rotated by a rotation.
- Parameters:
q (
org.javatuples.Quartet) – The rotation.v (
org.javatuples.Triplet) – The vector.
Note
Throws an exception if the quaternion is zero.
- org.javatuples.Quartet<Double, Double, Double, Double> quaternionFromAxisAngle(org.javatuples.Triplet<Double, Double, Double> axis, double angle)#
The rotation about an axis by an angle.
- Parameters:
axis (
org.javatuples.Triplet) – The axis of rotation.angle (
double) – The angle of rotation, in radians.
Note
Throws an exception if the axis is zero.
- AxisAngle quaternionToAxisAngle(org.javatuples.Quartet<Double, Double, Double, Double> q)#
The axis and angle of a rotation.
- Parameters:
q (
org.javatuples.Quartet) – The rotation.
Note
Throws an exception if the quaternion is zero.
- org.javatuples.Quartet<Double, Double, Double, Double> quaternionFromToRotation(org.javatuples.Triplet<Double, Double, Double> u, org.javatuples.Triplet<Double, Double, Double> v)#
The shortest rotation that takes one direction onto another.
- Parameters:
u (
org.javatuples.Triplet) – The direction to rotate from.v (
org.javatuples.Triplet) – The direction to rotate to.
Note
Opposite directions give a half turn about an arbitrary perpendicular axis. Throws an exception if either vector is zero.
- org.javatuples.Quartet<Double, Double, Double, Double> quaternionLookRotation(org.javatuples.Triplet<Double, Double, Double> forward, org.javatuples.Triplet<Double, Double, Double> up)#
The rotation that takes the z axis onto a forward direction, and the y axis toward an up direction.
- Parameters:
forward (
org.javatuples.Triplet) – The direction of the z axis.up (
org.javatuples.Triplet) – The direction the y axis points toward.
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.
- double quaternionAngle(org.javatuples.Quartet<Double, Double, Double, Double> q, org.javatuples.Quartet<Double, Double, Double, Double> r)#
The angle of the rotation that takes one rotation to another, in radians, between 0 and pi.
- Parameters:
q (
org.javatuples.Quartet) – The first rotation.r (
org.javatuples.Quartet) – The second rotation.
Note
Throws an exception if either quaternion is zero.
- org.javatuples.Quartet<Double, Double, Double, Double> quaternionSlerp(org.javatuples.Quartet<Double, Double, Double, Double> q, org.javatuples.Quartet<Double, Double, Double, Double> r, double t)#
Spherical linear interpolation between two rotations.
- Parameters:
q (
org.javatuples.Quartet) – The rotation when t is 0.r (
org.javatuples.Quartet) – The rotation when t is 1.t (
double) – The interpolation parameter.
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.
- public class AxisAngle#
A rotation as an axis and an angle.
- public AxisAngle(org.javatuples.Triplet<Double, Double, Double> axis, double angle)#
Construct a AxisAngle from the values of its fields.
- org.javatuples.Triplet<Double, Double, Double> getAxis()#
The axis of the rotation, as a unit vector, or zero for no rotation.
- double getAngle()#
The angle of the rotation, in radians between 0 and pi.
- public class ColorRGB#
A color, as red, green and blue components between 0 and 1.
- public ColorRGB(float r, float g, float b)#
Construct a ColorRGB from the values of its fields.
- float getR()#
The red component.
- float getG()#
The green component.
- float getB()#
The blue component.
- public class 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.
- public ColorRGBA(float r, float g, float b, float a)#
Construct a ColorRGBA from the values of its fields.
- float getR()#
The red component.
- float getG()#
The green component.
- float getB()#
The blue component.
- float getA()#
The alpha component.