Class MathUtils
java.lang.Object
net.buildtheearth.terraminusminus.util.MathUtils
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic double[]cartesian2Spherical(double[] cartesian) Converts Cartesian coordinates to spherical coordinates on a sphere of radius 1.static doubleclamp(double num, double min, double max) static double[]geo2Spherical(double[] geo) Converts geographic latitude and longitude coordinates to spherical coordinates on a sphere of radius 1.static doublelerp(double a, double min, double max) static double[]matVecProdD(double[][] matrix, double[] vector) Multiples the given matrix with the given vector.static double[][]produceZYZRotationMatrix(double a, double b, double c) TODO produceZYZRotationMatrix javadocstatic intsafeDirectionalShift(int val, int shift) Right-shifts the given value by the given number of bits, safely handling negative shifts and checking for overflow.static double[]spherical2Cartesian(double[] spherical) Converts spherical coordinates to Cartesian coordinates on a sphere of radius 1.static double[]spherical2Geo(double[] spherical) Converts spherical coordinates to geographic coordinates on a sphere of radius 1.static voidtoDegrees(double[] arr) Converts all values in a double array from radians to degreesstatic voidtoRadians(double[] arr) Converts all values in a double array from degrees to radians
-
Field Details
-
ROOT3
public static final double ROOT3Square root of 3 -
TAU
public static final double TAUTwo times pi- See Also:
-
-
Method Details
-
geo2Spherical
public static double[] geo2Spherical(double[] geo) Converts geographic latitude and longitude coordinates to spherical coordinates on a sphere of radius 1.- Parameters:
geo- - geographic coordinates as a double array of length 2, {longitude, latitude}, in degrees- Returns:
- the corresponding spherical coordinates in radians: {longitude, colatitude}
-
spherical2Geo
public static double[] spherical2Geo(double[] spherical) Converts spherical coordinates to geographic coordinates on a sphere of radius 1.- Parameters:
spherical- - spherical coordinates in radians as a double array of length 2: {longitude, colatitude}- Returns:
- the corresponding geographic coordinates in degrees: {longitude, latitude}
-
spherical2Cartesian
public static double[] spherical2Cartesian(double[] spherical) Converts spherical coordinates to Cartesian coordinates on a sphere of radius 1.- Parameters:
spherical- - spherical coordinates in radians as a double array of length 2: {longitude, colatitude}- Returns:
- the corresponding Cartesian coordinates: {x, y, z}
-
cartesian2Spherical
public static double[] cartesian2Spherical(double[] cartesian) Converts Cartesian coordinates to spherical coordinates on a sphere of radius 1.- Parameters:
cartesian- - Cartesian coordinates as double array of length 3: {x, y, z}- Returns:
- the spherical coordinates of the corresponding normalized vector
-
produceZYZRotationMatrix
public static double[][] produceZYZRotationMatrix(double a, double b, double c) TODO produceZYZRotationMatrix javadoc- Parameters:
a-b-c-- Returns:
-
matVecProdD
public static double[] matVecProdD(double[][] matrix, double[] vector) Multiples the given matrix with the given vector. The matrix is assumed to be square and the vector is assumed to be of the same dimension as the matrix.- Parameters:
matrix- - the matrix as a n*n double arrayvector- - the vector as double array of length n- Returns:
- the result of the multiplication as an array of double on length n
-
toRadians
public static void toRadians(double[] arr) Converts all values in a double array from degrees to radians- Parameters:
arr- - array to work on
-
toDegrees
public static void toDegrees(double[] arr) Converts all values in a double array from radians to degrees- Parameters:
arr- - array to work on
-
safeDirectionalShift
public static int safeDirectionalShift(int val, int shift) Right-shifts the given value by the given number of bits, safely handling negative shifts and checking for overflow.- Parameters:
val- the valueshift- the number of bits to shift by- Returns:
- the shifted value
-
clamp
public static double clamp(double num, double min, double max) -
lerp
public static double lerp(double a, double min, double max)
-