Wednesday, February 20, 2013

HW 3 - Matrix Transform


The controls for the applet are the following:

Applet
            • q, w, e : translate (+) x, y, z
            • a, s, d : translate (-) x, y, z
            • i, o, p : scale (+) x, y, z
            • j, k, l : scale (-) x, y, z
            • 1, 2 : rotation velocity (+/-) x
            • 3, 4 : rotation velocity (+/-) y
            • 5, 6 : rotation velocity (+/-) z
            • [space] : reset to identity

I made my own classes instead of implementing the interface IMatrix. First I have a class Matrix that simply defines a general matrix and has methods to perform operations.

class Matrix 

Variables:
    • double[][] mat
    • int nrows, ncols
Methods:
    • void set(int i, int j, double val) : set value of index i,j (HW)
    • double get(int i, int j) : get value of index i,j (HW)
    • int getn() : number of rows
    • int getm() : number of columns
    • double[][] getmat() : matrix ad 2d array
Static Operations:
    • void prettyPrint(Matrix m) : prints out matrix nicely
    • Matrix eye(int n) : returns nxn identity matrix (HW)
    • Matrix mult(double c, Matrix M) : scalar product of matrix
    • Matrix mult(Matrix ... M) : chain multiplication left to right (HW)
    • Matrix copy(Matrix M) : copy
    • Matrix transpose(Matrix M) : transpose

I also have a class called Transform. This defines the 4x4 Matrix TRS to perform transformations on points. There are two modes: separate=true,false. If separate=false, then only TRS is sequentially updated. If separate is true, then T, R, S, the translation, rotation, and scale matrices, are sequentially updated independently. Then TRS is calculated as the multiplication [T][R][S].

class Transform

Variables:
    • Matrix TRS, T, R, S
    • boolean separate, compressed
Methods:
    • void prettyPrint(): prints TRS, T, R, S nicely
    • void compressTRS() : calculate TRS by multiplying [T][R][S]
    • <> get<>() : retrieve one of the variables
    • void set<>(...) : set one of the matrix variables
    • void rotateZYX() : perform x, then y, then z rotation.
    • Matrix tM, rM, rxM, ryM, rzM, sM(...) : primitive matrices
    • double getTRS(int i, int j) (HW)
    • void setTRS(int i, int j, double val) (HW)
    • void reset() : identity (HW)
    • void translate(double x, double y, double z) (HW)
    • void rotate<>(double rad) (HW)
    • Matrix apply(Matrix src)
    • void apply(Matrix src, Matrix dst)  (HW)


___________________________________________________________________________________
Download HW3.zip
Download Matrix.java
Download Transform.java

No comments:

Post a Comment