maspack.matrix

Class Matrix3dBase

• Nested classes/interfaces inherited from interface maspack.matrix.Matrix

`Matrix.Partition, Matrix.WriteFormat`
• Field Summary

Fields
Modifier and Type Field and Description
`double` `m00`
Matrix element (0,0)
`double` `m01`
Matrix element (0,1)
`double` `m02`
Matrix element (0,2)
`double` `m10`
Matrix element (1,0)
`double` `m11`
Matrix element (1,1)
`double` `m12`
Matrix element (1,2)
`double` `m20`
Matrix element (2,0)
`double` `m21`
Matrix element (2,1)
`double` `m22`
Matrix element (2,2)
• Fields inherited from interface maspack.matrix.Matrix

`INDEFINITE, POSITIVE_DEFINITE, SPD, SYMMETRIC`
• Constructor Summary

Constructors
Constructor and Description
`Matrix3dBase()`
• Method Summary

All Methods
Modifier and Type Method and Description
`Matrix3dBase` `clone()`
`int` `colSize()`
Returns the number of columns in this matrix (which is always 3).
`double` `determinant()`
Returns the determinant of this matrix
`boolean` ```epsilonEquals(Matrix3dBase M1, double eps)```
Returns true if the elements of this matrix equal those of matrix `M1`within a prescribed tolerance `epsilon`.
`boolean` `equals(Matrix3dBase M1)`
Returns true if the elements of this matrix exactly equal those of matrix `M1`.
`void` ```factorQR(Matrix3dBase Q, Matrix3dBase R)```
Computes the QR decompostion for this matrix, for which
`double` `frobeniusNorm()`
Returns the Frobenius norm of this matrix.
`void` `get(double[] values)`
Copies the elements of this matrix into an array of doubles.
`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, double[] values, int off)```
Copies a column of this matrix into an array of doubles, starting at a specified offset.
`void` ```getColumn(int j, Vector3d col)```
Copies a column of this matrix into a 3-vector.
`void` ```getRow(int i, double[] values)```
Copies a row of this matrix into an array of doubles.
`void` ```getRow(int i, double[] values, int off)```
Copies a row of this matrix into an array of doubles, starting at a specified offset.
`void` ```getRow(int i, Vector3d row)```
Copies a row of this matrix into a 3-vector.
`double` `infinityNorm()`
Returns the infinity norm of this matrix.
`void` ```inverseTransform(RotationMatrix3d R, Matrix3dBase M1)```
Applies an inverse rotational transformation R to a matrix M1 and place the result in this matrix.
`boolean` `invert()`
Inverts this matrix in place, returning false if the matrix is detected to be singular.
`boolean` `isIdentity()`
Returns true if this matrix equals the identity.
`boolean` `isSymmetric(double tol)`
Returns true if this matrix is symmetric within a given absolute tolerance.
`static void` `main(java.lang.String[] args)`
`void` ```mul(Matrix3dBase M1, Matrix3dBase M2)```
Multiplies matrix M1 by M2 and places the result in this matrix.
`void` `mul(Vector3d vr)`
Multiplies this matrix by the column vector vr and places the result back into vr.
`void` ```mul(Vector3d vr, Vector3d v1)```
Multiplies this matrix by the column vector v1 and places the result in the vector vr.
`void` ```mul(VectorNd vr, VectorNd v1)```
Multiplies this matrix by the column vector v1 and places the result in the vector vr.
`void` ```mulAdd(Matrix M1, Matrix M2)```
Multiplies M1 by M2 and places the result in this matrix.
`void` ```mulAdd(Vector3d vr, Vector3d v1, Vector3d v2)```
Multiplies this matrix by the column vector v1, adds the vector v2, and places the result in the vector vr.
`boolean` `mulInverse(Vector3d vr)`
Multiplies the column vector vr by the inverse of this matrix and places the result back in vr.
`boolean` ```mulInverse(Vector3d vr, Vector3d v1)```
Multiplies the column vector v1 by the inverse of this matrix and places the result in vr.
`boolean` `mulInverseTranspose(Vector3d vr)`
Multiplies the column vector vr by the inverse transpose of this matrix and places the result back in vr.
`boolean` ```mulInverseTranspose(Vector3d vr, Vector3d v1)```
Multiplies the column vector v1 by the inverse transpose of this matrix and places the result in vr.
`void` `mulTranspose(Vector3d vr)`
Multiplies the transpose of this matrix by the vector vr and places the result back in vr.
`void` ```mulTranspose(Vector3d vr, Vector3d v1)```
Multiplies the transpose of this matrix by the vector v1 and places the result in vr.
`void` ```mulTransposeAdd(Vector3d vr, Vector3d v1, Vector3d v2)```
Multiplies the transpose of this matrix by the vector v1, adds the vector v2, and places the result in vr.
`void` ```mulTransposeLeftAdd(Matrix M1, Matrix M2)```
Multiplies M1^T by M2 and places the result in this matrix.
`void` ```mulTransposeRightAdd(Matrix M1, Matrix M2)```
Multiplies M1 by M2^T and places the result in this matrix.
`void` `negate()`
Negates this matrix in place.
`void` `negateColumn(int colIdx)`
Negates a column of this matrix.
`void` `negateRow(int rowIdx)`
Negates a row of this matrix.
`double` `oneNorm()`
Returns the 1 norm of this matrix.
`double` `orthogonalDeterminant()`
Returns the determinant of this matrix, assuming that it is orthogonal.
`int` `rowSize()`
Returns the number of rows in this matrix (which is always 3).
`void` ```scaleColumn(int j, double s)```
Scale a column
`void` ```scaleRow(int i, double s)```
Scale a row by a particular value
`void` `set(double[] vals)`
Sets the elements of this matrix from an array of doubles.
`void` ```set(int i, int j, double value)```
Sets a single element of this matrix.
`void` `set(Matrix M)`
Sets the values of this matrix to those of matrix M.
`void` `set(Matrix3dBase 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, Vector3d col)```
Sets a column of this matrix to the specified 3-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, Vector3d row)```
Sets a row of this matrix to the specified 3-vector.
`boolean` ```solve(Vector3d x, Vector3d b)```
Solves this matrix for `x` given a right hand side `b`, returning `false` if the matrix is detected to be singular.
`boolean` ```solveTranspose(Vector3d x, Vector3d b)```
Solves the transpose of this matrix for `x` given a right hand side `b`, returning `false` if the matrix is detected to be singular.
`double` `trace()`
Returns the trace of this matrix.
`void` `transpose()`
Transposes this matrix in place.
• Methods inherited from class maspack.matrix.DenseMatrixBase

`add, checkConsistency, set, set, set, setCCSValues, setColumn, setCRSValues, setRandom, setRow, setSubMatrix`
• Methods inherited from class maspack.matrix.MatrixBase

`containsNaN, epsilonEquals, equals, frobeniusNormSquared, get, getCCSIndices, getCCSIndices, getCCSIndices, getCCSValues, getCCSValues, getCCSValues, getColumn, getCRSIndices, getCRSIndices, getCRSIndices, getCRSValues, getCRSValues, getCRSValues, getDefaultFormat, getRow, getSize, getSubMatrix, hasNaN, idString, isFixedSize, isWritable, maxNorm, mul, mul, mulAdd, mulAdd, mulAdd, mulTranspose, mulTranspose, mulTranspose, mulTransposeAdd, mulTransposeAdd, mulTransposeAdd, numNonZeroVals, numNonZeroVals, scan, scan, setCRSValues, setDefaultFormat, setSize, toString, toString, toString, write, write, 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, frobeniusNormSquared, getCCSIndices, getCCSIndices, getCCSIndices, getCCSValues, getCCSValues, getCCSValues, getColumn, getCRSIndices, getCRSIndices, getCRSIndices, getCRSValues, getCRSValues, getCRSValues, getRow, getSize, getSubMatrix, isFixedSize, maxNorm, mul, mul, mulAdd, mulAdd, mulAdd, mulTranspose, mulTranspose, mulTranspose, mulTransposeAdd, mulTransposeAdd, mulTransposeAdd, numNonZeroVals, numNonZeroVals, scan, setSize, toString, toString, write, write, write`
• 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)
• m10

`public double m10`
Matrix element (1,0)
• m11

`public double m11`
Matrix element (1,1)
• m12

`public double m12`
Matrix element (1,2)
• m20

`public double m20`
Matrix element (2,0)
• m21

`public double m21`
Matrix element (2,1)
• m22

`public double m22`
Matrix element (2,2)
• Constructor Detail

• Matrix3dBase

`public Matrix3dBase()`
• Method Detail

• rowSize

`public final int rowSize()`
Returns the number of rows in this matrix (which is always 3).
Specified by:
`rowSize` in interface `LinearTransformNd`
Specified by:
`rowSize` in interface `Matrix`
Specified by:
`rowSize` in class `MatrixBase`
Returns:
3
• colSize

`public final int colSize()`
Returns the number of columns in this matrix (which is always 3).
Specified by:
`colSize` in interface `LinearTransformNd`
Specified by:
`colSize` in interface `Matrix`
Specified by:
`colSize` in class `MatrixBase`
Returns:
3
• get

```public double get(int i,
int j)```
Gets a single element of this matrix.
Specified by:
`get` in interface `Matrix`
Specified by:
`get` in class `MatrixBase`
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`.
Specified by:
`get` in interface `Matrix`
Overrides:
`get` in class `MatrixBase`
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.
Specified by:
`getColumn` in interface `Matrix`
Overrides:
`getColumn` in class `MatrixBase`
Parameters:
`j` - column index
`values` - array into which the column is copied
• getColumn

