|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.charvolant.matrix.Matrix
Generalised nxm matrix class.
The Matrix class provides a generalised 2-dimensional matrix package. Matrices are treated as values wherever possible, so matrix operations such as multiplication produce a new matrix as the result, rather than operate directly on the matrix.
This package is optimised towards the 4x4 transformation matrices which can be used for 3D projections. There are a number of class methods for generating transformation matrices.
| Field Summary | |
static double |
ISOMETRIC
Isometric factor. |
protected double[][] |
matrix
|
static int |
N
Normalisation. |
static int |
TD
Transformation size. |
static int |
X
X-axis. |
static int |
Y
Y-axis. |
static int |
Z
Z-axis. |
| Constructor Summary | |
Matrix(double[] init)
Initialised matrix. |
|
Matrix(double[][] init)
Initialised matrix. |
|
Matrix(int rows,
int cols)
Unit matrix. |
|
Matrix(Matrix copy)
Copied matrix. |
|
| Method Summary | |
Matrix |
add(double arg)
Constant addition. |
Matrix |
add(Matrix arg)
Matrix addition. |
double |
at(int i,
int j)
Get a matrix element. |
static Matrix |
cabinet(double angle)
Cabinet projection. |
static Matrix |
cavalier(double angle)
Cavalier projection. |
java.lang.Object |
clone()
Create a copy of this matrix. |
java.lang.Object |
clone(int rows,
int cols)
Create a resized copy. |
boolean |
equals(java.lang.Object obj)
Equality test. |
int |
getCols()
Matrix columns. |
int |
getRank()
The rank of the matrix. |
int |
getRows()
Matrix rows. |
int |
hashCode()
Hash code. |
Matrix |
inverted()
Matrix inversion. |
static Matrix |
isometric()
Isometric matrix. |
Matrix |
multiply(double arg)
Constant multiplication. |
double[] |
multiply(double[] arg)
Matrix multiplication. |
Matrix |
multiply(Matrix arg)
Matrix multiplication. |
Matrix |
negated()
Matrix negation. |
static Matrix |
permuteXZY()
Permutation matrix. |
static Matrix |
permuteYXZ()
Permutation matrix. |
static Matrix |
permuteYZX()
Permutation matrix. |
static Matrix |
permuteZXY()
Permutation matrix. |
static Matrix |
permuteZYX()
Permutation matrix. |
static Matrix |
perspective(double vz)
Perspective matrix. |
void |
put(int i,
int j,
double val)
Set at matrix element. |
static Matrix |
reflectX()
Reflection matrix. |
static Matrix |
reflectY()
Reflection matrix. |
static Matrix |
reflectZ()
Reflection matrix. |
static Matrix |
rotateX(double angle)
Rotation matrix. |
static Matrix |
rotateY(double angle)
Rotation matrix. |
static Matrix |
rotateZ(double angle)
Rotation matrix. |
static Matrix |
scaling(double sx,
double sy,
double sz)
Scaling transformation matrix. |
protected double[] |
specialMultiply(double[] arg)
Arithmetic. |
Matrix |
subtract(double arg)
Constant subtraction. |
Matrix |
subtract(Matrix arg)
Matrix subtraction. |
java.lang.String |
toString()
String representation. |
double |
trace()
Matrix trace. |
static Matrix |
transformation()
Unit transformation matrix. |
static Matrix |
translate(double tx,
double ty,
double tz)
Translation matrix. |
Matrix |
transposed()
Matrix tranposition. |
| Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
protected double[][] matrix
public static final int X
public static final int Y
public static final int Z
public static final int N
public static final int TD
public static final double ISOMETRIC
| Constructor Detail |
public Matrix(int rows,
int cols)
Unit matrix of size rows x cols.
rows - Number of rows in matrix.cols - Number of columns in matrix.public Matrix(double[][] init)
Make a matrix from the 2D array init.
init - An array of arrays containing the initial data.
MatrixDimensionException - if init contains rows of differing length.public Matrix(double[] init)
Make a vector matrix from the 1D array init.
init - Array to initialize the matrix.public Matrix(Matrix copy)
copy - The matrix to copy from.| Method Detail |
public static Matrix transformation()
public static Matrix scaling(double sx,
double sy,
double sz)
sx - Scaling factor for X axis.sy - Scaling factor for Y axis.sz - Scaling factor for Z axis.
public static Matrix rotateX(double angle)
angle - Number of radians to rotate about the axis.
public static Matrix rotateY(double angle)
angle - Number of radians to rotate about the axis.
public static Matrix rotateZ(double angle)
angle - Number of radians to rotate about the axis.
public static Matrix translate(double tx,
double ty,
double tz)
tx - Amount to translate a point along the X axis by.ty - Amount to translate a point along the Y axis by.tz - Amount to translate a point along the Z axis by.
public static Matrix reflectX()
public static Matrix reflectY()
public static Matrix reflectZ()
public static Matrix permuteYZX()
public static Matrix permuteZXY()
public static Matrix permuteYXZ()
public static Matrix permuteXZY()
public static Matrix permuteZYX()
public static Matrix isometric()
public static Matrix cavalier(double angle)
angle - Angle of rotation in radians
public static Matrix cabinet(double angle)
angle - Angle of rotation in radians
public static Matrix perspective(double vz)
vz - Z coordinate of vanishing point.
public int getRank()
The rank of the matrix is the number of dimensions it has.
public int getRows()
public int getCols()
public double at(int i,
int j)
i - Row number of element.j - Column number of element.
public void put(int i,
int j,
double val)
i - Row number of element.j - Column number of element.val - Value to set (i, j) to.public java.lang.Object clone()
public java.lang.Object clone(int rows,
int cols)
Clone this matrix with a new size of rows x cols. As much of the matrix that can be copied will be copied, with excess parts being discarded, and remaining parts of the copy filled with a unit matrix.
rows - New number of rows.cols - New number of columns.
public boolean equals(java.lang.Object obj)
Two matrices are equal if they have the same size and equal elements.
obj - Object to test matrix against.
public int hashCode()
Hash value for insertion into hash tables. The hash is based on the trace of the matrix.
public double trace()
The trace of a matrix is the sum of the elements along it's major diagonal: M.trace() = Sumi=0n Mii.
public Matrix add(Matrix arg)
Add two matrices together using the rules of matrix arithmetic: M.add(N)ij = Mij + Nij.
arg - Matrix to add to this matrix.
MatrixDimensionException - if the two matrices do not have the same size.public Matrix add(double arg)
Add arg to each element of the main diagonal. Similar to adding a diagonal matrix of arg.
arg - The value to add to this matrix.
add(Matrix)public Matrix subtract(Matrix arg)
Subtract two matrices using the rules of matrix arithmetic: M.subtract(N)ij = Mij - Nij.
arg - Matrix to subtract from this matrix.
MatrixDimensionException - if the two matrices do not have the same size.public Matrix subtract(double arg)
Subtract arg from each element of the main diagonal. Similar to subtracting a diagonal matrix of arg.
arg - The value to subtract from this matrix.
subtract(Matrix)public Matrix multiply(Matrix arg)
Multiply this matrix by arg using the rules of matrix arithmetic: M.multiply(N)ij = Sumk = 0n Mik * Nkj.
arg - The matrix to multiply this matrix by.
MatrixDimensionException - if arg does not have the same number of rows as this matrix has columns.public double[] multiply(double[] arg)
Multiply this matrix by arg using the rules of matrix arithmetic. arg is treated as a n x 1 vector for this purpose.
arg - The matrix to multiply this matrix by.
MatrixDimensionException - if arg does not have the same number of rows as this matrix has columns.multiply(Matrix)protected double[] specialMultiply(double[] arg)
multiply(double[])public Matrix multiply(double arg)
Multiply a matrix by a scalar: M.multiply(a)ij = Mij * a.
arg - The scalar to multiply by.
multiply(Matrix)public Matrix transposed()
Transpose a matrix: M.transposed()ij = Mji
public Matrix negated()
Negate a matrix: M.negated()ij = -Mij.
public Matrix inverted()
Invert a square matrix: M * M.inverted() = I.
MatrixDimensionException - if the matrix is not a sqaure matrix.
MatrixSingularException - if the matrix cannot be inverted (is singular).public java.lang.String toString()
Converts the matrix into a string of form [[m00, ..., m0c], ..., [mr0, ..., mcc]]
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||