com.kuka.math.geometry
Class Matrix

java.lang.Object
  extended by com.kuka.math.geometry.Matrix
All Implemented Interfaces:
Serializable

public final class Matrix
extends Object
implements Serializable

Immutable representation of a 3x3 matrix.

See Also:
Serialized Form

Field Summary
static Matrix IDENTITY
          Immutable Matrix instance representing the identity 3x3 matrix.
static Matrix ZERO
          Immutable Matrix instance representing a zero 3x3 matrix.
 
Method Summary
 Matrix add(Matrix other)
          Adds the given matrix to this one.
 double determinant()
          Calculates the determinant of this matrix.
 boolean equals(Object obj)
          Compares the specified object for equality with this matrix.
 double get(int row, int col)
          Returns the matrix element at the specified position.
 Vector3D getColumnVector(int col)
          Returns the column vector at the specified column.
 double getElement00()
          Returns a specific matrix element.
 double getElement01()
          Returns a specific matrix element.
 double getElement02()
          Returns a specific matrix element.
 double getElement10()
          Returns a specific matrix element.
 double getElement11()
          Returns a specific matrix element.
 double getElement12()
          Returns a specific matrix element.
 double getElement20()
          Returns a specific matrix element.
 double getElement21()
          Returns a specific matrix element.
 double getElement22()
          Returns a specific matrix element.
 int hashCode()
          Returns the hash code for this matrix.
 Matrix invert()
          Returns a matrix which is the inverse of this matrix, if it exists, otherwise throws ArithmeticException.
 Matrix multiply(double value)
          Multiplies this matrix element-wise with a scalar value.
 Matrix multiply(Matrix other)
          Multiplies this matrix with another matrix (Result = this*other).
 Vector3D multiply(Vector3D vector)
          Multiplies this matrix with a vector.
static Matrix ofColumnFirst(double d00, double d10, double d20, double d01, double d11, double d21, double d02, double d12, double d22)
          Returns an immutable Matrix instance from column-first order values.
static Matrix ofColumns(Vector3D col0, Vector3D col1, Vector3D col2)
          Returns an immutable Matrix instance constructed from column vectors.
static Matrix ofRowFirst(double d00, double d01, double d02, double d10, double d11, double d12, double d20, double d21, double d22)
          Returns an immutable Matrix instance from row-first order values.
 Matrix subtract(Matrix other)
          Subtracts the given matrix from this one.
 String toString()
          Returns the matrix value as a 3x3 matrix formatted in a way compatible with popular scientific numerical computing applications.
 String toString(NumberFormat fmt)
          Returns the matrix value as a 3x3 matrix formatted in a way similar to popular scientific numerical computing applications.
 double trace()
          Calculates the trace of this matrix, i.e. the sum of the diagonal elements.
 Matrix transpose()
          Returns a new matrix which consists of the transposed values of this matrix.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ZERO

public static final Matrix ZERO
Immutable Matrix instance representing a zero 3x3 matrix.


IDENTITY

public static final Matrix IDENTITY
Immutable Matrix instance representing the identity 3x3 matrix.

Method Detail

ofColumnFirst

public static Matrix ofColumnFirst(double d00,
                                   double d10,
                                   double d20,
                                   double d01,
                                   double d11,
                                   double d21,
                                   double d02,
                                   double d12,
                                   double d22)
Returns an immutable Matrix instance from column-first order values.

Parameters:
d00 - Value of the matrix in field 0x0
d10 - Value of the matrix in field 1x0
d20 - Value of the matrix in field 2x0
d01 - Value of the matrix in field 0x1
d11 - Value of the matrix in field 1x1
d21 - Value of the matrix in field 2x1
d02 - Value of the matrix in field 0x2
d12 - Value of the matrix in field 1x2
d22 - Value of the matrix in field 2x2
Returns:
an immutable Matrix instance

ofRowFirst

public static Matrix ofRowFirst(double d00,
                                double d01,
                                double d02,
                                double d10,
                                double d11,
                                double d12,
                                double d20,
                                double d21,
                                double d22)
Returns an immutable Matrix instance from row-first order values.

Parameters:
d00 - Value of the matrix in field 0x0
d01 - Value of the matrix in field 0x1
d02 - Value of the matrix in field 0x2
d10 - Value of the matrix in field 1x0
d11 - Value of the matrix in field 1x1
d12 - Value of the matrix in field 1x2
d20 - Value of the matrix in field 2x0
d21 - Value of the matrix in field 2x1
d22 - Value of the matrix in field 2x2
Returns:
an immutable Matrix instance

ofColumns

public static Matrix ofColumns(Vector3D col0,
                               Vector3D col1,
                               Vector3D col2)
Returns an immutable Matrix instance constructed from column vectors.

Parameters:
col0 - The vector in the first column (index 0)
col1 - The vector in the second column (index 1)
col2 - The vector in the third column (index 2)
Returns:
an immutable Matrix instance

getElement00

public double getElement00()
Returns a specific matrix element.

Returns:
the matrix element at row 0, column 0

