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 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 ?
-
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:
hashCode
in classjava.lang.Object
- Returns:
- the hash code
-
toString
public java.lang.String toString()String representation [ = "..." ].- Overrides:
toString
in classjava.lang.Object
- Returns:
- the string
-
equals
public boolean equals(java.lang.Object M)Compares with another matrix [ M = M ? ].- Overrides:
equals
in 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
-