```public void getColumn(int j,
double[] values,
int off)```
Copies a column of this matrix into an array of doubles, starting at a specified offset.
Specified by:
`getColumn` in interface `Matrix`
Overrides:
`getColumn` in class `MatrixBase`
Parameters:
`j` - column index
`values` - array into which the column is copied
`off` - offset in values where copying should begin
• getColumn

```public void getColumn(int j,
Vector3d col)```
Copies a column of this matrix into a 3-vector.
Parameters:
`j` - column index
`col` - 3-vector into which the column is copied
• scaleColumn

```public void scaleColumn(int j,
double s)```
Scale a column
• getRow

```public void getRow(int i,
double[] values)```
Copies a row of this matrix into an array of doubles.
Specified by:
`getRow` in interface `Matrix`
Overrides:
`getRow` in class `MatrixBase`
Parameters:
`i` - row index
`values` - array into which the row is copied
• getRow

```public void getRow(int i,
double[] values,
int off)```
Copies a row of this matrix into an array of doubles, starting at a specified offset.
Specified by:
`getRow` in interface `Matrix`
Overrides:
`getRow` in class `MatrixBase`
Parameters:
`i` - row index
`values` - array into which the row is copied
`off` - offset in values where copying should begin
• scaleRow

```public void scaleRow(int i,
double s)```
Scale a row by a particular value
• getRow

