|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--marf.math.Matrix
Algebraic operations on matrices. Adapted from my graphics project written in C++.
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.
$Id: Matrix.java,v 1.20 2005/06/01 01:57:16 mokhov Exp $
Nested Class Summary | |
protected 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 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(marf.math.Matrix poMatrix)
A-la copy-constructor. |
Method Summary | |
static marf.math.Matrix |
add(marf.math.Matrix poLHSMatrix,
marf.math.Matrix poRHSMatrix)
M3 = M1 + M2. |
java.lang.Object |
clone()
Implements Clonable interface. |
boolean |
crop(int piLeft,
int piTop,
int piRight,
int piBottom)
|
boolean |
cutColumn(int piColNum)
Shrinks a matrix by removing a specified colum from it. |
boolean |
cutRow(int piRowNum)
|
void |
display()
Outputs matrix in text format to STDOUT. |
static void |
divide(marf.math.Matrix poMatrix,
double pdNum)
M = M / d. |
boolean |
equals(marf.math.Matrix poMatrix)
this == M. |
static boolean |
equals(marf.math.Matrix poLHSMatrix,
marf.math.Matrix poRHSMatrix)
M1 == M2. |
void |
exhaustMatrix()
"Destroys" the internal array matrix by setting it to null . |
boolean |
extend(marf.math.Matrix poExtensionMatrix)
|
boolean |
extend(marf.math.Matrix poExtensionMatrix,
Matrix.Direction pDirection)
|
int |
getCols()
|
double |
getDeterminant()
Calculates determinant of this matrix. |
double |
getElement(int piRow,
int piCol)
|
int |
getElements()
Returns number of the elements of the matrix. |
double[][] |
getMatrix2D()
Returns internal matrix representation as 2-dimensional array of doubles. |
double[] |
getMatrixArray()
|
static java.lang.String |
getRevision()
Retrieves class' revision. |
int |
getRows()
|
boolean |
inverse()
Matrix inversion. |
boolean |
isIdentity()
Checks for strict identity matrix. |
boolean |
isNearlyIdentity()
|
boolean |
isNearlyIdentity(double pdDelta)
|
boolean |
isReduced()
|
void |
loadRow(int piRowNum,
marf.math.Vector poVector)
|
boolean |
makeIdentity()
Makes current matrix an identity one. |
marf.math.Matrix |
minus(marf.math.Matrix poMatrix)
this - M. |
static marf.math.Matrix |
minus(marf.math.Matrix poLHSMatrix,
marf.math.Matrix poRHSMatrix)
M3 = M1 - M2. |
static marf.math.Matrix |
minusUnary(marf.math.Matrix poMatrix)
M = -M. |
void |
multiply(double pdNum)
this = this * d. |
static void |
multiply(double pdNum,
marf.math.Matrix poMatrix)
M1 = d * M. |
marf.math.Matrix |
multiply(marf.math.Matrix poMatrix)
M1 = this * M. |
static void |
multiply(marf.math.Matrix poMatrix,
double pdNum)
M = M * d. |
static marf.math.Matrix |
multiply(marf.math.Matrix poLHSMatrix,
marf.math.Matrix poRHSMatrix)
M3 = M1 * M2. |
boolean |
rowOperation(double pdA,
int piRc)
|
boolean |
rowOperation(double piA,
int piRc,
char pcOp,
double piB,
int piRp)
|
boolean |
rowReduce()
|
void |
setAll()
Default of 0.0. |
void |
setAll(double pdFillValue)
Sets all elements of the matrix to the specified value. |
void |
setCols(int piCols)
|
void |
setElement(int piRow,
int piCol,
double pdValue)
|
void |
setMatrix2D(double[][] padd2DMatrix)
Sets internal array based on 2-dimensional parameter. |
void |
setMatrixArray(double[] padNewMatrix)
|
void |
setRows(int piRows)
|
int |
size()
Analoguous to getElements(). |
java.lang.String |
toString()
Textual representation of the matrix. |
boolean |
transpose()
Matrix transpose. |
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final int DEFAULT_ROWS
public static final int DEFAULT_COLS
protected int iRows
protected int iCols
protected double[] adMatrix
Constructor Detail |
public Matrix()
Matrix(Matrix.DEFAULT_ROWS, Matrix.DEFAULT_COLS)
.
public Matrix(int piRows, int piCols)
Matrix(piRows, piCols, 0.0)
.
piRows
- custom # of rows.piCols
- custom # of columns.public Matrix(int piRows, int piCols, double pdFillValue)
piRows
- custom # of rows.piCols
- custom # of columns.pdFillValue
- initial value of all the elements of the matrix.public Matrix(marf.math.Matrix poMatrix)
poMatrix
- Matrix object to copy data members off frompublic Matrix(double[] pad1DMatrix)
Matrix(pad1DMatrix, false)
.
pad1DMatrix
- vector's elementspublic Matrix(double[] pad1DMatrix, boolean pbTransposed)
pad1DMatrix
- vector's elementspbTransposed
- true if transposed, false otherwisepublic Matrix(double[][] padd2DMatrix)
padd2DMatrix
- initial array elementssetMatrix2D(double[][])
Method Detail |
public void exhaustMatrix()
null
.
Part of the leftover API from the C++ code.
public final int getRows()
public final int getCols()
public void setRows(int piRows)
public void setCols(int piCols)
public final double[] getMatrixArray()
public void setMatrixArray(double[] padNewMatrix)
public void setAll()
public void setAll(double pdFillValue)
public final int getElements()
public final int size()
public final double getElement(int piRow, int piCol)
java.lang.ArrayIndexOutOfBoundsException
public void setElement(int piRow, int piCol, double pdValue)
java.lang.ArrayIndexOutOfBoundsException
public void loadRow(int piRowNum, marf.math.Vector poVector)
public final double getDeterminant()
public boolean rowOperation(double pdA, int piRc)
public boolean rowOperation(double piA, int piRc, char pcOp, double piB, int piRp)
public boolean rowReduce()
public boolean isReduced()
public boolean extend(marf.math.Matrix poExtensionMatrix)
public boolean extend(marf.math.Matrix poExtensionMatrix, Matrix.Direction pDirection)
public boolean crop(int piLeft, int piTop, int piRight, int piBottom)
public boolean cutRow(int piRowNum)
public boolean cutColumn(int piColNum)
piColNum
- a valid index of the column to be removed.
true
if the column was actually removed; false
otherwisepublic void display()
public java.lang.String toString()
toString
in class java.lang.Object
public boolean inverse()
public boolean transpose()
public boolean makeIdentity()
public final boolean isIdentity()
public final boolean isNearlyIdentity(double pdDelta)
public final boolean isNearlyIdentity()
public static marf.math.Matrix add(marf.math.Matrix poLHSMatrix, marf.math.Matrix poRHSMatrix)
public static marf.math.Matrix minus(marf.math.Matrix poLHSMatrix, marf.math.Matrix poRHSMatrix)
public static marf.math.Matrix minusUnary(marf.math.Matrix poMatrix)
public marf.math.Matrix minus(marf.math.Matrix poMatrix)
public marf.math.Matrix multiply(marf.math.Matrix poMatrix)
public static marf.math.Matrix multiply(marf.math.Matrix poLHSMatrix, marf.math.Matrix poRHSMatrix)
public static void multiply(marf.math.Matrix poMatrix, double pdNum)
public void multiply(double pdNum)
public static void multiply(double pdNum, marf.math.Matrix poMatrix)
public static void divide(marf.math.Matrix poMatrix, double pdNum)
public boolean equals(marf.math.Matrix poMatrix)
public static boolean equals(marf.math.Matrix poLHSMatrix, marf.math.Matrix poRHSMatrix)
public double[][] getMatrix2D()
public void setMatrix2D(double[][] padd2DMatrix)
public java.lang.Object clone()
clone
in class java.lang.Object
public static java.lang.String getRevision()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |