Guest User

Untitled

a guest
Aug 17th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. package rg;
  2.  
  3. public class Transformation {
  4.  
  5. private Matrix M;
  6.  
  7. public Transformation() {
  8. double[][] d = {{1, 0, 0, 0 },
  9. {0, 1, 0, 0},
  10. {0, 0, 1, 0},
  11. {0, 0, 0, 1}};
  12. Matrix M = new Matrix(d);
  13. }
  14.  
  15. public void translate(double tx, double ty, double tz) {
  16.  
  17. double[][] trt = new double[][] { { 1, 0, 0, tx },
  18. { 0, 1, 0, ty },
  19. { 0, 0, 1, tz },
  20. { 0, 0, 0, 1 } };
  21.  
  22. Matrix translate = new Matrix(trt);
  23.  
  24. this.M = Matrix.multiply(this.M, translate);
  25.  
  26. }
  27.  
  28. public void scale(double sx, double sy, double sz){
  29. double[][] sc = new double[][] { { sx, 0, 0, 0 },
  30. { 0, sy, 0, 0 },
  31. { 0, 0, sz, 0 },
  32. { 0, 0, 0, 1 } };
  33.  
  34. Matrix scale = new Matrix(sc);
  35.  
  36. this.M = Matrix.multiply(this.M, scale);
  37.  
  38. }
  39.  
  40. public void rotateX(double phi){
  41. double[][] rX = new double[][] { { 1, 0, 0, 0 },
  42. { 0, Math.cos(phi),-1*Math.sin(phi), 0 },
  43. { 0, Math.sin(phi), Math.cos(phi), 0 },
  44. { 0, 0, 0, 1 } };
  45.  
  46. Matrix rotateX = new Matrix(rX);
  47.  
  48. this.M = Matrix.multiply(this.M, rotateX);
  49.  
  50. }
  51.  
  52. public void rotateY(double phi){
  53. double[][] rY = new double[][] { { Math.cos(phi), 0, Math.sin(phi), 0 },
  54. { 0, 1, 0, 0 },
  55. { -1*Math.sin(phi),0, Math.cos(phi), 0 },
  56. { 0, 0, 0, 1 } };
  57.  
  58. Matrix rotateY = new Matrix(rY);
  59.  
  60. this.M = Matrix.multiply(this.M, rotateY);
  61.  
  62. }
  63.  
  64. public void rotateZ(double phi){
  65. double[][] rZ = new double[][] { { Math.cos(phi), -1*Math.sin(phi),0, 0 },
  66. {Math.sin(phi), Math.cos(phi), 0, 0 },
  67. { 0, 0, 1, 0 },
  68. { 0, 0, 0, 1 } };
  69.  
  70. Matrix rotateZ = new Matrix(rZ);
  71.  
  72. this.M = Matrix.multiply(this.M, rotateZ);
  73.  
  74. }
  75.  
  76.  
  77. public double[] transformPoint(double[] point) {
  78. double [][] tocka = new double[4][1];
  79. tocka [0][0] = point [0];
  80. tocka [1][0] = point [1];
  81. tocka [2][0] = point [2];
  82. tocka [3][0] = 1;
  83.  
  84. Matrix newPoint = new Matrix(tocka);
  85. newPoint = Matrix.multiply(M, newPoint);
  86. return new double[] {newPoint.getValues()[0][0], newPoint.getValues()[1][0],newPoint.getValues()[2][0]};
  87.  
  88. }
  89.  
  90. }
Add Comment
Please, Sign In to add comment