Advertisement
Guest User

Untitled

a guest
Nov 28th, 2015
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. import java.awt.Point;
  2.  
  3. public class Direction {
  4. private final double x;
  5. private final double y;
  6. public Direction(double x,double y){
  7. this.x=x;
  8. this.y=y;
  9.  
  10. }
  11. public Direction(Point point1,Point point2){
  12. this.x=point1.getX() - point2.getX();
  13. this.y=point2.getY() - point2.getY();
  14. }
  15. double getX(){
  16. return x;
  17. }
  18. double getY(){
  19. return y;
  20. }
  21. Direction sub(Direction direction){
  22. double tempX=this.x-direction.getX();
  23. double tempY=this.y-direction.getY();
  24. Direction subresult=new Direction(tempX,tempY);
  25. return subresult;
  26. }
  27.  
  28.  
  29.  
  30. Direction add(Direction direction){
  31. double tempX=this.x+direction.getX();
  32. double tempY=this.y+direction.getY();
  33. Direction addresult=new Direction(tempX,tempY);
  34. return addresult;
  35. }
  36.  
  37. Direction mul(double factor){
  38. double tempX=this.x*factor;
  39. double tempY=this.y*factor;
  40. Direction multiply=new Direction(tempX,tempY);
  41. return multiply;
  42. }
  43.  
  44. Direction normalized(){
  45. double norm=Math.sqrt(Math.pow(x,2)+Math.pow(y,2));
  46. double tempX= this.x/norm;
  47. double tempY= this.y/norm;
  48. Direction normalized= new Direction (tempX,tempY);
  49. return normalized;
  50. }
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement