marf.math
Class Matrix

java.lang.Object
  extended by marf.math.Matrix
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
ComplexMatrix, Vector

public class Matrix
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable

Provides linear math and storage matrix operations. This class implements a 2-dimensional matrix of doubles; internally implemented as a single-dimensional array with a common linear algebra operations as well as methods to cut/add rows or columns and glue matrices together.

NOTE: this class provides a lot of useful and working functionality, but requires a lot of improvements. In particular in performance, documentation, and styles and consistency in operators. Some missing features will be added/filled in as well. Requires a lot of thorough testing and MathTestApp serves that purpose.

$Id: Matrix.java,v 1.47 2007/12/18 03:45:42 mokhov Exp $

Since:
0.3.0.1
Version:
$Revision: 1.47 $
Author:
Serguei Mokhov, Shuxin Fan
See Also:
Vector, Serialized Form

Nested Class Summary
static class Matrix.Direction
          Indicates the direction in which a matrix to be extended.
 
Field Summary
protected  double[] adMatrix
          Matrix itself.
static int DEFAULT_COLS
          Default dimension of X of matrix is 4.
static double DEFAULT_ERROR_DELTA
          Default precision delta to compute nearly-identity matrices or other error-based calculations.
static int DEFAULT_ROWS
          Default dimension of Y of matrix is 4.
protected  int iCols
          Actual number of columns in the matrix.
protected  int iRows
          Actual number of rows in the matrix.
 
Constructor Summary
Matrix()
          Default constructor.
Matrix(double[] pad1DMatrix)
          This constructor makes up a vector.
Matrix(double[][] padd2DMatrix)
          Constructs a 2D matrix from a 2D array.
Matrix(double[] pad1DMatrix, boolean pbTransposed)
          This constructor makes up a transposed vector.
Matrix(int piRows, int piCols)
          Constructor with custom dimensions.
Matrix(int piRows, int piCols, double pdFillValue)
          Constructor with custom dimensions and initial fill value.
Matrix(Matrix poMatrix)
          A-la copy-constructor.
 
Method Summary
 Matrix add(double pdNum)
          Adds a scalar to the matrix: this = this + N.
static Matrix add(Matrix poLHSMatrix, double pdNum)
          Adds a scalar to the matrix: M1 = M + N.
static Matrix add(Matrix poLHSMatrix, Matrix poRHSMatrix)
          M3 = M1 + M2.
protected  Matrix applyAdd(Matrix poLHSMatrix, Matrix poRHSMatrix, int i, int j)
          Actually applies the addition of operation to two elements of a matrix.
protected  Matrix applyMinus(Matrix poLHSMatrix, Matrix poRHSMatrix, int i, int j)
           
protected  Matrix applyMultiply(Matrix poLHSMatrix, Matrix poRHSMatrix)
           
protected  Matrix applyMultiply(Matrix poLHSMatrix, Matrix poRHSMatrix, int i, int j)
           
 java.lang.Object clone()
          Implements Clonable interface.
static Matrix crop(double[] padMatrixToCrop, int piRows, int piCols, int piLeft, int piTop, int piRight, int piBottom)
           
 boolean crop(int piLeft, int piTop, int piRight, int piBottom)
          A general routine that allows arbitrary cropping of a matrix.
 boolean cutColumn(int piColNum)
          Shrinks a matrix by removing a specified column from it.
 boolean cutFirstColumn()
           
 boolean cutFirstRow()
           
 boolean cutLastColumn()
           
 boolean cutLastRow()
           
 boolean cutRow(int piRowNum)
          Cuts a specified row away from the matrix.
 void display()
          Outputs matrix in text format to STDOUT.
 Matrix divide(double pdNum)
          this = this / d.
static Matrix divide(Matrix poMatrix, double pdNum)
          M = M / d.
static Matrix divide(Matrix poLHSMatrix, Matrix poRHSMatrix)
           
 boolean equals(Matrix poMatrix)
          this == M.
static boolean equals(Matrix poLHSMatrix, Matrix poRHSMatrix)
          M1 == M2.
 boolean equals(java.lang.Object poMatrix)
           
 void exhaustMatrix()
          "Destroys" the internal array matrix by setting it to null.
