Class Matrix

java.lang.Object
hoverball.math.Matrix

public final class Matrix
extends java.lang.Object
The class Matrix represents a real 3 x 3-Matrix.

Let be:
    A, B, M  -  matrices
    a, b, c  -  vectors (as column vectors)
    x, y, z  -  real numbers (as coordinates)
    v  -  vector
    r  -  real number
    a ("alpha")  -  real number (as angle)
    x, y, z  -  the unit vectors
    M  -  the matrix of the Matrix object itself

Note: Unlike the standard notation of mathematics, matrix operations are read from left to right. Thus, in Hoverball we write v A B for a vector v which is multiplied by the matrix A and afterwards by the matrix B (instead of B A v).

Operator Overloading for Groovy, Scala, Kotlin and Jython is supported.

  • Field Summary

    Fields 
    Modifier and Type Field Description
    Vector a
    First column vector of the matrix.
    Vector b
    Second column vector of the matrix.
    Vector c
    Third column vector of the matrix.
  • Constructor Summary

    Constructors 
    Constructor Description
    Matrix()
    Creates a unit matrix.
    Matrix​(double r)
    Creates a multiple of the unit matrix.
    Matrix​(double ax, double ay, double az, double bx, double by, double bz, double cx, double cy, double cz)
    Creates a matrix with the coordinates ((ax,ay,az), (bx,by,bz), (cx,cy,cz)).
    Matrix​(Matrix M)
    Creates a matrix equal to another.
    Matrix​(Vector a, Vector b, Vector c)
    Creates a matrix with the column vectors (a,b,c).
  • Method Summary

    Modifier and Type Method Description
    Matrix add​(Matrix B)
    Adds a matrix  [ M = M + B ].
    static Matrix add​(Matrix A, Matrix B)
    Sums two matrices  [ = A + B ].
    Matrix conj​(Matrix B)
    Conjugates by a matrix  [ M = B^ M B ].
    static Matrix conj​(Matrix A, Matrix B)
    Conjugates a matrix by a matrix  [ = B^ A B ].
    double det()
    Returns the determinant  [ = det M ].
    boolean equals​(java.lang.Object M)
    Compares with another matrix  [ M = M ?
    int hashCode()
    Returns the hash code  [ = #### ].
    Matrix inv()
    Finds the inverse of the matrix  [ M = M^ ].
    static Matrix inv​(Matrix M)
    Creates the inverse matrix  [ = M^ ].
    Matrix mul​(double r)
    Multiplies by a real number.
    Matrix mul​(Matrix B)
    Equal to the method mulR(Matrix).
    static Matrix mul​(Matrix M, double r)
    Multiplies a matrix by a real number  [ = M r ].
    static Matrix mul​(Matrix A, Matrix B)
    Multiplies two matrices  [ = A B ].
    Matrix mulL​(Matrix A)
    Pre-multiplies by a matrix  [ M = A M ].
    Matrix mulR​(Matrix B)
    Post-multiplies by a matrix  [ M = M B ].
    Matrix neg()
    Negates the matrix  [ M = -M ].
    static Matrix neg​(Matrix M)
    Creates the negated matrix  [ = -M ].
    static Matrix rot​(Vector v, double alpha)
    Creates a turn matrix around an arbitrary axis  [ = D (v,a) ].
    static Matrix rotX​(double alpha)
    Creates a turn matrix around the x-axis  [ = D (x,a) ].
    static Matrix rotY​(double alpha)
    Creates a turn matrix around the y-axis  [ = D (y,a) ].
    static Matrix rotZ​(double alpha)
    Creates a turn matrix around the z-axis  [ = D (z,a) ].
    Matrix sub​(Matrix B)
    Substracts a matrix  [ M = M - B ].
    static Matrix sub​(Matrix A, Matrix B)
    Substracts two matrices  [ = A - B ].
    java.lang.String toString()
    String representation  [ = "..." ].
    Matrix trans()
    Transposes the matrix  [ M = M ].
    static Matrix trans​(Matrix M)
    Creates the transposed matrix  [ = M ].
    boolean zero()
    Tests if zero  [ M = 0 ?

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • a

      public final Vector a
      First column vector of the matrix.
    • b

      public final Vector b
      Second column vector of the matrix.
    • c

      public final Vector c
      Third column vector of the matrix.
  • Constructor Details

    • Matrix

      public Matrix()
      Creates a unit matrix.
    • Matrix

      public Matrix​(double r)
      Creates a multiple of the unit matrix.
      Parameters:
      r - factor
    • Matrix

      public Matrix​(double ax, double ay, double az, double bx, double by, double bz, double cx, double cy, double cz)
      Creates a matrix with the coordinates ((ax,ay,az), (bx,by,bz), (cx,cy,cz)).
      Parameters:
      ax - x-coordinate of the first column vector
      ay - y-coordinate of the first column vector
      az - z-coordinate of the first column vector
      bx - x-coordinate of the second column vector
      by - y-coordinate of the second column vector
      bz - z-coordinate of the second column vector
      cx - x-coordinate of the third column vector
      cy - y-coordinate of the third column vector
      cz - z-coordinate of the third column vector
    • Matrix

      public Matrix​(Vector a, Vector b, Vector c)
      Creates a matrix with the column vectors (a,b,c).
      Parameters:
      a - first column vector
      b - second column vector
      c - third column vector
    • Matrix

      public Matrix​(Matrix M)
      Creates a matrix equal to another.
      Parameters:
      M - copied matrix
  • Method Details

    • hashCode

      public int hashCode()
      Returns the hash code  [ = #### ].
      Overrides:
      hashCode in class java.lang.Object
      Returns:
      the hash code
    • toString

      public java.lang.String toString()
      String representation  [ = "..." ].
      Overrides:
      toString in class java.lang.Object
      Returns:
      the string
    • equals

      public boolean equals​(java.lang.Object M)
      Compares with another matrix  [ M = M ? ].
      Overrides:
      equals in class java.lang.Object
      Parameters:
      M - matrix
      Returns:
      the equality
    • add

      public final Matrix add​(Matrix B)
      Adds a matrix  [ M = M + B ].
      Parameters:
      B - matrix
      Returns:
      this
    • sub

      public final Matrix sub​(Matrix B)
      Substracts a matrix  [ M = M - B ].
      Parameters:
      B - matrix
      Returns:
      this
    • mul

      public final Matrix mul​(double r)
      Multiplies by a real number.  [ M = M r ].
      Parameters:
      r - real number
      Returns:
      this
    • mulL

      public final Matrix mulL​(Matrix A)
      Pre-multiplies by a matrix  [ M = A M ].
      Parameters:
      A - matrix
      Returns:
      this
    • mulR

      public final Matrix mulR​(Matrix B)
      Post-multiplies by a matrix  [ M = M B ].
      Parameters:
      B - matrix
      Returns:
      this
    • mul

      public final Matrix mul​(Matrix B)
      Equal to the method mulR(Matrix).
      Parameters:
      B - matrix
      Returns:
      this
    • conj

      public final Matrix conj​(Matrix B)
      Conjugates by a matrix  [ M = B^ M B ].
      Parameters:
      B - matrix
      Returns:
      this
    • inv

      public final Matrix inv()
      Finds the inverse of the matrix  [ M = M^ ].
      Returns:
      this
    • neg

      public final Matrix neg()
      Negates the matrix  [ M = -M ].
      Returns:
      this
    • trans

      public final Matrix trans()
      Transposes the matrix  [ M = M ].
      Returns:
      this
    • zero

      public final boolean zero()
      Tests if zero  [ M = 0 ? ].
      Returns:
      true, if this matrix is (0)
    • det

      public final double det()
      Returns the determinant  [ = det M ].
      Returns:
      the determinant
    • add

      public static final Matrix add​(Matrix A, Matrix B)
      Sums two matrices  [ = A + B ].
      Parameters:
      A - matrix
      B - matrix
      Returns:
      the sum
    • sub

      public static final Matrix sub​(Matrix A, Matrix B)
      Substracts two matrices  [ = A - B ].
      Parameters:
      A - matrix
      B - matrix
      Returns:
      the difference
    • neg

      public static final Matrix neg​(Matrix M)
      Creates the negated matrix  [ = -M ].
      Parameters:
      M - matrix
      Returns:
      the negated matrix
    • inv

      public static final Matrix inv​(Matrix M)
      Creates the inverse matrix  [ = M^ ].
      Parameters:
      M - matrix
      Returns:
      the inverse matrix
    • trans

      public static final Matrix trans​(Matrix M)
      Creates the transposed matrix  [ = M ].
      Parameters:
      M - matrix
      Returns:
      the transposed matrix
    • mul

      public static final Matrix mul​(Matrix M, double r)
      Multiplies a matrix by a real number  [ = M r ].
      Parameters:
      M - matrix
      r - real number
      Returns:
      the product
    • mul

      public static final Matrix mul​(Matrix A, Matrix B)
      Multiplies two matrices  [ = A B ].
      Parameters:
      A - matrix
      B - matrix
      Returns:
      the product
    • conj

      public static final Matrix conj​(Matrix A, Matrix B)
      Conjugates a matrix by a matrix  [ = B^ A B ].
      Parameters:
      A - matrix
      B - matrix
      Returns:
      the conjugate matrix
    • rotX

      public static final Matrix rotX​(double alpha)
      Creates a turn matrix around the x-axis  [ = D (x,a) ].
      Parameters:
      alpha - angle
      Returns:
      the turn matrix
    • rotY

      public static final Matrix rotY​(double alpha)
      Creates a turn matrix around the y-axis  [ = D (y,a) ].
      Parameters:
      alpha - angle
      Returns:
      the turn matrix
    • rotZ

      public static final Matrix rotZ​(double alpha)
      Creates a turn matrix around the z-axis  [ = D (z,a) ].
      Parameters:
      alpha - angle
      Returns:
      the turn matrix
    • rot

      public static final Matrix rot​(Vector v, double alpha)
      Creates a turn matrix around an arbitrary axis  [ = D (v,a) ].
      Parameters:
      v - vector that you turn around
      alpha - angle
      Returns:
      the turn matrix