Monday, September 17, 2007

How to use Matrixmath

The MatrixMath library will let you perform a number of different matrix operations. The following post describes the functions available to users of the pMatrix library.

Source Code
download v1.1


SAMPLE:

import matrixMath.*;

float[][] numbers = new float[2][3];
numbers[0][0] = 1;
numbers[0][1] = 2;
numbers[0][2] = 3;
numbers[1][0] = 4;
numbers[1][1] = 4;
numbers[1][2] = 4;

float[][] numbers2 = new float[3][3];
numbers2[0][0] = 1;
numbers2[0][1] = 2;
numbers2[0][2] = 3;
numbers2[1][0] = 2;
numbers2[1][1] = 2;
numbers2[1][2] = 2;

matrixMath a = new matrixMath(numbers);

a.setNumber(0,2,5);

matrixMath aResult = new matrixMath(numbers2);

println(aResult.getNumber(0,0));

//println(a.give);
aResult = matrixMath.scalePoint(aResult,2,2,2);

println(a.getNumber(0,2));
println(aResult.getNumber(0,0));
println(aResult.getNumber(0,1));
println(aResult.getNumber(0,2));
println(aResult.getNumber(1,0));
println(aResult.getNumber(1,1));
println(aResult.getNumber(1,2));

a = matrixMath.addSquareMatrix(a,aResult);

print("\n");
print("\n");
print("\n");
println(a.sizeCol());
println(a.sizeRow());


println(aResult.getNumber(0,0));
println(aResult.getNumber(0,1));
println(aResult.getNumber(0,2));
println(aResult.getNumber(1,0));
println(aResult.getNumber(1,1));
println(aResult.getNumber(1,2));

Saturday, September 15, 2007

Currently Available Functions

The following is a list of operations you can perform with the library and brief description of how to use them.

note: the term "square matrix" in the function name only means that each matrix needs to be of the same dimension not that they need to be of equal height and width.



public matrixMath(float matrix_[][])

public void setNumber(int i, int j, float value)

public float getNumber(int i, int j)

public int sizeRow()

public int sizeCol()

public matrixMath copy()

public matrixMath buildMatrx(int row, int col)

this function will create an nxn matrix and set all values to zero


the following functions will allow you to transform arrays of points of nx3 dimension.

public static matrixMath scalePoint(matrixMath x,int scaleX, int scaleY, int scaleZ)

public static matrixMath transPoint(matrixMath x,int transX, int transY, int transZ)

public static matrixMath shearPoint(matrixMath x,int shearX, int shearY, int shearZ)

public static matrixMath rotateXPoint(matrixMath x,int rotX)

public static matrixMath rotateYPoint(matrixMath x,int rotY)

public static matrixMath rotateZPoint(matrixMath x,int rotZ)


Identity matrix: This function will produce an identity matrix of a chosen size.

1000
0100
0010
0001

public static matrixMath identityMatrix(int matrixSize)


Multiply matrix: Multiply two matrices.

1234---4567
1234-*-4567
1234---4567
1234---4567

public static matrixMath multiplySquareMatrix(matrixMath matrixA, matrixMath matrixB)


Multiply 1 X N matrix: Multiply two matrices of different dimension.

4---4567
4-*-4567
4---4567
4---4567

public static matrixMath columnMultiplyMatrix(float matrixA[],matrixMath matrixB)


Scale matrix: Scale one matrix.

4---567
4-*-4567
4---567
4---567

public static matrixMath scaleSquareMatrix(matrixMath matrixA, matrixMath matrixB,int scaleFactor)


Add matrix: Add two matrices.

1234---4567
1234-+-4567
1234---4567
1234---4567

public static matrixMath addSquareMatrix(matrixMath matrixA, matrixMath matrixB)


Subtract matrix: subtract two matrices.

1234---4567
1234---4567
1234---4567
1234--- 4567

public static matrixMath subtractSquareMatrix(matrixMath matrixA, matrixMath matrixB)


Transpose matrix: transpose rows and columns.

1234---1111
1234-=-2222
1234---3333
1234---4444

public static matrixMath transposeMatrix(matrixMath matrixA)

Tuesday, September 4, 2007

Future Development

The next phase of development for pMatrix should concentrate developing functions for calculating inverse matrices and determinates.

If you want to contribute code or have other ideas please keep in mind that this is an open source project and your participation in its development is entirely welcome. We have a site set up on sourceforge.net if you are interested in being part of the libraries development.

In the next few weeks we will have matrix operations for translation, shearing and rotation.