```public void getRow(int i,
Vector3d row)```
Copies a row of this matrix into a 3-vector.
Parameters:
`i` - row index
`row` - 3-vector into which the row is copied
• set

```public void set(int i,
int j,
double value)```
Sets a single element of this matrix.
Specified by:
`set` in interface `DenseMatrix`
Specified by:
`set` in class `DenseMatrixBase`
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`.
Specified by:
`set` in interface `DenseMatrix`
Overrides:
`set` in class `DenseMatrixBase`
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.
Specified by:
`setColumn` in interface `DenseMatrix`
Overrides:
`setColumn` in class `DenseMatrixBase`
Parameters:
`j` - column index
`values` - array from which column values are copied
• setColumn

```public void setColumn(int j,
Vector3d col)```
Sets a column of this matrix to the specified 3-vector.
Parameters:
`j` - column index
`col` - 3-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.
Specified by:
`setRow` in interface `DenseMatrix`
Overrides:
`setRow` in class `DenseMatrixBase`
Parameters:
`i` - row index
`values` - array from which the row is copied
• setRow

```public void setRow(int i,
Vector3d row)```
Sets a row of this matrix to the specified 3-vector.
Parameters:
`i` - row index
`row` - 3-vector from which the row is copied
• set

`public void set(Matrix M)`
Sets the values of this matrix to those of matrix M.
Specified by:
`set` in interface `Matrix`
Overrides:
`set` in class `DenseMatrixBase`
Parameters:
`M` - matrix whose values are to be copied
• set

`public void set(Matrix3dBase 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(Matrix3dBase M1,
Matrix3dBase M2)```
Multiplies matrix M1 by M2 and places the result in this matrix.
Parameters:
`M1` - left-hand matrix
`M2` - right-hand matrix
• inverseTransform

```public void inverseTransform(RotationMatrix3d R,
Matrix3dBase M1)```
Applies an inverse rotational transformation R to a matrix M1 and place the result in this matrix. This is equivalent to forming the product
```    R^T M1 R
```
Parameters:
`R` - rotational transformation matrix
`M1` - matrix to transform

```public void mulAdd(Matrix M1,
Matrix M2)```
Multiplies M1 by M2 and places the result in this matrix.
Parameters:
`M1` - left matrix term
`M2` - right matrix term

```public void mulTransposeRightAdd(Matrix M1,
Matrix M2)```
Multiplies M1 by M2^T and places the result in this matrix.
Parameters:
`M1` - left matrix term
`M2` - right matrix term

```public void mulTransposeLeftAdd(Matrix M1,
Matrix M2)```
Multiplies M1^T by M2 and places the result in this matrix.
Parameters:
`M1` - left matrix term
`M2` - right matrix term
• mul

```public void mul(Vector3d vr,
Vector3d 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(VectorNd vr,
VectorNd 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
```
Specified by:
`mul` in interface `LinearTransformNd`
Specified by:
`mul` in interface `Matrix`
Overrides:
`mul` in class `MatrixBase`
Parameters:
`vr` - result vector
`v1` - vector to multiply by

```public void mulAdd(Vector3d vr,
Vector3d v1,
Vector3d v2)```
Multiplies this matrix by the column vector v1, adds the vector v2, and places the result in the vector vr. If M represents this matrix, this is equivalent to computing
```  vr = M v1 + v2
```
Parameters:
`vr` - result vector
`v1` - vector to multiply by
`v2` - vector to add
• mul

`public void mul(Vector3d 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(Vector3d vr,
Vector3d 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

```public void mulTransposeAdd(Vector3d vr,
Vector3d v1,
Vector3d v2)```
Multiplies the transpose of this matrix by the vector v1, adds the vector v2, and places the result in vr. If M represents this matrix, this is equivalent to computing
```  vr = v1 M + v2
```
Parameters:
`vr` - result vector
`v1` - vector to multiply by
`v2` - vector to add
• mulTranspose

`public void mulTranspose(Vector3d 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(Vector3d vr,
Vector3d v1)```
Multiplies the column vector v1 by the inverse of this matrix and places the result in vr. This is equivalent to `solve(vr,v1)`.
Parameters:
`vr` - result vector
`v1` - vector to multiply by
Returns:
false if this matrix is singular
• mulInverse

`public boolean mulInverse(Vector3d 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(Vector3d vr,
Vector3d v1)```
Multiplies the column vector v1 by the inverse transpose of this matrix and places the result in vr. This is equivalent to `solveTranspose(vr,v1)`.
Parameters:
`vr` - result vector
`v1` - vector to multiply by
Returns:
false if this matrix is singular
• mulInverseTranspose

`public boolean mulInverseTranspose(Vector3d 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(Matrix3dBase M1,
double eps)```
Returns true if the elements of this matrix equal those of matrix `M1`within a prescribed tolerance `epsilon`.
Parameters:
`M1` - matrix to compare with
`eps` - comparison tolerance
Returns:
false if the matrices are not equal within the specified tolerance
• equals

`public boolean equals(Matrix3dBase 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.
Specified by:
`infinityNorm` in interface `Matrix`
Overrides:
`infinityNorm` in class `MatrixBase`
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.
Specified by:
`oneNorm` in interface `Matrix`
Overrides:
`oneNorm` in class `MatrixBase`
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.
Specified by:
`frobeniusNorm` in interface `Matrix`
Overrides:
`frobeniusNorm` in class `MatrixBase`
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 unrolled LU decomposition with partial pivoting.
• solve

```public boolean solve(Vector3d x,
Vector3d b)```
Solves this matrix for `x` given a right hand side `b`, returning `false` if the matrix is detected to be singular. The solution is computed using partial pivoting.
Parameters:
`x` - result
`b` - right hand side
Returns:
false if this matrix is singular
• solveTranspose

```public boolean solveTranspose(Vector3d x,
Vector3d b)```
Solves the transpose of this matrix for `x` given a right hand side `b`, returning `false` if the matrix is detected to be singular. The solution is computed using partial pivoting.
Parameters:
`x` - result
`b` - right hand side
Returns:
false if this matrix is singular
• determinant

```public double determinant()
throws ImproperSizeException```
Returns the determinant of this matrix
Specified by:
`determinant` in interface `Matrix`
Overrides:
`determinant` in class `MatrixBase`
Returns:
matrix determinant
Throws:
`ImproperSizeException` - if the matrix is not square
• isIdentity

`public boolean isIdentity()`
Returns true if this matrix equals the identity.
Returns:
true if this matrix equals the identity
• orthogonalDeterminant

`public double orthogonalDeterminant()`
Returns the determinant of this matrix, assuming that it is orthogonal. This is done by computing the cross product of the first two columns and then computing its dot product with the third column.
Returns:
orthogonal matrix determinant
• factorQR

```public void factorQR(Matrix3dBase Q,
Matrix3dBase R)```
Computes the QR decompostion for this matrix, for which
```    M = Q R
```
where Q is orthogonal and R is upper triangular.
Parameters:
`Q` - if non-null, returns Q
`R` - if non-null, returns R The computation is the same as that performed by the QRDecomposition class, except significantly faster.
• clone

`public Matrix3dBase clone()`
Specified by:
`clone` in interface `Clonable`
Overrides:
`clone` in class `java.lang.Object`
• trace

`public double trace()`
Returns the trace of this matrix.
Specified by:
`trace` in interface `Matrix`
Overrides:
`trace` in class `MatrixBase`
Returns:
matrix trace
• isSymmetric

`public boolean isSymmetric(double tol)`
Returns true if this matrix is symmetric within a given absolute tolerance. Specifically, each off-diagonal element must equal it's transposed counterpart within the given tolerance.
Specified by:
`isSymmetric` in interface `Matrix`
Overrides:
`isSymmetric` in class `MatrixBase`
Parameters:
`tol` - absolute tolerance for checking equality of off-diagonal elements
• negateColumn

`public void negateColumn(int colIdx)`
Negates a column of this matrix.
Parameters:
`colIdx` - index of the column to negate
• negateRow

`public void negateRow(int rowIdx)`
Negates a row of this matrix.
Parameters:
`rowIdx` - index of the row to negate
• main

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