static Matrix extend(double[] padMatrixToExtend, int piMatrixToExtendRows, int piMatrixToExtendCols, double[] padExtensionMatrix, int piExtensionMatrixRows, int piExtensionMatrixCols, Matrix.Direction poDirection)
          Refactors matrix array extension to operate on raw arrays.
 boolean extend(Matrix poExtensionMatrix)
          Extends this matrix by another (by gluing two matrices together) assuming the extension direction of Direction.EAST.
 boolean extend(Matrix poExtensionMatrix, Matrix.Direction poDirection)
          Extends this matrix by another (by gluing two matrices together) given the extension direction.
 int getCols()
          Retrieves number of the columns in this matrix.
 Vector getColumn(int piColNum)
           
 double getDeterminant()
          Calculates determinant of this matrix using Laplace's formula.
 double getElement(int piRow, int piCol)
          Retrieves matrix element's value given row and column.
 int getElements()
          Returns number of the elements of the matrix.
static java.lang.String getMARFSourceCodeRevision()
          Retrieves class' revision.
 double[][] getMatrix2D()
          Returns internal matrix representation as 2-dimensional array of doubles.
 double[] getMatrixArray()
          Allows getting internal array representing the matrix data.
protected  Matrix getNewMatrix()
           
protected  Matrix getNewMatrix(int piRows, int piCols)
           
 Vector getRow(int piRowNum)
           
 int getRows()
          Retrieves number of the rows in this matrix.
 boolean inverse()
          Matrix inversion.
 boolean isIdentity()
          Checks for strict identity matrix.
 boolean isNearlyIdentity()
          Tests nearly-identity matrices with the default delta.
 boolean isNearlyIdentity(double pdDelta)
          Tests nearly-identity matrices with the specified delta.
 boolean isReduced()
          Allows examine if this matrix was row-reduced already.
 void loadColumn(int piColNum, Vector poVector)
          Allows loading a row of a matrix with values from a vector.
 void loadRow(int piRowNum, Vector poVector)
          Allows loading a row of a matrix with values from a vector.
 boolean makeIdentity()
          Makes current matrix an identity one.
 Matrix minus(double pdNum)
          Subtracts a scalar from the matrix's each element: this = this - N.
 Matrix minus(Matrix poMatrix)
          this = this - M.
static Matrix minus(Matrix poLHSMatrix, double pdNum)
          Subtracts a scalar from the matrix's each element: M1 = M - N.
static Matrix minus(Matrix poLHSMatrix, Matrix poRHSMatrix)
          M3 = M1 - M2.
static Matrix minusUnary(Matrix poMatrix)
          M1 = -M.
 Matrix multiply(double pdNum)
          this = this * d.
static Matrix multiply(double pdNum, Matrix poMatrix)
          M1 = d * M.
 Matrix multiply(Matrix poMatrix)
          M1 = this * M.
static Matrix multiply(Matrix poMatrix, double pdNum)
          M1 = M * d.
static Matrix multiply(Matrix poLHSMatrix, Matrix poRHSMatrix)
          M3 = M1 * M2.
static Vector multiply(Matrix poMatrix, Vector poVector)
          V2 = M * V1.
 Vector multiply(Vector poVector)
          V1 = this * V.
 Matrix pow(int piPow)
           
static Matrix pow(Matrix poMatrix, int piPow)
           
 Vector rotate(Vector poPointToRotate, double[] padRotateFactors)
          Rotates a vector according to the given axis' factor and angle's degree.
 Vector rotate(Vector poPointToRotate, double pdRotateX, double pdRotateY, double pdRotateZ, double pdRotateAngle)
          Rotates a vector according to the given axis' factor and angle's degree.
 Vector rotate(Vector poPointToRotate, Vector poRotateFactors)
          Rotates a vector according to the given axis' factor and angle's degree.
 boolean rowOperation(double pdA, int piRc)
          Performs a '+' linear row operation given the A and Rc parameters.
 boolean rowOperation(double pdA, int piRc, char pcOp, double pdB, int piRp)
          Performs a specified linear row operation given the parameters.
 boolean rowReduce()
          Applies row-reduce operation in this matrix.
 Vector scale(Vector poPointToScale, double[] padScaleFactors)
          Returns a scaled vector.
 Vector scale(Vector poPointToScale, double pdScaleX, double pdScaleY, double pdScaleZ)
          Returns a scaled vector.
 Vector scale(Vector poPointToScale, Vector poScaleFactors)
          Returns a scaled vector.
 void setAll()
          Sets all elements of the matrix to a default of 0.0.
 void setAll(double pdFillValue)
          Sets all elements of the matrix to the specified value.
 void setAllRandom()
          Sets all elements of the matrix at pseudo-random order.
 void setCols(int piCols)
          Allows setting number of columns of the matrix.
 void setElement(int piRow, int piCol, double pdValue)
          Sets matrix element's value at specified position.
 void setMatrix2D(double[][] padd2DMatrix)
          Sets internal array based on 2-dimensional parameter.
 void setMatrixArray(double[] padNewMatrix)
          Allows setting the new internal array of matrix data from the parameter.
 void setRows(int piRows)
          Allows setting number of rows of the matrix.
 Vector shear(Vector poPointToShear, double[] padShearFactors)
          Returns a sheared vector.
 Vector shear(Vector poPointToShear, double pdShearX, double pdShearY, double pdShearZ)
          Returns a sheared vector.
 Vector shear(Vector poPointToShear, Vector poShearFactors)
          Returns a sheared vector.
 int size()
          Analogous to getElements().
 java.lang.String toString()
          Textual representation of the matrix.
 Vector translate(Vector poPointToTranslate, double[] padTranslateVals)
          Translates a vector according to the given size.
 Vector translate(Vector poPointToTranslate, double pdTranslateX, double pdTranslateY, double pdTranslateZ)
          Translates a vector according to the given size.
 Vector translate(Vector poPointToTranslate, Vector poTranslateVals)
          Translates a vector according to the given size.
 boolean transpose()
          Matrix transpose.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_ROWS

public static final int DEFAULT_ROWS
Default dimension of Y of matrix is 4.

See Also:
Constant Field Values

DEFAULT_COLS

public static final int DEFAULT_COLS
Default dimension of X of matrix is 4.

See Also:
Constant Field Values

DEFAULT_ERROR_DELTA

public static final double DEFAULT_ERROR_DELTA
Default precision delta to compute nearly-identity matrices or other error-based calculations.

Since:
0.3.0.3
See Also:
Constant Field Values

iRows

protected int iRows
Actual number of rows in the matrix.


iCols

protected int iCols
Actual number of columns in the matrix.


adMatrix

protected double[] adMatrix
Matrix itself.

Constructor Detail

Matrix

public Matrix()
Default constructor. Equivalent to Matrix(Matrix.DEFAULT_ROWS, Matrix.DEFAULT_COLS).

See Also:
Matrix(int, int)

Matrix

public Matrix(int piRows,
              int piCols)
Constructor with custom dimensions. Equivalent to Matrix(piRows, piCols, 0.0).

Parameters:
piRows - custom # of rows.
piCols - custom # of columns.
See Also:
Matrix(int, int, double)

Matrix

public Matrix(int piRows,
              int piCols,
              double pdFillValue)
Constructor with custom dimensions and initial fill value.

Parameters:
piRows - custom # of rows.
piCols - custom # of columns.
pdFillValue - initial value of all the elements of the matrix.

Matrix

public Matrix(Matrix poMatrix)
A-la copy-constructor.

Parameters:
poMatrix - Matrix object to copy data members off from

Matrix

public Matrix(double[] pad1DMatrix)
This constructor makes up a vector. Equivalent to Matrix(pad1DMatrix, false).

Parameters:
pad1DMatrix - vector's elements
See Also:
Matrix(double[], boolean)

Matrix

public Matrix(double[] pad1DMatrix,
              boolean pbTransposed)
This constructor makes up a transposed vector.

Parameters:
pad1DMatrix - vector's elements
pbTransposed - true if transposed, false otherwise

Matrix

public Matrix(double[][] padd2DMatrix)
Constructs a 2D matrix from a 2D array. Internally calls setMatrix2D().

