maspack.matrix
Class Matrix3d

java.lang.Object
  extended bymaspack.matrix.MatrixObject
      extended bymaspack.matrix.Matrix3dObject
          extended bymaspack.matrix.Matrix3d
All Implemented Interfaces:
java.io.Serializable

public class Matrix3d
extends Matrix3dObject

A general 3 x 3 matrix with the elements stored as explicit fields.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class maspack.matrix.Matrix3dObject
m00, m01, m02, m10, m11, m12, m20, m21, m22
 
Constructor Summary
Matrix3d()
          Creates a matrix and initializes it to zero.
Matrix3d(double[] vals)
          Creates a matrix and initializes its elements from an array of values.
Matrix3d(Matrix3dObject M)
          Creates a matrix and initializes its elements to those of the matrix M.
 
Method Summary
 void add(Matrix3dObject M1)
          Adds this matrix to M1 and places the result in this matrix.
 void add(Matrix3dObject M1, Matrix3dObject M2)
          Adds matrix M1 to M2 and places the result in this matrix.
 boolean invert()
          Inverts this matrix in place, returning false if the matrix is detected to be singular. The inverse is computed using an unrolled LU decomposition with partial pivoting.
 boolean invert(Matrix3dObject M)
          Inverts the matrix M and places the result in this matrix, return false if M is detected to be singular. The inverse is computed using an unrolled LU decomposition with partial pivoting.
static void main(java.lang.String[] args)
           
 void mul(Matrix3dObject M1)
          Multiplies this matrix by M1 and places the result in this matrix.
 void mul(Matrix3dObject M1, Matrix3dObject M2)
          Multiplies matrix M1 by M2 and places the result in this matrix.
 boolean mulInverse(Matrix3dObject M1)
          Multiplies this matrix by the inverse of M1 and places the result in this matrix.
 boolean mulInverseBoth(Matrix3dObject M1, Matrix3dObject M2)
          Multiplies the inverse of matrix M1 by the inverse of M2 and places the result in this matrix.
 boolean mulInverseLeft(Matrix3dObject M1, Matrix3dObject M2)
          Multiplies the inverse of matrix M1 by M2 and places the result in this matrix.
 boolean mulInverseRight(Matrix3dObject M1, Matrix3dObject M2)
          Multiplies matrix M1 by the inverse of M2 and places the result in this matrix.
 void mulTranspose(Matrix3dObject M1)
          Multiplies this matrix by the transpose of M1 and places the result in this matrix.
 void mulTransposeBoth(Matrix3dObject M1, Matrix3dObject M2)
          Multiplies the transpose of matrix M1 by the transpose of M2 and places the result in this matrix.
 void mulTransposeLeft(Matrix3dObject M1, Matrix3dObject M2)
          Multiplies the transpose of matrix M1 by M2 and places the result in this matrix.
 void mulTransposeRight(Matrix3dObject M1, Matrix3dObject M2)
          Multiplies matrix M1 by the transpose of M2 and places the result in this matrix.
 void negate(Matrix3dObject M1)
          Sets this matrix to the negative of M1.
 void scale(double s)
          Scales the elements of this matrix by s.
 void scale(double s, Matrix3dObject M1)
          Scales the elements of matrix M1 by s and places the results in this matrix.
 void setDiagonal(double[] vals)
          Sets this matrix to a diagonal matrix whose values are specified by the array vals.
 void setDiagonal(Vector3d diag)
          Sets this matrix to a diagonal matrix whose values are specified by diag.
 void setRandom()
          Sets the elements of this matrix to uniformly distributed random values in the range -0.5 (inclusive) to 0.5 (exclusive).
 void setRandom(double lower, double upper)
          Sets the elements of this matrix to uniformly distributed random values in a specified range.
 void setRandom(double lower, double upper, java.util.Random generator)
          Sets the elements of this matrix to uniformly distributed random values in a specified range, using a supplied random number generator.
 void setZero()
          Sets the elements of this matrix to zero.
 void sub(Matrix3dObject M1)
          Subtracts this matrix from M1 and places the result in this matrix.
 void sub(Matrix3dObject M1, Matrix3dObject M2)
          Subtracts matrix M1 from M2 and places the result in this matrix.
 void transpose(Matrix3dObject M1)
          Takes the transpose of matrix M1 and places the result in this matrix.
 
Methods inherited from class maspack.matrix.Matrix3dObject
colSize, determinant, epsilonEquals, equals, frobeniusNorm, get, get, getColumn, getColumn, getRow, getRow, infinityNorm, mul, mul, mulInverse, mulInverse, mulInverseTranspose, mulInverseTranspose, mulTranspose, mulTranspose, negate, oneNorm, rowSize, set, set, set, setColumn, setColumn, setIdentity, setRow, setRow, transpose
 
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
 

Constructor Detail

Matrix3d

public Matrix3d()
Creates a matrix and initializes it to zero.


Matrix3d

public Matrix3d(double[] vals)
Creates a matrix and initializes its elements from an array of values.

Parameters:
vals - element values for the matrix, with element (i,j) stored at location i*3+j

Matrix3d

public Matrix3d(Matrix3dObject M)
Creates a matrix and initializes its elements to those of the matrix M.

Parameters:
M - matrix object to be copied.
Method Detail

mul

public void mul(Matrix3dObject M1)
Multiplies this matrix by M1 and places the result in this matrix.

