package myGraphics.VectorGrafix; import myGraphics.VectorGrafix.Matrix3d; import myGraphics.VectorGrafix.Vector3d; import java.lang.Math; public class Transformation3d extends Matrix3d{ public Transformation3d() { super(); } public Transformation3d(Matrix3d M) { super(); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { mterm[i][j] = M.mterm[i][j]; } } } public Transformation3d copy() { Transformation3d target = new Transformation3d(); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { target.mterm[i][j] = mterm[i][j]; } } return target; } public Transformation3d translate(double Ax, double Ay, double Az) { Matrix3d temp = new Matrix3d(); temp.set_term(0, 0, 1.0); temp.set_term(0, 3, Ax); temp.set_term(1, 1, 1.0); temp.set_term(1, 3, Ay); temp.set_term(2, 2, 1.0); temp.set_term(2, 3, Az); return new Transformation3d(temp.multiply(this)); } public Transformation3d translate(Vector3d v) { return translate(v.x(), v.y(), v.z()); } public Transformation3d scale(double Sx, double Sy, double Sz) { Matrix3d temp = new Matrix3d(); temp.set_term(0, 0, Sx); temp.set_term(1, 1, Sy); temp.set_term(2, 2, Sz); temp.set_term(3, 3, 1.0); return new Transformation3d(temp.multiply(this)); } public Transformation3d x_rotate(double Theta) { Matrix3d temp = new Matrix3d(); double theSin = Math.sin(Theta); double theCos = Math.cos(Theta); temp.set_term(0, 0, 1.0); temp.set_term(1, 1, theCos); temp.set_term(1, 2, -theSin); temp.set_term(2, 1, theSin); temp.set_term(2, 2, theCos); temp.set_term(3, 3, 1.0); return new Transformation3d(temp.multiply(this)); } public Transformation3d y_rotate(double Theta) { Matrix3d temp = new Matrix3d(); double theSin = Math.sin(Theta); double theCos = Math.cos(Theta); temp.set_term(0, 0, theCos); temp.set_term(0, 2, theSin); temp.set_term(1, 1, 1.0); temp.set_term(2, 0, -theSin); temp.set_term(2, 2, theCos); temp.set_term(3, 3, 1.0); return new Transformation3d(temp.multiply(this)); } public Transformation3d z_rotate(double Theta) { Matrix3d temp = new Matrix3d(); double theSin = Math.sin(Theta); double theCos = Math.cos(Theta); temp.set_term(0, 0, theCos); temp.set_term(0, 1, -theSin); temp.set_term(1, 0, theSin); temp.set_term(1, 1, theCos); temp.set_term(2, 2, 1.0); temp.set_term(3, 3, 1.0); return new Transformation3d(temp.multiply(this)); } public Vector3d apply(Vector3d v) { return this.multiply(v); } public Transformation3d appliedBefore(Transformation3d laterTrans) { return new Transformation3d(laterTrans.multiply(this)); } }