Parameters:
padd2DMatrix - initial array elements
See Also:
setMatrix2D(double[][])
Method Detail

exhaustMatrix

public void exhaustMatrix()
"Destroys" the internal array matrix by setting it to null. Also, the garbage collector is hinted to collect as soon as it can with System.gc(). If called very often, may actually slowdown the system during the garbage collection runs. The cardinality of the matrix is not affected and a new instance of it is not created; use setMatrixArray() to set the new matrix data.

See Also:
setMatrixArray(double[]), setMatrix2D(double[][]), System.gc()

getRows

public final int getRows()
Retrieves number of the rows in this matrix.

Returns:
number of rows

getCols

public final int getCols()
Retrieves number of the columns in this matrix.

Returns:
number of columns

setRows

public void setRows(int piRows)
Allows setting number of rows of the matrix.

Parameters:
piRows - new number of rows

setCols

public void setCols(int piCols)
Allows setting number of columns of the matrix.

Parameters:
piCols - new number of cloumns

getMatrixArray

public final double[] getMatrixArray()
Allows getting internal array representing the matrix data.

Returns:
inner array of doubles

setMatrixArray

public void setMatrixArray(double[] padNewMatrix)
Allows setting the new internal array of matrix data from the parameter. The cardinality is kept before the setting as no assumptions is made about the new data. The array is copied entirely into internal storage.

Parameters:
padNewMatrix - new matrix data
Throws:
java.lang.NullPointerException - if the parameter is null

setAll

public void setAll()
Sets all elements of the matrix to a default of 0.0.


setAll

public void setAll(double pdFillValue)
Sets all elements of the matrix to the specified value.

Parameters:
pdFillValue - the value to fill the matrix with.

setAllRandom

public void setAllRandom()
Sets all elements of the matrix at pseudo-random order. Used primarily for testing. The range of the values is [- Double.MAX_VALUE / 2, Double.MAX_VALUE / 2].

Since:
0.3.0.3
See Also:
Double.MAX_VALUE

getElements

public final int getElements()
Returns number of the elements of the matrix.

Returns:
element count

size

public final int size()
Analogous to getElements().

Returns:
element count
Since:
0.3.0.1
See Also:
getElements()

getElement

public final double getElement(int piRow,
                               int piCol)
Retrieves matrix element's value given row and column.

Parameters:
piRow - row index of the element
piCol - column index of the element
Returns:
element's value
Throws:
java.lang.ArrayIndexOutOfBoundsException - if at least one of the indices is out of range

setElement

public void setElement(int piRow,
                       int piCol,
                       double pdValue)
Sets matrix element's value at specified position.

Parameters:
piRow - row index of the element to set
piCol - column index of the element to set
pdValue - the value of the element
Throws:
java.lang.ArrayIndexOutOfBoundsException - if at least one of the indices is out of range

loadRow

public void loadRow(int piRowNum,
                    Vector poVector)
Allows loading a row of a matrix with values from a vector.

Parameters:
piRowNum - index of the row to load
poVector - the values to take
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the row number is out of range or there are insufficient number of elements in the vector

getRow

public Vector getRow(int piRowNum)
Parameters:
piRowNum -
Returns:
Since:
0.3.0.6

loadColumn

public void loadColumn(int piColNum,
                       Vector poVector)
Allows loading a row of a matrix with values from a vector.

Parameters:
piColNum - index of the column to load
poVector - the values to take
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the column number is out of range or there are insufficient number of elements in the vector
Since:
0.3.0.6

getColumn

public Vector getColumn(int piColNum)
Parameters:
piColNum -
Returns:
Since:
0.3.0.6

getDeterminant

public final double getDeterminant()
Calculates determinant of this matrix using Laplace's formula. Also, det(0) = 0, i.e. a square matrix of 0x0 has a determinant of zero. See this for details.

Returns:
the determinant value

rowOperation

public boolean rowOperation(double pdA,
                            int piRc)
Performs a '+' linear row operation given the A and Rc parameters.

Parameters:
pdA - A
piRc - Rc
Returns:
true if the operation was successful

rowOperation

public boolean rowOperation(double pdA,
                            int piRc,
                            char pcOp,
                            double pdB,
                            int piRp)
