Class MatrixMath

java.lang.Object
ffx.numerics.math.MatrixMath

public final class MatrixMath extends Object
The MatrixMath class is a simple matrix math library used mainly by the X-ray package.

All methods are thread-safe and static.

Since:
1.0
Author:
Michael J. Schnieders
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    mat3Determinant(double[] m)
    Returns the determinant of a symmetric 3x3 matrix stored in vector form as 11, 22, 33, 12, 13, 23.
    static double
    mat3Determinant(double[][] m)
    Calculated the determinant for a 3x3 matrix.
    static double[][]
    mat3Inverse(double[][] m)
    Compute the inverse of 3x3 matrix.
    static double[][]
    mat3Inverse(double[][] m, double[][] output)
    Compute the inverse of 3x3 matrix.
    static double[][]
    mat3Mat3Multiply(double[][] m, double[][] n)
    Multiple a 3x3 matrix m and a 3x3 matrix n.
    static double[][]
    mat3Mat3Multiply(double[][] m, double[][] n, double[][] result)
    Multiple a 3x3 matrix m and a 3x3 matrix n.
    static double[][]
    mat3SymVec6(double[][] m, double[] v)
    Matrix times a vector representation of a symmetric 3x3 matrix
    static double[][]
    mat3SymVec6(double[][] m, double[] v, double[][] output)
    Matrix times a vector representation of a symmetric 3x3 matrix.
    static double[][]
    mat3Transpose(double[][] m)
    Returns the transpose of a 3x3 Matrix m in newly allocated memory.
    static double[][]
    mat3Transpose(double[][] m, double[][] output)
    Transpose a 3x3 Matrix m and store the result in output.
    static double[][]
    mat4Mat4(double[][] m1, double[][] m2)
    Matrix times a matrix (both 4x4).
    static double[][]
    mat4Mat4(double[][] m1, double[][] m2, double[][] res)
    Multiply two 4x4 matrices.
    static double[]
    vec3Mat3(double[] v, double[][] m)
    Multiply a 1x3 vector and 3x3 matrix.
    static double[]
    vec3Mat3(double[] v, double[][] m, double[] output)
    Multiply a 1x3 vector and 3x3 matrix.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • mat3Determinant

      public static double mat3Determinant(double[][] m)
      Calculated the determinant for a 3x3 matrix.
      Parameters:
      m - input matrix.
      Returns:
      The determinant.
    • mat3Determinant

      public static double mat3Determinant(double[] m)
      Returns the determinant of a symmetric 3x3 matrix stored in vector form as 11, 22, 33, 12, 13, 23.
      Parameters:
      m - symmetric input matrix in vector format.
      Returns:
      The determinant.
    • mat3Inverse

      public static double[][] mat3Inverse(double[][] m)
      Compute the inverse of 3x3 matrix. The result is returned in a newly allocated matrix.
      Parameters:
      m - The input 3x3 matrix.
      Returns:
      Returns the inverse of the input matrix m.
    • mat3Inverse

      public static double[][] mat3Inverse(double[][] m, double[][] output)
      Compute the inverse of 3x3 matrix. If the input matrix m can be specified for the output matrix to store the result in place.
      Parameters:
      m - The input 3x3 matrix.
      output - The output 3x3 matrix.
      Returns:
      Returns the inverse of the input matrix m.
    • mat3Mat3Multiply

      public static double[][] mat3Mat3Multiply(double[][] m, double[][] n)
      Multiple a 3x3 matrix m and a 3x3 matrix n. The output is returned in a newly allocated 3x3 matrix.
      Parameters:
      m - an input 3x3 matrix.
      n - an input 3x3 matrix
      Returns:
      Returns the 3x3 matrix result.
    • mat3Mat3Multiply

      public static double[][] mat3Mat3Multiply(double[][] m, double[][] n, double[][] result)
      Multiple a 3x3 matrix m and a 3x3 matrix n. The output is stored in result. The matrix m or n can be used for the result matrix.
      Parameters:
      m - an input 3x3 matrix.
      n - an input 3x3 matrix
      result - a 3x3 matrix to store the result.
      Returns:
      Returns the matrix result.
    • mat4Mat4

      public static double[][] mat4Mat4(double[][] m1, double[][] m2)
      Matrix times a matrix (both 4x4).
      Parameters:
      m1 - First input matrix.
      m2 - Second input matrix.
      Returns:
      Returns the matrix product.
    • mat4Mat4

      public static double[][] mat4Mat4(double[][] m1, double[][] m2, double[][] res)
      Multiply two 4x4 matrices.
      Parameters:
      m1 - an array of double (first matrix).
      m2 - an array of double (second matrix).
      res - Resultant matrix.
      Returns:
      Returns the matrix res.
    • mat3SymVec6

      public static double[][] mat3SymVec6(double[][] m, double[] v)
      Matrix times a vector representation of a symmetric 3x3 matrix
      Parameters:
      m - input 3x3 matrix.
      v - input vector of the form 11, 22, 33, 12, 13, 23
      Returns:
      matrix product in newly allocated space.
    • mat3SymVec6

      public static double[][] mat3SymVec6(double[][] m, double[] v, double[][] output)
      Matrix times a vector representation of a symmetric 3x3 matrix. The input matrix m can also be used for the output, which overwrites m with the output.
      Parameters:
      m - input 3x3 matrix.
      v - input vector of the form 11, 22, 33, 12, 13, 23
      output - output 3x3 matrix.
      Returns:
      matrix product in newly allocated space.
    • mat3Transpose

      public static double[][] mat3Transpose(double[][] m)
      Returns the transpose of a 3x3 Matrix m in newly allocated memory.
      Parameters:
      m - The input matrix.
      Returns:
      An allocated a 3x3 matrix with transpose of m.
    • mat3Transpose

      public static double[][] mat3Transpose(double[][] m, double[][] output)
      Transpose a 3x3 Matrix m and store the result in output. The input matrix m and output matrix output can be the same variable to store the transpose in-place.
      Parameters:
      m - The input matrix.
      output - The output transposed matrix.
      Returns:
      Returns the transposed matrix output.
    • vec3Mat3

      public static double[] vec3Mat3(double[] v, double[][] m)
      Multiply a 1x3 vector and 3x3 matrix. The output is returned in a newly allocated 1x3 vector.
      Parameters:
      v - input 1x3 vector.
      m - input 3x3 matrix.
      Returns:
      Returns the output vector.
    • vec3Mat3

      public static double[] vec3Mat3(double[] v, double[][] m, double[] output)
      Multiply a 1x3 vector and 3x3 matrix. If the vector v is also used for the output, the output result will overwrite the input values of v.
      Parameters:
      v - input 1x3 vector.
      m - input 3x3 matrix.
      output - output 1x3 vector.
      Returns:
      Returns the output vector.