maspack.matrix
Class Matrix2d

java.lang.Object
  extended by maspack.matrix.MatrixBase
      extended by maspack.matrix.DenseMatrixBase
          extended by maspack.matrix.Matrix2dBase
              extended by maspack.matrix.Matrix2d
All Implemented Interfaces:
java.lang.Cloneable, DenseMatrix, LinearTransformNd, Matrix, Clonable
Direct Known Subclasses:
Matrix2x2Block

public class Matrix2d
extends Matrix2dBase

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


Nested Class Summary
 
Nested classes/interfaces inherited from interface maspack.matrix.Matrix
Matrix.Partition, Matrix.WriteFormat
 
Field Summary
static Matrix2d IDENTITY
          Global identity matrix.
static Matrix2d ZERO
          Global zero matrix.
 
Fields inherited from class maspack.matrix.Matrix2dBase
m00, m01, m10, m11
 
Fields inherited from interface maspack.matrix.Matrix
INDEFINITE, POSITIVE_DEFINITE, SPD, SYMMETRIC
 
Constructor Summary
Matrix2d()
          Creates a matrix and initializes it to zero.
Matrix2d(double[] vals)
          Creates a matrix and initializes its elements from an array of values.
Matrix2d(Matrix M)
          Creates a matrix and initializes its elements to those of the matrix M.
Matrix2d(Matrix2dBase M)
          Creates a matrix and initializes its elements to those of the matrix M.
 