Performs a specified linear row operation given the parameters.

Parameters:
pdA - A
piRc - Rc
pcOp - operation ('+' or '-')
pdB - B
piRp - Rb
Returns:
true if the operation was successful

rowReduce

public boolean rowReduce()
Applies row-reduce operation in this matrix.

Returns:
true if the operation was successful

isReduced

public boolean isReduced()
Allows examine if this matrix was row-reduced already.

Returns:
true if the matrix if row-reduced
See Also:
rowReduce()

extend

public boolean extend(Matrix poExtensionMatrix)
Extends this matrix by another (by gluing two matrices together) assuming the extension direction of Direction.EAST. NOTICE, if doubling the same this matrix, make a copy for the argument instead.

Parameters:
poExtensionMatrix - the matrix to extend the current by
Returns:
true if the operation was successful
See Also:
Matrix.Direction.EAST

extend

public boolean extend(Matrix poExtensionMatrix,
                      Matrix.Direction poDirection)
Extends this matrix by another (by gluing two matrices together) given the extension direction. NOTICE, if doubling the same matrix, make a copy for the argument instead.

Parameters:
poExtensionMatrix - the matrix to extend the current by
poDirection - in which direction the extension should happen
Returns:
true if the operation was successful
See Also:
Matrix.Direction

extend

public static Matrix extend(double[] padMatrixToExtend,
                            int piMatrixToExtendRows,
                            int piMatrixToExtendCols,
                            double[] padExtensionMatrix,
                            int piExtensionMatrixRows,
                            int piExtensionMatrixCols,
                            Matrix.Direction poDirection)
Refactors matrix array extension to operate on raw arrays.

Parameters:
padMatrixToExtend -
piMatrixToExtendRows -
piMatrixToExtendCols -
padExtensionMatrix -
piExtensionMatrixRows -
piExtensionMatrixCols -
poDirection -
Returns:
Since:
0.3.0.6

crop

public boolean crop(int piLeft,
                    int piTop,
                    int piRight,
                    int piBottom)
A general routine that allows arbitrary cropping of a matrix. The cropping rectangle specified by the parameters is (left, top) - (right, bottom) -- anything inside is kept including the borders, all of the outside is thrown out.

Parameters:
piLeft - left index border to crop after
piTop - top index border to crop after
piRight - right index border to crop after
piBottom - bottom index border to crop after
Returns:
true if the cropping was successful

crop

public static Matrix crop(double[] padMatrixToCrop,
                          int piRows,
                          int piCols,
                          int piLeft,
                          int piTop,
                          int piRight,
                          int piBottom)
Parameters:
padMatrixToCrop -
piRows -
piCols -
piLeft -
piTop -
piRight -
piBottom -
Returns:
Since:
0.3.0.6

cutRow

public boolean cutRow(int piRowNum)
Cuts a specified row away from the matrix.

Parameters:
piRowNum - row to remove
Returns:
true if cutting was successful

cutLastRow

public boolean cutLastRow()
Returns:
Since:
0.3.0.6

cutFirstRow

public boolean cutFirstRow()
Returns:
Since:
0.3.0.6

cutColumn

public boolean cutColumn(int piColNum)
Shrinks a matrix by removing a specified column from it.

Parameters:
piColNum - a valid index of the column to be removed.
Returns:
true if the column was actually removed; false otherwise

cutLastColumn

public boolean cutLastColumn()
Returns:
Since:
0.3.0.6

cutFirstColumn

public boolean cutFirstColumn()
Returns:
Since:
0.3.0.6

display

public void display()
Outputs matrix in text format to STDOUT.


toString

public java.lang.String toString()
Textual representation of the matrix.

Overrides:
toString in class java.lang.Object
Returns:
String representation

getNewMatrix

protected Matrix getNewMatrix()
Returns:

getNewMatrix

protected Matrix getNewMatrix(int piRows,
                              int piCols)
Parameters:
piRows -
piCols -
Returns:

inverse

public boolean inverse()
Matrix inversion.

Returns:
true if matrix was possible to invert, false otherwise

transpose

public boolean transpose()
Matrix transpose.

Returns:
true if matrix was transposed, false otherwise

makeIdentity

public boolean makeIdentity()
Makes current matrix an identity one.

Returns:
true if the operation completed successfully

isIdentity

public final boolean isIdentity()
Checks for strict identity matrix. Any deviations due to errors in floating point arithmetic will return false. If imprecise values are allowed, consider using isNearlyIdentity().

Returns:
true if the matrix is strictly identity
See Also:
isNearlyIdentity(), isNearlyIdentity(double)

isNearlyIdentity

public final boolean isNearlyIdentity(double pdDelta)
Tests nearly-identity matrices with the specified delta.

Parameters:
pdDelta - the FP error to assume when checking for identity
Returns:
true if the matrix is nearly identity

isNearlyIdentity

public final boolean isNearlyIdentity()
Tests nearly-identity matrices with the default delta.

Returns:
true if the matrix is nearly identity
See Also:
DEFAULT_ERROR_DELTA

add

public static Matrix add(Matrix poLHSMatrix,
                         Matrix poRHSMatrix)
M3 = M1 + M2.

Parameters:
poLHSMatrix - M1
poRHSMatrix - M2
Returns:
M3; if cardinalities of M1 and M2 do not match; M1 is returned

applyAdd

protected Matrix applyAdd(Matrix poLHSMatrix,
                          Matrix poRHSMatrix,
                          int i,
                          int j)
Actually applies the addition of operation to two elements of a matrix. Designed to be overridden for complex or otherwise matrices.

Parameters:
poLHSMatrix -
poRHSMatrix -
i -
j -

add

public Matrix add(double pdNum)
Adds a scalar to the matrix: this = this + N.

Parameters:
pdNum - the scalar N
Returns:
this
Since:
0.3.0.6

add

public static Matrix add(Matrix poLHSMatrix,
                         double pdNum)
Adds a scalar to the matrix: M1 = M + N.

Parameters:
poLHSMatrix - M
pdNum - the scalar N
Returns:
M1
Since:
0.3.0.6

minus

public static Matrix minus(Matrix poLHSMatrix,
                           Matrix poRHSMatrix)
M3 = M1 - M2.

Parameters:
poLHSMatrix - M1
poRHSMatrix - M2
Returns:
M3

applyMinus

protected Matrix applyMinus(Matrix poLHSMatrix,
                            Matrix poRHSMatrix,
                            int i,
                            int j)
Parameters:
poLHSMatrix -
poRHSMatrix -
i -
j -

minusUnary

public static Matrix minusUnary(Matrix poMatrix)
M1 = -M.

Parameters:
poMatrix - M
Returns:
-M1

minus

public Matrix minus(Matrix poMatrix)
this = this - M.

Parameters:
poMatrix - M
Returns:
a copy of this matrix after subtraction

minus

public Matrix minus(double pdNum)
Subtracts a scalar from the matrix's each element: this = this - N.

Parameters:
pdNum - the scalar
Since:
0.3.0.6

minus

public static Matrix minus(Matrix poLHSMatrix,
                           double pdNum)
Subtracts a scalar from the matrix's each element: M1 = M - N.

Parameters:
pdNum - the scalar
Since:
0.3.0.6

multiply

public Matrix multiply(Matrix poMatrix)
M1 = this * M.

Parameters:
poMatrix - M
Returns:
M1

multiply

public static Matrix multiply(Matrix poLHSMatrix,
                              Matrix poRHSMatrix)
M3 = M1 * M2.

Parameters:
poLHSMatrix - M1
poRHSMatrix - M2
Returns:
M3; M3 = 0x0 if the columns of M1 != rows of M2

applyMultiply

protected Matrix applyMultiply(Matrix poLHSMatrix,
                               Matrix poRHSMatrix)

applyMultiply

protected Matrix applyMultiply(Matrix poLHSMatrix,
                               Matrix poRHSMatrix,
                               int i,
                               int j)
Parameters:
poLHSMatrix -
poRHSMatrix -
i -
j -

multiply

public static Vector multiply(Matrix poMatrix,
                              Vector poVector)
V2 = M * V1.

Parameters:
poMatrix - M
poVector - V1
Returns:
V2
Since:
0.3.0.3

