Idoor

Vector3DProcessor

Sep 21st, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. package classes;
  2. import classes.Vector3D;
  3.  
  4. public class Vector3DProcessor {
  5.  
  6. public void addition(Vector3D v, Vector3D v1, Vector3D v2) {
  7. v.x = v1.x + v2.x;
  8. v.y = v1.y + v2.y;
  9. v.z = v1.z + v2.z;
  10. }
  11.  
  12. public void difference(Vector3D v, Vector3D v1, Vector3D v2){
  13. v.x = v1.x - v2.x;
  14. v.y = v1.y - v2.y;
  15. v.z = v1.z - v2.z;
  16. }
  17.  
  18. public double scalarProduct(Vector3D v1, Vector3D v2){
  19. return (v1.x*v2.x + v1.y*v2.y + v1.z*v2.z);
  20. }
  21.  
  22. public void vectorProduct(Vector3D v, Vector3D v1, Vector3D v2){
  23. v.x = v1.y * v2.z - v1.z * v2.x;
  24. v.y = v1.z * v2.x - v1.x * v2.z;
  25. v.z = v1.x * v2.y - v1.y * v2.x;
  26. }
  27.  
  28. public boolean collinear(Vector3D v1, Vector3D v2){
  29. Vector3D mult = new Vector3D();
  30. vectorProduct(mult, v1, v2);
  31. if(mult.x == 0 && mult.y == 0 && mult.z == 0) {return true;}
  32. else {return false;}
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment