Class Matrix

java.lang.Object
  |
  +--Matrix

public class Matrix
extends java.lang.Object

A class to represent a 4x4 transformational matrix


Field Summary
 double[][] m
          double m[4][4]
purpose : store the values of the matrix
 
Constructor Summary
Matrix()
          Default constructor
purpose : initialize the matrix to a zero matrix
Matrix(Matrix x)
          Copy constructor
purpose : initialize the matrix to the input Matrix x
 
Method Summary
static Matrix identity()
          purpose : create an identity matrix
static Matrix minus(Matrix a, Matrix b)
          purpose : subtract one matrix by another matrix
static Matrix multi(Matrix a, Matrix b)
          purpose : multiply two matrices
static Matrix plus(Matrix a, Matrix b)
          purpose : add two matrices
 void print()
          purpose : print the matrix
static Matrix rotate(char axis, double angle)
          purpose : create a rotational matrix
static Matrix scale(double sx, double sy, double sz)
          purpose : create a scale matrix
static Matrix translate(double tx, double ty, double tz)
          purpose : create a translational matrix
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m

public double[][] m
double m[4][4]
purpose : store the values of the matrix
Constructor Detail

Matrix

public Matrix()
Default constructor
purpose : initialize the matrix to a zero matrix

Matrix

public Matrix(Matrix x)
Copy constructor
purpose : initialize the matrix to the input Matrix x
Parameters:
x - Matrix
Method Detail

identity

public static Matrix identity()
purpose : create an identity matrix
Returns:
an identity matrix

plus

public static Matrix plus(Matrix a,
                          Matrix b)
purpose : add two matrices
Parameters:
a - first Matrix
b - second Matrix
Returns:
a new copy of a + b

minus

public static Matrix minus(Matrix a,
                           Matrix b)
purpose : subtract one matrix by another matrix
Parameters:
a - first Matrix
b - second Matrix
Returns:
a new copy of a - b

multi

public static Matrix multi(Matrix a,
                           Matrix b)
purpose : multiply two matrices
Parameters:
a - first Matrix
b - second Matrix
Returns:
a new copy of a x b

translate

public static Matrix translate(double tx,
                               double ty,
                               double tz)
purpose : create a translational matrix
Parameters:
tx - translate distance along x-axis
ty - translate distance along y-axis
tz - translate distance along z-axis
Returns:
a translational matrix

scale

public static Matrix scale(double sx,
                           double sy,
                           double sz)
purpose : create a scale matrix
Parameters:
sx - scale factor along x-axis
sy - scale factor along y-axis
sz - scale factor along z-axis
Returns:
a scale matrix

rotate

public static Matrix rotate(char axis,
                            double angle)
purpose : create a rotational matrix
Parameters:
axis - rotation axis (x, y or z)
angle - rotate by angle in radian
Returns:
a rotational matrix

print

public void print()
purpose : print the matrix