Package org.rcsb.strucmotif.math
Class Algebra
java.lang.Object
org.rcsb.strucmotif.math.Algebra
A collection of algebraic or generic mathematical functions.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidadd3d(float[] out, float[] v1, float[] v2) Adds 2 3D vectors.static floatcapToInterval(float lowerBound, float value, float upperBound) Caps a value to a defined interval.static intcapToInterval(int lowerBound, int value, int upperBound) Caps a value to a defined interval.static float[]centroid3d(Collection<float[]> vs) Computes the centroid of a collection of 3D vectors.static float[][]composeTransformationMatrix(float[][] rotation3x3, float[] translation3d) Combine a rotation matrix and a translation vector into a 4x4 transformation matrix.static voidcrossProduct3d(float[] out, float[] v1, float[] v2) Computes the cross-produced of 2 3D vectors.static floatdistance3d(float[] v1, float[] v2) Computes the distance between 2 3D vectors.static floatdistanceSquared3d(float[] v1, float[] v2) Computes the squared distance between 2 3D vectors.static voiddivide3d(float[] out, float[] v, float scalar) Divides a 3D vector by a scalar.static floatdotProduct3d(float[] v1, float[] v2) Computes the dot-product of 2 3D vectors.static voidmultiply3d(float[] out, float[][] m, float[] v) Left-multiplies a 3D vector with a 3x3 matrix.static voidmultiply3d(float[] out, float[] v, float scalar) Multiplies a 3D vector with a scalar.static float[][]multiply4d(float[][] matrix4d1, float[][] matrix4d2) Multiplies 2 4x4 matrices.static voidmultiply4d(float[] out, float[][] m, float[] v) Left-multiplies a 3D vector with a 4x4 matrix.static floatnorm3d(float[] vec3d) Computes the norm of a vector.static voidnormalize3d(float[] out, float[] v) Normalizes a vector (i.e.static voidsubtract3d(float[] out, float[] v1, float[] v2) Subtracts 2 3D vectors.static float[][]transpose3d(float[][] rot) Transpose a 3x3 matrix.
-
Method Details
-
capToInterval
public static int capToInterval(int lowerBound, int value, int upperBound) Caps a value to a defined interval. Returns lower respectively upper bound for values out of range and otherwise the original value.- Parameters:
lowerBound- the minimum value to acceptvalue- the value to processupperBound- the maximum value to accept- Returns:
- an int in this interval
-
capToInterval
public static float capToInterval(float lowerBound, float value, float upperBound) Caps a value to a defined interval. Returns lower respectively upper bound for values out of range and otherwise the original value.- Parameters:
lowerBound- the minimum value to acceptvalue- the value to processupperBound- the maximum value to accept- Returns:
- a float in this interval
-
add3d
public static void add3d(float[] out, float[] v1, float[] v2) Adds 2 3D vectors.- Parameters:
out- the outputv1- first vectorv2- second vector
-
centroid3d
Computes the centroid of a collection of 3D vectors.- Parameters:
vs- collection of 3D vectors- Returns:
- the 3D vector describing the centroid
-
subtract3d
public static void subtract3d(float[] out, float[] v1, float[] v2) Subtracts 2 3D vectors.- Parameters:
out- the outputv1- first vectorv2- second vector
-
multiply3d
public static void multiply3d(float[] out, float[][] m, float[] v) Left-multiplies a 3D vector with a 3x3 matrix.- Parameters:
out- the outputm- the 3x3 matrixv- the vector
-
multiply3d
public static void multiply3d(float[] out, float[] v, float scalar) Multiplies a 3D vector with a scalar.- Parameters:
out- the outputv- the vectorscalar- the scalar
-
divide3d
public static void divide3d(float[] out, float[] v, float scalar) Divides a 3D vector by a scalar.- Parameters:
out- the outputv- the vectorscalar- the scalar
-
crossProduct3d
public static void crossProduct3d(float[] out, float[] v1, float[] v2) Computes the cross-produced of 2 3D vectors.- Parameters:
out- the outputv1- first vectorv2- second vector
-
dotProduct3d
public static float dotProduct3d(float[] v1, float[] v2) Computes the dot-product of 2 3D vectors.- Parameters:
v1- first vectorv2- second vector- Returns:
- the dot-product of both vectors
-
distanceSquared3d
public static float distanceSquared3d(float[] v1, float[] v2) Computes the squared distance between 2 3D vectors. Faster when root is not needed (comparing values et al.).- Parameters:
v1- first vectorv2- second vector- Returns:
- the squared distance between both vectors
-
distance3d
public static float distance3d(float[] v1, float[] v2) Computes the distance between 2 3D vectors.- Parameters:
v1- first vectorv2- second vector- Returns:
- the distance between both vectors
-
norm3d
public static float norm3d(float[] vec3d) Computes the norm of a vector.- Parameters:
vec3d- the vector- Returns:
- the norm of the vector
-
normalize3d
public static void normalize3d(float[] out, float[] v) Normalizes a vector (i.e. divide by its norm).- Parameters:
out- the outputv- the vector
-
multiply4d
public static void multiply4d(float[] out, float[][] m, float[] v) Left-multiplies a 3D vector with a 4x4 matrix.- Parameters:
out- the outputm- the 4x4 matrixv- the vector
-
multiply4d
public static float[][] multiply4d(float[][] matrix4d1, float[][] matrix4d2) Multiplies 2 4x4 matrices. Does not manipulate original matrices.- Parameters:
matrix4d1- first matrixmatrix4d2- second matrix- Returns:
- the resulting 4x4 matrix
-
transpose3d
public static float[][] transpose3d(float[][] rot) Transpose a 3x3 matrix.- Parameters:
rot- the original matrix- Returns:
- a new, transposed matrix
-
composeTransformationMatrix
public static float[][] composeTransformationMatrix(float[][] rotation3x3, float[] translation3d) Combine a rotation matrix and a translation vector into a 4x4 transformation matrix.- Parameters:
rotation3x3- a 3x3 rotation matrixtranslation3d- a 3-element translation vector- Returns:
- a transformation matrix
-