Parameters:
M1 - right-hand matrix

mul

public void mul(Matrix3dObject M1,
                Matrix3dObject M2)
Multiplies matrix M1 by M2 and places the result in this matrix.

Parameters:
M1 - left-hand matrix
M2 - right-hand matrix

mulTranspose

public void mulTranspose(Matrix3dObject M1)
Multiplies this matrix by the transpose of M1 and places the result in this matrix.

Parameters:
M1 - right-hand matrix

mulTransposeLeft

public void mulTransposeLeft(Matrix3dObject M1,
                             Matrix3dObject M2)
Multiplies the transpose of matrix M1 by M2 and places the result in this matrix.

Parameters:
M1 - left-hand matrix
M2 - right-hand matrix

mulTransposeRight

public void mulTransposeRight(Matrix3dObject M1,
                              Matrix3dObject M2)
Multiplies matrix M1 by the transpose of M2 and places the result in this matrix.

Parameters:
M1 - left-hand matrix
M2 - right-hand matrix

mulTransposeBoth

public void mulTransposeBoth(Matrix3dObject M1,
                             Matrix3dObject M2)
Multiplies the transpose of matrix M1 by the transpose of M2 and places the result in this matrix.

Parameters:
M1 - left-hand matrix
M2 - right-hand matrix

mulInverse

public boolean mulInverse(Matrix3dObject M1)
Multiplies this matrix by the inverse of M1 and places the result in this matrix.

Parameters:
M1 - right-hand matrix
Returns:
false if M1 is singular

mulInverseRight

public boolean mulInverseRight(Matrix3dObject M1,
                               Matrix3dObject M2)
Multiplies matrix M1 by the inverse of M2 and places the result in this matrix.

Parameters:
M1 - left-hand matrix
M2 - right-hand matrix
Returns:
false if M2 is singular

mulInverseLeft

public boolean mulInverseLeft(Matrix3dObject M1,
                              Matrix3dObject M2)
Multiplies the inverse of matrix M1 by M2 and places the result in this matrix.

Parameters:
M1 - left-hand matrix
M2 - right-hand matrix
Returns:
false if M1 is singular

mulInverseBoth

public boolean mulInverseBoth(Matrix3dObject M1,
                              Matrix3dObject M2)
Multiplies the inverse of matrix M1 by the inverse of M2 and places the result in this matrix.

Parameters:
M1 - left-hand matrix
M2 - right-hand matrix
Returns:
false if M1 or M2 is singular

add

public void add(Matrix3dObject M1,
                Matrix3dObject M2)
Adds matrix M1 to M2 and places the result in this matrix.

Parameters:
M1 - left-hand matrix
M2 - right-hand matrix

add

public void add(Matrix3dObject M1)
Adds this matrix to M1 and places the result in this matrix.

Parameters:
M1 - right-hand matrix

sub

public void sub(Matrix3dObject M1,
                Matrix3dObject M2)
Subtracts matrix M1 from M2 and places the result in this matrix.

Parameters:
M1 - left-hand matrix
M2 - right-hand matrix

sub

public void sub(Matrix3dObject M1)
Subtracts this matrix from M1 and places the result in this matrix.

Parameters:
M1 - right-hand matrix

scale

public void scale(double s)
Scales the elements of this matrix by s.

Parameters:
s - scaling factor

scale

public void scale(double s,
                  Matrix3dObject M1)
Scales the elements of matrix M1 by s and places the results in this matrix.

Parameters:
s - scaling factor
M1 - matrix to be scaled

negate

public void negate(Matrix3dObject M1)
Sets this matrix to the negative of M1.

Parameters:
M1 - matrix to negate

transpose

public void transpose(Matrix3dObject M1)
Takes the transpose of matrix M1 and places the result in this matrix.

Parameters:
M1 - matrix to take the transpose of

setZero

public void setZero()
Sets the elements of this matrix to zero.


setRandom

public void setRandom()
Sets the elements of this matrix to uniformly distributed random values in the range -0.5 (inclusive) to 0.5 (exclusive).


setRandom

public void setRandom(double lower,
                      double upper)
Sets the elements of this matrix to uniformly distributed random values in a specified range.

Parameters:
lower - lower random value (inclusive)
upper - upper random value (exclusive)

setRandom

public void setRandom(double lower,
                      double upper,
                      java.util.Random generator)
Sets the elements of this matrix to uniformly distributed random values in a specified range, using a supplied random number generator.

Parameters:
lower - lower random value (inclusive)
upper - upper random value (exclusive)
generator - random number generator

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 unrolled LU decomposition with partial pivoting.

Overrides:
invert in class Matrix3dObject

invert

public boolean invert(Matrix3dObject M)
Inverts the matrix M and places the result in this matrix, return false if M is detected to be singular. The inverse is computed using an unrolled LU decomposition with partial pivoting.

Parameters:
M - matrix to invert
Returns:
false if M is singular

setDiagonal

public void setDiagonal(Vector3d diag)
Sets this matrix to a diagonal matrix whose values are specified by diag.

Parameters:
diag - diagonal values

setDiagonal

public void setDiagonal(double[] vals)
Sets this matrix to a diagonal matrix whose values are specified by the array vals.

Parameters:
vals - diagonal values

main

public static void main(java.lang.String[] args)