Package hoverball.math
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
-
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 Matrixadd(Matrix B)Adds a matrix [ M = M + B ].static Matrixadd(Matrix A, Matrix B)Sums two matrices [ = A + B ].Matrixconj(Matrix B)Conjugates by a matrix [ M = B^ M B ].static Matrixconj(Matrix A, Matrix B)Conjugates a matrix by a matrix [ = B^ A B ].doubledet()Returns the determinant [ = det M ].booleanequals(java.lang.Object M)Compares with another matrix [ M = M ?inthashCode()Returns the hash code [ =####].Matrixinv()Finds the inverse of the matrix [ M = M^ ].static Matrixinv(Matrix M)Creates the inverse matrix [ = M^ ].Matrixmul(double r)Multiplies by a real number.Matrixmul(Matrix B)Equal to the method mulR(Matrix).static Matrixmul(Matrix M, double r)Multiplies a matrix by a real number [ = M r ].static Matrixmul(Matrix A, Matrix B)Multiplies two matrices [ = A B ].MatrixmulL(Matrix A)Pre-multiplies by a matrix [ M = A M ].MatrixmulR(Matrix B)Post-multiplies by a matrix [ M = M B ].Matrixneg()Negates the matrix [ M = -M ].static Matrixneg(Matrix M)Creates the negated matrix [ = -M ].static Matrixrot(Vector v, double alpha)Creates a turn matrix around an arbitrary axis [ = D (v,a) ].static MatrixrotX(double alpha)Creates a turn matrix around the x-axis [ = D (x,a) ].static MatrixrotY(double alpha)Creates a turn matrix around the y-axis [ = D (y,a) ].static MatrixrotZ(double alpha)Creates a turn matrix around the z-axis [ = D (z,a) ].Matrixsub(Matrix B)Substracts a matrix [ M = M - B ].static Matrixsub(Matrix A, Matrix B)Substracts two matrices [ = A - B ].java.lang.StringtoString()String representation [ = "..." ].Matrixtrans()Transposes the matrix [ M = M ].static Matrixtrans(Matrix M)Creates the transposed matrix [ = M ].booleanzero()Tests if zero [ M = 0 ?
-
Field Details
-
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 vectoray- y-coordinate of the first column vectoraz- z-coordinate of the first column vectorbx- x-coordinate of the second column vectorby- y-coordinate of the second column vectorbz- z-coordinate of the second column vectorcx- x-coordinate of the third column vectorcy- y-coordinate of the third column vectorcz- z-coordinate of the third column vector
-
Matrix
Creates a matrix with the column vectors (a,b,c).- Parameters:
a- first column vectorb- second column vectorc- third column vector
-
Matrix
Creates a matrix equal to another.- Parameters:
M- copied matrix
-
-
Method Details
-
hashCode
public int hashCode()Returns the hash code [ =####].- Overrides:
hashCodein classjava.lang.Object- Returns:
- the hash code
-
toString
public java.lang.String toString()String representation [ = "..." ].- Overrides:
toStringin classjava.lang.Object- Returns:
- the string
-
equals
public boolean equals(java.lang.Object M)Compares with another matrix [ M = M ? ].- Overrides:
equalsin classjava.lang.Object- Parameters:
M- matrix- Returns:
- the equality
-
add
Adds a matrix [ M = M + B ].- Parameters:
B- matrix- Returns:
- this
-
sub
Substracts a matrix [ M = M - B ].- Parameters:
B- matrix- Returns:
- this
-
mul
Multiplies by a real number. [ M = M r ].- Parameters:
r- real number- Returns:
- this
-
mulL
Pre-multiplies by a matrix [ M = A M ].- Parameters:
A- matrix- Returns:
- this
-
mulR
Post-multiplies by a matrix [ M = M B ].- Parameters:
B- matrix- Returns:
- this
-
mul
Equal to the method mulR(Matrix).- Parameters:
B- matrix- Returns:
- this
-
conj
Conjugates by a matrix [ M = B^ M B ].- Parameters:
B- matrix- Returns:
- this
-
inv
Finds the inverse of the matrix [ M = M^ ].- Returns:
- this
-
neg
Negates the matrix [ M = -M ].- Returns:
- this
-
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
Sums two matrices [ = A + B ].- Parameters:
A- matrixB- matrix- Returns:
- the sum
-
sub
Substracts two matrices [ = A - B ].- Parameters:
A- matrixB- matrix- Returns:
- the difference
-
neg
Creates the negated matrix [ = -M ].- Parameters:
M- matrix- Returns:
- the negated matrix
-
inv
Creates the inverse matrix [ = M^ ].- Parameters:
M- matrix- Returns:
- the inverse matrix
-
trans
Creates the transposed matrix [ = M ].- Parameters:
M- matrix- Returns:
- the transposed matrix
-
mul
Multiplies a matrix by a real number [ = M r ].- Parameters:
M- matrixr- real number- Returns:
- the product
-
mul
Multiplies two matrices [ = A B ].- Parameters:
A- matrixB- matrix- Returns:
- the product
-
conj
Conjugates a matrix by a matrix [ = B^ A B ].- Parameters:
A- matrixB- matrix- Returns:
- the conjugate matrix
-
rotX
Creates a turn matrix around the x-axis [ = D (x,a) ].- Parameters:
alpha- angle- Returns:
- the turn matrix
-
rotY
Creates a turn matrix around the y-axis [ = D (y,a) ].- Parameters:
alpha- angle- Returns:
- the turn matrix
-
rotZ
Creates a turn matrix around the z-axis [ = D (z,a) ].- Parameters:
alpha- angle- Returns:
- the turn matrix
-
rot
Creates a turn matrix around an arbitrary axis [ = D (v,a) ].- Parameters:
v- vector that you turn aroundalpha- angle- Returns:
- the turn matrix
-