mr3d.lang
Class Matrix

java.lang.Object
  extended bymr3d.debug.ErrorHandling
      extended bymr3d.lang.Matrix
All Implemented Interfaces:
Debugable

public class Matrix
extends ErrorHandling
implements Debugable

The class Matrix is able to represent an mathematical 4x4 matrix object.

The following example assumes that the class mr3d.lang.Matrix has been imported with import mr3d.lang.Matrix in the head of the java-file.

      // create a unit matrix 
     Matrix myMatrix = new Matrix(Matrix.TYPE_UNIT);
  

Since:
MR3Dv1.0
Version:
10-2004
Author:
Manuel Ruelke

Field Summary
private  int[] matrixData
          Elements or data of the matrix.
private  int matType
          Internal type variable.
static int TYPE_GENERIC
          Type constant generic matrix.
static int TYPE_ROTA
          Type constant for rotation matrix.
static int TYPE_SCAL
          Type constant for scalation matrix.
static int TYPE_TRAN
          Type constant for translation matrix.
static int TYPE_UNIT
          Type constant for unit matrix.
static int TYPE_ZERO
          Type constant zero matrix.
 
Fields inherited from class mr3d.debug.ErrorHandling
 
Fields inherited from interface mr3d.debug.Debugable
ERROR_INT, ERROR_STRING
 
Constructor Summary
Matrix()
          Creates a new Matrix.
 
Method Summary
 int get(int index)
          Returns the matrix element at the specified linear index.
 int get(int line, int column)
          Returns the matrix element at the specified index.
 Matrix mul(Matrix matrix)
          Multplies two matrices.
 Vector3D mul(Vector3D mulVec)
          Multiplies a vector with a Matrix.
private  void selfMul(Matrix matrix)
          Multiplies this matrix with the given matrix.
 void set(int[] args)
          Overwrites the complete matrix data with the specified array.
 void set(int index, int value)
          Sets the matrix element at the specified index to be the specified value.
 void set(int line, int column, int value)
          Sets the matrix element at the specified index to be the specified value.
 void setType(int newType)
          Sets the matType of the Matrix.
 void toConsole()
          Prints the contents of the matrix object to the Java console.
 void toConsole(java.lang.String msgString)
          Prints the contents of the object to the Java console together with an information string.
 int type()
          Returns the Matrix matType contant of the current Matrix.
 
Methods inherited from class mr3d.debug.ErrorHandling
getErrMsg, notifyError
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

matrixData

private int[] matrixData
Elements or data of the matrix. This data is stored in a linear int-Array consisting of 16 elements. This array is only accessible with the given set and get functions.


matType

private int matType
Internal type variable. Used to optimize matrix-aritmetical operations.


TYPE_GENERIC

public static final int TYPE_GENERIC
Type constant generic matrix.

See Also:
Constant Field Values

TYPE_ROTA

public static final int TYPE_ROTA
Type constant for rotation matrix.

See Also:
Constant Field Values

TYPE_SCAL

public static final int TYPE_SCAL
Type constant for scalation matrix.

See Also:
Constant Field Values

TYPE_TRAN

public static final int TYPE_TRAN
Type constant for translation matrix.

See Also:
Constant Field Values

TYPE_UNIT

public static final int TYPE_UNIT
Type constant for unit matrix.

See Also:
Constant Field Values

TYPE_ZERO

public static final int TYPE_ZERO
Type constant zero matrix.

See Also:
Constant Field Values
Constructor Detail

Matrix

public Matrix()
Creates a new Matrix. This standard implementation creates a matrix where all elements are 0 (zero matrix).

Method Detail

get

public int get(int index)
Returns the matrix element at the specified linear index.

Parameters:
index - index of the matrix element in linear coordinates (0 to 15)
Returns:
the element at the specified index
See Also:
matrixData

get

public int get(int line,
               int column)
Returns the matrix element at the specified index. This method works with two-dimensional indices. (line index, column index).

Parameters:
line - line index of matrix element
column - column index of matrix element
Returns:
the element at the specified index
See Also:
matrixData

mul

public Matrix mul(Matrix matrix)
Multplies two matrices.

Example

A matrix multiplication in the form of

Matrix3 = Matrix1 * Matrix2

can be realized this way:

Matrix Matrix3 = Matrix1.mul(Matrix2);

Parameters:
matrix - matrix, which will be mutiplied to this matrix
Returns:
resulting matrix

mul

public Vector3D mul(Vector3D mulVec)
Multiplies a vector with a Matrix. The result will be returned as a vector.

Example

The mathematical expression

Vektor2 = Matrix1 * Vektor1

can be realized as

Vektor2 = Matrix1.mul(Vektor1);


selfMul

private void selfMul(Matrix matrix)
Multiplies this matrix with the given matrix. This matrix will be overwritten with the result.

Example

To demonstrate the way of working of this method look at the following example:

When result of the multiplication
Matrix1 * Matrix2
should be saved into Matrix1, you can use the following expressions:

Matrix1.selfMul(Matrix2);

or

Matrix1 = Matrix1.mul(Matrix2);

Parameters:
matrix - matrix, which will be mutiplied to this matrix

set

public void set(int[] args)
Overwrites the complete matrix data with the specified array.

Parameters:
args - the int-array of with 16 elements that replaces matrixData
See Also:
matrixData

set

public void set(int index,
                int value)
Sets the matrix element at the specified index to be the specified value. This method works with linear coordinates.

Parameters:
index - linear index of matrix element
value - what the element is to be set to
See Also:
matrixData

set

public void set(int line,
                int column,
                int value)
Sets the matrix element at the specified index to be the specified value. This method works with two-dimensional coordinates.

Parameters:
line - line index of matrix element
column - column index of matrix elememt
value - what the element is to be set to
See Also:
matrixData

setType

public void setType(int newType)
Sets the matType of the Matrix.

Parameters:
newType - new Matrix matType constant.

toConsole

public void toConsole()
Prints the contents of the matrix object to the Java console. The output will be organzied by the line. The different matrix elements will be seperated by the character symbol "|".

Specified by:
toConsole in interface Debugable

toConsole

public void toConsole(java.lang.String msgString)
Description copied from interface: Debugable
Prints the contents of the object to the Java console together with an information string. How the information will be displayed depends on what data the object contains. Depending on structure and contents every implementation of this function produces a different result on the console.

Specified by:
toConsole in interface Debugable

type

public int type()
Returns the Matrix matType contant of the current Matrix.

Returns:
matrix matType contant