Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package rg;
- public class Transformation {
- private Matrix M;
- public Transformation() {
- double[][] d = {{1, 0, 0, 0 },
- {0, 1, 0, 0},
- {0, 0, 1, 0},
- {0, 0, 0, 1}};
- Matrix M = new Matrix(d);
- }
- public void translate(double tx, double ty, double tz) {
- double[][] trt = new double[][] { { 1, 0, 0, tx },
- { 0, 1, 0, ty },
- { 0, 0, 1, tz },
- { 0, 0, 0, 1 } };
- Matrix translate = new Matrix(trt);
- this.M = Matrix.multiply(this.M, translate);
- }
- public void scale(double sx, double sy, double sz){
- double[][] sc = new double[][] { { sx, 0, 0, 0 },
- { 0, sy, 0, 0 },
- { 0, 0, sz, 0 },
- { 0, 0, 0, 1 } };
- Matrix scale = new Matrix(sc);
- this.M = Matrix.multiply(this.M, scale);
- }
- public void rotateX(double phi){
- double[][] rX = new double[][] { { 1, 0, 0, 0 },
- { 0, Math.cos(phi),-1*Math.sin(phi), 0 },
- { 0, Math.sin(phi), Math.cos(phi), 0 },
- { 0, 0, 0, 1 } };
- Matrix rotateX = new Matrix(rX);
- this.M = Matrix.multiply(this.M, rotateX);
- }
- public void rotateY(double phi){
- double[][] rY = new double[][] { { Math.cos(phi), 0, Math.sin(phi), 0 },
- { 0, 1, 0, 0 },
- { -1*Math.sin(phi),0, Math.cos(phi), 0 },
- { 0, 0, 0, 1 } };
- Matrix rotateY = new Matrix(rY);
- this.M = Matrix.multiply(this.M, rotateY);
- }
- public void rotateZ(double phi){
- double[][] rZ = new double[][] { { Math.cos(phi), -1*Math.sin(phi),0, 0 },
- {Math.sin(phi), Math.cos(phi), 0, 0 },
- { 0, 0, 1, 0 },
- { 0, 0, 0, 1 } };
- Matrix rotateZ = new Matrix(rZ);
- this.M = Matrix.multiply(this.M, rotateZ);
- }
- public double[] transformPoint(double[] point) {
- double [][] tocka = new double[4][1];
- tocka [0][0] = point [0];
- tocka [1][0] = point [1];
- tocka [2][0] = point [2];
- tocka [3][0] = 1;
- Matrix newPoint = new Matrix(tocka);
- newPoint = Matrix.multiply(M, newPoint);
- return new double[] {newPoint.getValues()[0][0], newPoint.getValues()[1][0],newPoint.getValues()[2][0]};
- }
- }
Add Comment
Please, Sign In to add comment