Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. public class Point{
  2. private double _radius;
  3. private double _alpha;
  4. private final double DEFAULT_VAL=0;
  5. public Point(double x,double y){
  6. if(y<DEFAULT_VAL){
  7. _alpha=0;}
  8. double alpha=Math.atan(y/x);
  9. _alpha=Math.round(alpha*10000)/(double)10000;
  10. double radius=Math.sqrt(Math.pow(x,2)+Math.pow(y,2));
  11. _radius=Math.round(radius*10000)/(double)10000;
  12.  
  13.  
  14. }
  15. public Point(Point other){
  16. _radius=other._radius;
  17. _alpha=other._alpha;
  18. }
  19. public double getX(){
  20. double p=Math.cos(_alpha)*_radius;
  21. return Math.round(p*10000)/(double)10000;
  22. }
  23. public double getY(){
  24. double p=Math.sin(_alpha)*_radius;
  25. return Math.round(p*10000)/(double)10000;
  26. }
  27. public void setX(double num){
  28. double y=getY();
  29.  
  30. if(num>DEFAULT_VAL && y>DEFAULT_VAL){
  31. //double radius=getRadius(num,getY());
  32. _radius=getRadius(num,y);
  33. //double alpha=getAlpha(num,getY());
  34. _alpha=getAlpha(num,y);
  35. }
  36. }
  37.  
  38. public void setY(double num){
  39. double x=getX();
  40. if(num>DEFAULT_VAL){
  41. //double radius=getRadius(getX(),num);
  42. _radius=getRadius(x,num);
  43. //double alpha=getAlpha(getX(),num);
  44. _alpha=getAlpha(x,num);}
  45. }
  46. public String toString(){
  47. return "("+_radius+","+_alpha+")";
  48. }
  49. public boolean equals(Point other){
  50. return this.getY()==other.getY() && this.getX()==other.getX();
  51.  
  52.  
  53. }
  54. public boolean isAbove(Point other){
  55. return(this.getY()>other.getY());
  56. }
  57.  
  58. public boolean isUnder(Point other){
  59. return other.isAbove(this);
  60. }
  61. public boolean isLeft(Point other){
  62. return (this.getX()<other.getX());
  63. }
  64. public boolean isRight(Point other){
  65. return other.isLeft(this);
  66. }
  67. public double distance(Point p){
  68. double d;
  69. d=Math.sqrt(Math.pow((p.getX() -this.getX()), 2)+Math.pow((p.getY()-this.getY()), 2));
  70. return Math.round(d*10000)/(double)10000;
  71.  
  72.  
  73. }
  74. public void move(double dX,double dY){
  75. if((getX()+dX)>=DEFAULT_VAL && (getY()+dY)>=DEFAULT_VAL){
  76. setX(getX()+dX);
  77. setY(getY()+dY);}
  78. }
  79. private double getRadius(double x,double y){
  80. _radius=Math.sqrt(Math.pow(x,2)+Math.pow(y,2));
  81. return Math.round(_radius*10000)/(double)10000;}
  82. private double getAlpha(double x,double y){
  83. if(getY()==DEFAULT_VAL){
  84. _alpha=Math.PI/2;
  85. return Math.round(_alpha*10000)/(double)10000;}
  86. _alpha=Math.atan(y/x);
  87. return Math.round(_alpha*10000)/(double)10000;
  88. }
  89.  
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement