maspack.matrix
Class Matrix4dObject

java.lang.Object
  extended bymaspack.matrix.MatrixObject
      extended bymaspack.matrix.Matrix4dObject
Direct Known Subclasses:
Matrix4d

public abstract class Matrix4dObject
extends MatrixObject

Base class for 4 x 4 matrices in which the elements are stored as explicit fields. A primary motivation for such objects is computational speed.


Field Summary
 double m00
          Matrix element (0,0)
 double m01
          Matrix element (0,1)
 double m02
          Matrix element (0,2)
 double m03
          Matrix element (0,3)
 double m10
          Matrix element (1,0)
 double m11
          Matrix element (1,1)
 double m12
          Matrix element (1,2)
 double m13
          Matrix element (1,3)
 double m20
          Matrix element (2,0)
 double m21
          Matrix element (2,1)
 double m22
          Matrix element (2,2)
 double m23
          Matrix element (2,3)
 double m30
          Matrix element (3,0)
 double m31
          Matrix element (3,1)
 double m32
          Matrix element (3,2)
 double m33
          Matrix element (3,3)
 
Constructor Summary
Matrix4dObject()
           
 
Method Summary
 int colSize()
          Returns the number of columns in this matrix (which is always 4).
 double determinant()
          Returns the determinant of this matrix
 boolean epsilonEquals(Matrix4dObject M1, double epsilon)
          Returns true if the elements of this matrix equal those of matrix M1within a prescribed tolerance epsilon.
 boolean equals(Matrix4dObject M1)
          Returns true if the elements of this matrix exactly equal those of matrix M1.
 double frobeniusNorm()
          Returns the Frobenius norm of this matrix.
 void get(double[] values)
          Copies the elements of this matrix into an array of doubles. The elements are stored using row-major order, so that element (i,j) is stored at location i*colSize()+j.
 double get(int i, int j)
          Gets a single element of this matrix.
 void getColumn(int j, double[] values)
          Copies a column of this matrix into an array of doubles.
 void getColumn(int j, Vector4d col)
          Copies a column of this matrix into a 4-vector.
 void getRow(int i, double[] values)
          Copies a row of this matrix into an array of doubles.
 void getRow(int i, Vector4d row)
          Copies a row of this matrix into a 4-vector.
 double infinityNorm()
          Returns the infinity norm of this matrix.
 boolean invert()
          Inverts this matrix in place, returning false if the matrix is detected to be singular.
 void mul(Vector4d vr)
          Multiplies this matrix by the column vector vr and places the result back into vr.
 void mul(Vector4d vr, Vector4d v1)
          Multiplies this matrix by the column vector v1 and places the result in the vector vr.
 boolean mulInverse(Vector4d vr)
          Multiplies the column vector vr by the inverse of this matrix and places the result back in vr.
 boolean mulInverse(Vector4d vr, Vector4d v1)
          Multiplies the column vector v1 by the inverse of this matrix and places the result in vr.
 boolean mulInverseTranspose(Vector4d vr)
          Multiplies the column vector vr by the inverse transpose of this matrix and places the result back in vr.
 boolean mulInverseTranspose(Vector4d vr, Vector4d v1)
          Multiplies the column vector v1 by the inverse transpose of this matrix and places the result in vr.
 void mulTranspose(Vector4d vr)
          Multiplies the transpose of this matrix by the vector vr and places the result back in vr.
 void mulTranspose(Vector4d vr, Vector4d v1)
          Multiplies the transpose of this matrix by the vector v1 and places the result in vr.
 void negate()
          Negates this matrix in place.
 double oneNorm()
          Returns the 1 norm of this matrix.
 int rowSize()
          Returns the number of rows in this matrix (which is always 4).
 void set(double[] vals)
          Sets the elements of this matrix from an array of doubles. The elements in the array should be stored using row-major order, so that element (i,j) is stored at location i*colSize()+j.
 void set(int i, int j, double value)
          Sets a single element of this matrix.
 void set(Matrix4dObject M)
          Sets the values of this matrix to those of matrix M.
 void setColumn(int j, double[] values)
          Sets a column of this matrix from an array of doubles.
 void setColumn(int j, Vector4d col)
          Sets a column of this matrix to the specified 4-vector.
 void setIdentity()
          Sets this matrix to the identity.
 void setRow(int i, double[] values)
          Set a row of this matrix from an array of doubles.
 void setRow(int i, Vector4d row)
          Sets a row of this matrix to the specified 4-vector.
 void transpose()
          Transposes this matrix in place.
 