Method Summary
 void add(Matrix2dBase M1)
          Adds this matrix to M1 and places the result in this matrix.
 void add(Matrix2dBase M1, Matrix2dBase 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.
 boolean invert(Matrix2dBase M)
          Inverts the matrix M and places the result in this matrix, return false if M is detected to be singular.
 void mul(Matrix2dBase M1)
          Multiplies this matrix by M1 and places the result in this matrix.
 void mul(Matrix2dBase M1, Matrix2dBase M2)
          Multiplies matrix M1 by M2 and places the result in this matrix.
 boolean mulInverse(Matrix2dBase M1)
          Multiplies this matrix by the inverse of M1 and places the result in this matrix.
 boolean mulInverseBoth(Matrix2dBase M1, Matrix2dBase M2)
          Multiplies the inverse of matrix M1 by the inverse of M2 and places the result in this matrix.
 boolean mulInverseLeft(Matrix2dBase M1, Matrix2dBase M2)
          Multiplies the inverse of matrix M1 by M2 and places the result in this matrix.
 boolean mulInverseRight(Matrix2dBase M1, Matrix2dBase M2)
          Multiplies matrix M1 by the inverse of M2 and places the result in this matrix.
 void mulTranspose(Matrix2dBase M1)
          Multiplies this matrix by the transpose of M1 and places the result in this matrix.
 void mulTransposeBoth(Matrix2dBase M1, Matrix2dBase M2)
          Multiplies the transpose of matrix M1 by the transpose of M2 and places the result in this matrix.
 void mulTransposeLeft(Matrix2dBase M1, Matrix2dBase M2)
          Multiplies the transpose of matrix M1 by M2 and places the result in this matrix.
 void mulTransposeRight(Matrix2dBase M1, Matrix2dBase M2)
          Multiplies matrix M1 by the transpose of M2 and places the result in this matrix.
 void negate(Matrix2dBase 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, Matrix2dBase M1)
          Scales the elements of matrix M1 by s and places the results in this matrix.
 void scaledAdd(double s, Matrix2dBase M1)
          Computes s M1 and adds the result to this matrix.
 void scaledAdd(double s, Matrix2dBase M1, Matrix2dBase M2)
          Computes s M1 + M2 and places the result in this matrix.
 void setColumns(Vector2d v0, Vector2d v1)
          Sets the columns of this matrix to the vectors v0 and v1.
 void setDiagonal(double[] vals)
          Sets this matrix to a diagonal matrix whose values are specified by the array vals.
 void setDiagonal(double m00, double m11)
          Sets this matrix to a diagonal matrix whose values are specified.
 void setDiagonal(Vector2d 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 setRows(Vector2d v0, Vector2d v1)
          Sets the rows of this matrix to the vectors v0 and v1.
 void setZero()
          Sets the elements of this matrix to zero.
 void sub(Matrix2dBase M1)
          Subtracts this matrix from M1 and places the result in this matrix.
 void sub(Matrix2dBase M1, Matrix2dBase M2)
          Subtracts matrix M1 from M2 and places the result in this matrix.
 void transpose(Matrix2dBase M1)
          Takes the transpose of matrix M1 and places the result in this matrix.
 
Methods inherited from class maspack.matrix.Matrix2dBase
clone, colSize, determinant, epsilonEquals, equals, frobeniusNorm, get, get, getColumn, getColumn, getColumn, getRow, getRow, getRow, infinityNorm, mul, mul, mul, mulAdd, mulInverse, mulInverse, mulInverseTranspose, mulInverseTranspose, mulTranspose, mulTranspose, negate, oneNorm, rowSize, set, set, set, set, setColumn, setColumn, setIdentity, setRow, setRow, transpose
 
Methods inherited from class maspack.matrix.DenseMatrixBase
add, checkConsistency, set, set, set, setCCSValues, setColumn, setCRSValues, setRow, setSubMatrix
 
Methods inherited from class maspack.matrix.MatrixBase
containsNaN, epsilonEquals, equals, get, getCCSIndices, getCCSIndices, getCCSValues, getCCSValues, getColumn, getCRSIndices, getCRSIndices, getCRSValues, getCRSValues, getDefaultFormat, getRow, getSize, getSubMatrix, hasNaN, idString, isFixedSize, isSymmetric, mul, mul, mulAdd, mulAdd, mulAdd, mulTranspose, mulTranspose, mulTranspose, mulTransposeAdd, mulTransposeAdd, mulTransposeAdd, numNonZeroVals, numNonZeroVals, scan, setCRSValues, setDefaultFormat, setSize, toString, toString, toString, trace, write, write, write, write, write, writeToFile
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface maspack.matrix.Matrix
epsilonEquals, equals, getCCSIndices, getCCSIndices, getCCSValues, getCCSValues, getColumn, getCRSIndices, getCRSIndices, getCRSValues, getCRSValues, getRow, getSize, getSubMatrix, isFixedSize, isSymmetric, mul, mul, mulAdd, mulAdd, mulAdd, mulTranspose, mulTranspose, mulTranspose, mulTransposeAdd, mulTransposeAdd, mulTransposeAdd, numNonZeroVals, numNonZeroVals, scan, setSize, toString, trace, write, write, write
 

Field Detail

IDENTITY

public static final Matrix2d IDENTITY
Global identity matrix. Should not be modified.


ZERO

public static final Matrix2d ZERO
Global zero matrix. Should not be modified.

Constructor Detail

Matrix2d

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


Matrix2d

public Matrix2d(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*2+j

Matrix2d

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

Parameters:
M - matrix object to be copied.

Matrix2d

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

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

setColumns

public void setColumns(Vector2d v0,
                       Vector2d v1)
Sets the columns of this matrix to the vectors v0 and v1.

Parameters:
v0 - values for the first column
v1 - values for the second column

setRows

public void setRows(Vector2d v0,
                    Vector2d v1)
Sets the rows of this matrix to the vectors v0 and v1.

Parameters:
v0 - values for the first row
v1 - values for the second row

mul

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

Parameters:
M1 - right-hand matrix

mul

public void mul(Matrix2dBase M1,
                Matrix2dBase 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(Matrix2dBase 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(Matrix2dBase M1,
                             Matrix2dBase 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(Matrix2dBase M1,
                              Matrix2dBase 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(Matrix2dBase M1,
                             Matrix2dBase 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(Matrix2dBase 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(Matrix2dBase M1,
                               Matrix2dBase 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(Matrix2dBase M1,
                              Matrix2dBase 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(Matrix2dBase M1,
                              Matrix2dBase 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(Matrix2dBase M1,
                Matrix2dBase 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(Matrix2dBase M1)
Adds this matrix to M1 and places the result in this matrix.

Parameters:
M1 - right-hand matrix

sub

public void sub(Matrix2dBase M1,
                Matrix2dBase 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(Matrix2dBase 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,
                  Matrix2dBase 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

scaledAdd

public void scaledAdd(double s,
                      Matrix2dBase M1,
                      Matrix2dBase M2)
Computes s M1 + M2 and places the result in this matrix.

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

scaledAdd

public void scaledAdd(double s,
                      Matrix2dBase M1)
Computes s M1 and adds the result to this matrix.

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

negate

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

Parameters:
M1 - matrix to negate

transpose

public void transpose(Matrix2dBase 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.

Overrides:
invert in class Matrix2dBase

invert

public boolean invert(Matrix2dBase M)
Inverts the matrix M and places the result in this matrix, return false if M is detected to be singular.

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

setDiagonal

public void setDiagonal(Vector2d 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

setDiagonal

public void setDiagonal(double m00,
                        double m11)
Sets this matrix to a diagonal matrix whose values are specified.

Parameters:
m00 - first diagonal value
m11 - second diagonal value