Class Algebra

java.lang.Object
org.rcsb.strucmotif.math.Algebra

public class Algebra extends Object
A collection of algebraic or generic mathematical functions.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    add3d(float[] out, float[] v1, float[] v2)
    Adds 2 3D vectors.
    static float
    capToInterval(float lowerBound, float value, float upperBound)
    Caps a value to a defined interval.
    static int
    capToInterval(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 void
    crossProduct3d(float[] out, float[] v1, float[] v2)
    Computes the cross-produced of 2 3D vectors.
    static float
    distance3d(float[] v1, float[] v2)
    Computes the distance between 2 3D vectors.
    static float
    distanceSquared3d(float[] v1, float[] v2)
    Computes the squared distance between 2 3D vectors.
    static void
    divide3d(float[] out, float[] v, float scalar)
    Divides a 3D vector by a scalar.
    static float
    dotProduct3d(float[] v1, float[] v2)
    Computes the dot-product of 2 3D vectors.
    static void
    multiply3d(float[] out, float[][] m, float[] v)
    Left-multiplies a 3D vector with a 3x3 matrix.
    static void
    multiply3d(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 void
    multiply4d(float[] out, float[][] m, float[] v)
    Left-multiplies a 3D vector with a 4x4 matrix.
    static float
    norm3d(float[] vec3d)
    Computes the norm of a vector.
    static void
    normalize3d(float[] out, float[] v)
    Normalizes a vector (i.e.
    static void
    subtract3d(float[] out, float[] v1, float[] v2)
    Subtracts 2 3D vectors.
    static float[][]
    transpose3d(float[][] rot)
    Transpose a 3x3 matrix.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 accept
      value - the value to process
      upperBound - 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 accept
      value - the value to process
      upperBound - 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 output
      v1 - first vector
      v2 - second vector
    • centroid3d

      public static float[] centroid3d(Collection<float[]> vs)
      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 output
      v1 - first vector
      v2 - 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 output
      m - the 3x3 matrix
      v - the vector
    • multiply3d

      public static void multiply3d(float[] out, float[] v, float scalar)
      Multiplies a 3D vector with a scalar.
      Parameters:
      out - the output
      v - the vector
      scalar - the scalar
    • divide3d

      public static void divide3d(float[] out, float[] v, float scalar)
      Divides a 3D vector by a scalar.
      Parameters:
      out - the output
      v - the vector
      scalar - the scalar
    • crossProduct3d

      public static void crossProduct3d(float[] out, float[] v1, float[] v2)
      Computes the cross-produced of 2 3D vectors.
      Parameters:
      out - the output
      v1 - first vector
      v2 - second vector
    • dotProduct3d

      public static float dotProduct3d(float[] v1, float[] v2)
      Computes the dot-product of 2 3D vectors.
      Parameters:
      v1 - first vector
      v2 - 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 vector
      v2 - 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 vector
      v2 - 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 output
      v - 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 output
      m - the 4x4 matrix
      v - the vector
    • multiply4d

      public static float[][] multiply4d(float[][] matrix4d1, float[][] matrix4d2)
      Multiplies 2 4x4 matrices. Does not manipulate original matrices.
      Parameters:
      matrix4d1 - first matrix
      matrix4d2 - 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 matrix
      translation3d - a 3-element translation vector
      Returns:
      a transformation matrix