Methods inherited from class maspack.matrix.MatrixObject
epsilonEquals, equals, equals, get, getColumn, getRow, isFixedSize, scan, set, set, setColumn, setRow, setSize, toString, toString, toString
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m00

public double m00
Matrix element (0,0)


m01

public double m01
Matrix element (0,1)


m02

public double m02
Matrix element (0,2)


m03

public double m03
Matrix element (0,3)


m10

public double m10
Matrix element (1,0)


m11

public double m11
Matrix element (1,1)


m12

public double m12
Matrix element (1,2)


m13

public double m13
Matrix element (1,3)


m20

public double m20
Matrix element (2,0)


m21

public double m21
Matrix element (2,1)


m22

public double m22
Matrix element (2,2)


m23

public double m23
Matrix element (2,3)


m30

public double m30
Matrix element (3,0)


m31

public double m31
Matrix element (3,1)


m32

public double m32
Matrix element (3,2)


m33

public double m33
Matrix element (3,3)

Constructor Detail

Matrix4dObject

public Matrix4dObject()
Method Detail

rowSize

public final int rowSize()
Returns the number of rows in this matrix (which is always 4).

Specified by:
rowSize in class MatrixObject
Returns:
4

colSize

public final int colSize()
Returns the number of columns in this matrix (which is always 4).

Specified by:
colSize in class MatrixObject
Returns:
4

get

public double get(int i,
                  int j)
Gets a single element of this matrix.

Specified by:
get in class MatrixObject
Parameters:
i - element row index
j - element column index
Returns:
element value

get

public void get(double[] values)
Copies the elements of this matrix into an array of doubles. The elements are stored using row-major order, so that element (i,j) is stored at location i*colSize()+j.

Overrides:
get in class MatrixObject
Parameters:
values - array into which values are copied

getColumn

public void getColumn(int j,
                      double[] values)
Copies a column of this matrix into an array of doubles.

Overrides:
getColumn in class MatrixObject
Parameters:
j - column index
values - array into which the column is copied

getColumn

public void getColumn(int j,
                      Vector4d col)
Copies a column of this matrix into a 4-vector.

Parameters:
j - column index
col - 4-vector into which the column is copied

getRow

public void getRow(int i,
                   double[] values)
Copies a row of this matrix into an array of doubles.

Overrides:
getRow in class MatrixObject
Parameters:
i - row index
values - array into which the row is copied

getRow

public void getRow(int i,
                   Vector4d row)
Copies a row of this matrix into a 4-vector.

Parameters:
i - row index
row - 4-vector into which the row is copied

set

public final void set(int i,
                      int j,
                      double value)
Sets a single element of this matrix.

Specified by:
set in class MatrixObject
Parameters:
i - element row index
j - element column index
value - element value

set

public void set(double[] vals)
Sets the elements of this matrix from an array of doubles. The elements in the array should be stored using row-major order, so that element (i,j) is stored at location i*colSize()+j.

Overrides:
set in class MatrixObject
Parameters:
vals - array from which values are copied

setColumn

public void setColumn(int j,
                      double[] values)
Sets a column of this matrix from an array of doubles.

Overrides:
setColumn in class MatrixObject
Parameters:
j - column index
values - array from which column values are copied

setColumn

public void setColumn(int j,
                      Vector4d col)
Sets a column of this matrix to the specified 4-vector.

Parameters:
j - column index
col - 4-vector from which the column is copied

setRow

public void setRow(int i,
                   double[] values)
Set a row of this matrix from an array of doubles.

Overrides:
setRow in class MatrixObject
Parameters:
i - row index
values - array from which the row is copied

setRow

public void setRow(int i,
                   Vector4d row)
Sets a row of this matrix to the specified 4-vector.