getElement01

public double getElement01()
Returns a specific matrix element.

Returns:
the matrix element at row 0, column 1

getElement02

public double getElement02()
Returns a specific matrix element.

Returns:
the matrix element at row 0, column 2

getElement10

public double getElement10()
Returns a specific matrix element.

Returns:
the matrix element at row 1, column 0

getElement11

public double getElement11()
Returns a specific matrix element.

Returns:
the matrix element at row 1, column 1

getElement12

public double getElement12()
Returns a specific matrix element.

Returns:
the matrix element at row 1, column 2

getElement20

public double getElement20()
Returns a specific matrix element.

Returns:
the matrix element at row 2, column 0

getElement21

public double getElement21()
Returns a specific matrix element.

Returns:
the matrix element at row 2, column 1

getElement22

public double getElement22()
Returns a specific matrix element.

Returns:
the matrix element at row 2, column 2

get

public double get(int row,
                  int col)
Returns the matrix element at the specified position.

Parameters:
row - The row of the position. Must be between 0 and 2.
col - The column of the position. Must be between 0 and 2.
Returns:
the matrix element at the specified position.
Throws:
IndexOutOfBoundsException - illegal index

getColumnVector

public Vector3D getColumnVector(int col)
Returns the column vector at the specified column.

Parameters:
col - The index of the column. Must be between 0 and 2.
Returns:
The specified column vector.
Throws:
IndexOutOfBoundsException - illegal index

transpose

public Matrix transpose()
Returns a new matrix which consists of the transposed values of this matrix.

Returns:
the transposed matrix.

invert

public Matrix invert()
Returns a matrix which is the inverse of this matrix, if it exists, otherwise throws ArithmeticException. The matrix is invertible if its determinant is non-zero.

Returns:
the inverse matrix.
Throws:
ArithmeticException - if the matrix is not invertible
See Also:
determinant()

determinant

public double determinant()
Calculates the determinant of this matrix.

Returns:
The determinant of this matrix.

trace

public double trace()
Calculates the trace of this matrix, i.e. the sum of the diagonal elements.

Returns:
The trace of this matrix.

multiply

public Matrix multiply(double value)
Multiplies this matrix element-wise with a scalar value. Returns a matrix instance which contains the result.

Parameters:
value - The scalar value.
Returns:
The resulting matrix.

multiply

public Vector3D multiply(Vector3D vector)
Multiplies this matrix with a vector. Returns a new instance of a vector which contains the result. This function executes the calculation: Result = Matrix*Vector.

Parameters:
vector - The other vector.
Returns:
The resulting translation vector.

multiply

public Matrix multiply(Matrix other)
Multiplies this matrix with another matrix (Result = this*other). Returns a new instance of a matrix which contains the result.

Parameters:
other - The other matrix.
Returns:
The resulting new matrix.

add

public Matrix add(Matrix other)
Adds the given matrix to this one.

Parameters:
other - another matrix
Returns:
a new Matrix instance with the element-wise sum of this and the other matrix.

subtract

public Matrix subtract(Matrix other)
Subtracts the given matrix from this one.

Parameters:
other - another matrix
Returns:
a new Matrix instance with the element-wise subtraction of the other matrix from this one.

toString

public String toString()
Returns the matrix value as a 3x3 matrix formatted in a way compatible with popular scientific numerical computing applications. The matrix values will be printed in row-first order. The numerical values will be printed with the default format as returned by MathUtils.getDefaultNumberFormat().

The following string can be regarded as typical:

[[0.0 0.0 -1.0]; [0.0 -1.0 0.0]; [-1.0 0.0 0.0]]

Overrides:
toString in class Object
Returns:
a textual representation of the matrix as a 3x3 matrix

toString

public String toString(NumberFormat fmt)
Returns the matrix value as a 3x3 matrix formatted in a way similar to popular scientific numerical computing applications. The matrix values will be printed in row-first order. The numerical values will be printed using the NumberFormat.format(double) method of the given formatter.

Example: The following code snippet, used on a given Matrix mat

 NumberFormat fmt = NumberFormat.getNumberInstance(Locale.US);
 fmt.setMinimumFractionDigits(1);
 fmt.setMaximumFractionDigits(3);
 System.out.println(mat.toString(fmt));
might give the following output:
 [[0.707 -0.707 0.0]; [0.707 0.707 0.0]; [0.0 0.0 1.0]]

Parameters:
fmt - the NumberFormat used to format the number values
Returns:
a textual representation of the matrix as a 3x3 matrix

hashCode

public int hashCode()
Returns the hash code for this matrix. The hash code is computed by a combination of all the data elements defined by this interface.

Overrides:
hashCode in class Object
Returns:
hash code for this matrix.

equals

public boolean equals(Object obj)
Compares the specified object for equality with this matrix. Matrices are equal if the publicly visible state (i.e. all queryable elements) is equal.

Overrides:
equals in class Object
Parameters:
obj - Object to be compared with this matrix.
Returns:
true if the object is equal to this matrix.


Copyright © 2019. All rights reserved.