multiply

public Vector multiply(Vector poVector)
V1 = this * V.

Parameters:
poVector - V
Returns:
V1
Since:
0.3.0.3

multiply

public static Matrix multiply(Matrix poMatrix,
                              double pdNum)
M1 = M * d.

Parameters:
poMatrix - M
pdNum - d
Returns:
M1

multiply

public Matrix multiply(double pdNum)
this = this * d.

Parameters:
pdNum - d
Returns:
this

multiply

public static Matrix multiply(double pdNum,
                              Matrix poMatrix)
M1 = d * M.

Parameters:
pdNum - d
poMatrix - M
Returns:
M1

divide

public static Matrix divide(Matrix poMatrix,
                            double pdNum)
M = M / d.

Parameters:
poMatrix - M
pdNum - d
Returns:
modified M

divide

public static Matrix divide(Matrix poLHSMatrix,
                            Matrix poRHSMatrix)
Parameters:
poLHSMatrix -
poRHSMatrix -
Returns:
Since:
0.3.0.6

divide

public Matrix divide(double pdNum)
this = this / d.

Parameters:
pdNum - d
Since:
0.3.0.3

pow

public Matrix pow(int piPow)
Parameters:
piPow -
Returns:
Since:
0.3.0.6

pow

public static Matrix pow(Matrix poMatrix,
                         int piPow)
Parameters:
poMatrix -
piPow -
Returns:
Since:
0.3.0.6

equals

public boolean equals(Matrix poMatrix)
this == M.

Parameters:
poMatrix - M
Returns:
true if this and parameter matrices are equal

equals

public static boolean equals(Matrix poLHSMatrix,
                             Matrix poRHSMatrix)
M1 == M2. The equality of two matrices determined by the equality of their dimensions and the contents.

Parameters:
poLHSMatrix - M1
poRHSMatrix - M2
Returns:
true of the matrices are equal

equals

public boolean equals(java.lang.Object poMatrix)
Overrides:
equals in class java.lang.Object
See Also:
Object.equals(java.lang.Object)

getMatrix2D

public double[][] getMatrix2D()
Returns internal matrix representation as 2-dimensional array of doubles.

Returns:
2-dimensional array of doubles

setMatrix2D

public void setMatrix2D(double[][] padd2DMatrix)
Sets internal array based on 2-dimensional parameter. Works under assumption that all rows are of the same length.

Parameters:
padd2DMatrix - the two dimensional array of doubles to convert from

clone

public java.lang.Object clone()
Implements Clonable interface. Creates a deep copy of the object by cloning the internal matrix array.

Overrides:
clone in class java.lang.Object
Returns:
object copy of this matrix
See Also:
Object.clone()

scale

public Vector scale(Vector poPointToScale,
                    Vector poScaleFactors)
Returns a scaled vector.

Parameters:
poPointToScale - the vector of objects to be scaled.
poScaleFactors - the vector of objects containing the vector's scaling factors
Returns:
a scaled vector
Throws:
java.lang.IllegalArgumentException - if the sizes of the two vectors are different
Since:
0.3.0.3

scale

public Vector scale(Vector poPointToScale,
                    double[] padScaleFactors)
Returns a scaled vector.

Parameters:
poPointToScale - the vector of objects to be scaled.
padScaleFactors - the array of doubles containing the vector's scaling factors
Returns:
a scaled vector
Throws:
java.lang.IllegalArgumentException - if the sizes of the array and the vector are different
Since:
0.3.0.3

scale

public Vector scale(Vector poPointToScale,
                    double pdScaleX,
                    double pdScaleY,
                    double pdScaleZ)
Returns a scaled vector.

Parameters:
poPointToScale - the vector of objects to be scaled.
pdScaleX - the X axis scaled factor of double
pdScaleY - the Y axis scaled factor of double
pdScaleZ - the Z axis scaled factor of double
Returns:
a scaled vector
Since:
0.3.0.3

translate

public Vector translate(Vector poPointToTranslate,
                        Vector poTranslateVals)
Translates a vector according to the given size.