Parameters:
i - row index
row - 4-vector from which the row is copied

set

public void set(Matrix4dObject M)
Sets the values of this matrix to those of matrix M.

Parameters:
M - matrix whose values are to be copied

mul

public void mul(Vector4d vr,
                Vector4d v1)
Multiplies this matrix by the column vector v1 and places the result in the vector vr. If M represents this matrix, this is equivalent to computing
  vr = M v1
 

Parameters:
vr - result vector
v1 - vector to multiply by

mul

public void mul(Vector4d vr)
Multiplies this matrix by the column vector vr and places the result back into vr. If M represents this matrix, this is equivalent to computing
  vr = M vr
 

Parameters:
vr - vector to multiply (in place)

mulTranspose

public void mulTranspose(Vector4d vr,
                         Vector4d v1)
Multiplies the transpose of this matrix by the vector v1 and places the result in vr. If M represents this matrix, this is equivalent to computing
  vr = v1 M
 

Parameters:
vr - result vector
v1 - vector to multiply by

mulTranspose

public void mulTranspose(Vector4d vr)
Multiplies the transpose of this matrix by the vector vr and places the result back in vr. If M represents this matrix, this is equivalent to computing
  vr = vr M
 

Parameters:
vr - vector to multiply by (in place)

mulInverse

public boolean mulInverse(Vector4d vr,
                          Vector4d v1)
Multiplies the column vector v1 by the inverse of this matrix and places the result in vr.

Parameters:
vr - result vector
v1 - vector to multiply by
Returns:
false if this matrix is singular

mulInverse

public boolean mulInverse(Vector4d vr)
Multiplies the column vector vr by the inverse of this matrix and places the result back in vr.

Parameters:
vr - vector to multiply by (in place)
Returns:
false if this matrix is singular

mulInverseTranspose

public boolean mulInverseTranspose(Vector4d vr,
                                   Vector4d v1)
Multiplies the column vector v1 by the inverse transpose of this matrix and places the result in vr.

Parameters:
vr - result vector
v1 - vector to multiply by
Returns:
false if this matrix is singular

mulInverseTranspose

public boolean mulInverseTranspose(Vector4d vr)
Multiplies the column vector vr by the inverse transpose of this matrix and places the result back in vr.

Parameters:
vr - vector to multiply by (in place)
Returns:
false if this matrix is singular

negate

public void negate()
Negates this matrix in place.


transpose

public void transpose()
Transposes this matrix in place.


setIdentity

public void setIdentity()
Sets this matrix to the identity.


epsilonEquals

public boolean epsilonEquals(Matrix4dObject M1,
                             double epsilon)
Returns true if the elements of this matrix equal those of matrix M1within a prescribed tolerance epsilon.

Parameters:
M1 - matrix to compare with
epsilon - comparison tolerance
Returns:
false if the matrices are not equal within the specified tolerance

equals

public boolean equals(Matrix4dObject M1)
Returns true if the elements of this matrix exactly equal those of matrix M1.

Parameters:
M1 - matrix to compare with
Returns:
false if the matrices are not equal

infinityNorm

public double infinityNorm()
Returns the infinity norm of this matrix. This is equal to the maximum of the vector 1-norm of each row.

Overrides:
infinityNorm in class MatrixObject
Returns:
infinity norm of this matrix

oneNorm

public double oneNorm()
Returns the 1 norm of this matrix. This is equal to the maximum of the vector 1-norm of each column.

Overrides:
oneNorm in class MatrixObject
Returns:
1 norm of this matrix

frobeniusNorm

public double frobeniusNorm()
Returns the Frobenius norm of this matrix. This is equal to the square root of the sum of the squares of each element.

Overrides:
frobeniusNorm in class MatrixObject
Returns:
Frobenius norm of this matrix

invert

public boolean invert()
Inverts this matrix in place, returning false if the matrix is detected to be singular. The inverse is computed using an LU decomposition with partial pivoting.


determinant

public double determinant()
                   throws ImproperSizeException
Returns the determinant of this matrix

Overrides:
determinant in class MatrixObject
Returns:
matrix determinant
Throws:
ImproperSizeException - if the matrix is not square