Parameters:
poPointToTranslate - the vector of objects to be translated.
poTranslateVals - the vector of objects that contains the vector's translating values
Returns:
a translated Vector
Throws:
java.lang.IllegalArgumentException - if the sizes of the array and the vector are different
Since:
0.3.0.3

translate

public Vector translate(Vector poPointToTranslate,
                        double[] padTranslateVals)
Translates a vector according to the given size.

Parameters:
poPointToTranslate - the vector of objects to be translated.
padTranslateVals - the Array of doubles that contains the vector's translating values
Returns:
a translated Vector
Throws:
java.lang.IllegalArgumentException - if the sizes of the array and the vector are different
Since:
0.3.0.3

translate

public Vector translate(Vector poPointToTranslate,
                        double pdTranslateX,
                        double pdTranslateY,
                        double pdTranslateZ)
Translates a vector according to the given size.

Parameters:
poPointToTranslate - the vector of objects to be translated.
pdTranslateX - the X axis translated factor of double
pdTranslateY - the Y axis translated factor of double
pdTranslateZ - the Z axis translated factor of double
Returns:
a translated Vector
Throws:
java.lang.IllegalArgumentException - if the sizes of the vector is not one bigger than the number of scaled factors
Since:
0.3.0.3

rotate

public Vector rotate(Vector poPointToRotate,
                     Vector poRotateFactors)
Rotates a vector according to the given axis' factor and angle's degree.

Parameters:
poPointToRotate - the vector of objects to be rotated
poRotateFactors - the vector of objects that contains the vector's rotating factors
Returns:
a rotated Vector
Throws:
java.lang.IllegalArgumentException - if the sizes of two vectors are different
Since:
0.3.0.3

rotate

public Vector rotate(Vector poPointToRotate,
                     double[] padRotateFactors)
Rotates a vector according to the given axis' factor and angle's degree.

Parameters:
poPointToRotate - the vector of objects to be rotated.
padRotateFactors - the Array of doubles that contains the vector's rotating values
Returns:
a rotated Vector
Throws:
java.lang.IllegalArgumentException - if the sizes of the array and the vector are different
Since:
0.3.0.3

rotate

public Vector rotate(Vector poPointToRotate,
                     double pdRotateX,
                     double pdRotateY,
                     double pdRotateZ,
                     double pdRotateAngle)
Rotates a vector according to the given axis' factor and angle's degree.

Parameters:
poPointToRotate - the vector of objects to be rotated.
pdRotateX - the X axis rotated factor of double
pdRotateY - the Y axis rotated factor of double
pdRotateZ - the Z axis rotated factor of double
pdRotateAngle - the rotate angle of degree around one axis
Returns:
a rotated Vector
Throws:
java.lang.IllegalArgumentException - if the sizes of the vector is not one bigger than the number of rotated factors
Since:
0.3.0.3

shear

public Vector shear(Vector poPointToShear,
                    Vector poShearFactors)
Returns a sheared vector.

Parameters:
poPointToShear - the vector of objects to be sheared.
poShearFactors - the vector of objects containing the vector's shearing factors
Returns:
a sheared vector
Throws:
java.lang.IllegalArgumentException - if the sizes of the two vectors are different
Since:
0.3.0.3

shear

public Vector shear(Vector poPointToShear,
                    double[] padShearFactors)
Returns a sheared vector.

Parameters:
poPointToShear - the vector of objects to be sheared
padShearFactors - the array of doubles containing the vector's shearing factors
Returns:
a sheared vector
Throws:
java.lang.IllegalArgumentException - if the sizes of the array and the vector are different
Since:
0.3.0.3

shear

public Vector shear(Vector poPointToShear,
                    double pdShearX,
                    double pdShearY,
                    double pdShearZ)
Returns a sheared vector.

Parameters:
poPointToShear - the vector of objects to be sheared
pdShearX - the X axis sheared factor of double
pdShearY - the Y axis sheared factor of double
pdShearZ - the Z axis sheared factor of double
Returns:
a sheared vector
Since:
0.3.0.3

getMARFSourceCodeRevision

public static java.lang.String getMARFSourceCodeRevision()
Retrieves class' revision.

Returns:
revision string
Since:
0.3.0.2


SourceForge Logo