Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. /**
  2. * Created by tal on 4/25/17.
  3. */
  4. public class Point {
  5. private double _radius;
  6. private double _alpha;
  7.  
  8. public Point(double x, double y)
  9. {
  10.  
  11. _radius = Math.sqrt(Math.pow(x,2) + Math.pow(y,2));
  12. _alpha = Math.atan(y/x);
  13. if(_alpha >= ((Math.PI)/2) & _alpha < (Math.PI))
  14. _alpha = Math.PI/2;
  15. if(_alpha >= Math.PI & _alpha < (Math.PI * 3/4))
  16. _radius = 0;
  17. if(_alpha >= (Math.PI * 3/4))
  18. _alpha = 0;
  19. }
  20. public Point(Point other)
  21. {
  22. this._radius = other._radius;
  23. this._alpha = other._alpha;
  24. }
  25. public double getX()
  26. {
  27. return(_radius * Math.cos(_alpha));
  28. }
  29. public double getY()
  30. {
  31. return(_radius * Math.sin(_alpha));
  32. }
  33. public void setX(double num)
  34. {
  35. if (num >= 0)
  36. {
  37. _radius = num / Math.cos(_alpha);
  38. _alpha = Math.atan(Math.sqrt(Math.pow(_radius, 2) - Math.pow(num, 2)) / 2);
  39. }
  40. }
  41. public void setY(double num)
  42. {
  43. if (num >= 0)
  44. {
  45. _radius = num / Math.sin(_alpha);
  46. _alpha = Math.atan(Math.sqrt(Math.pow(_radius, 2) - Math.pow(num, 2)) / 2);
  47. }
  48. }
  49. public String toString()
  50. {
  51. return ("(" + _radius * Math.cos(_alpha) + "," + (_radius * Math.sin(_alpha)) + ")"); // need to round it.
  52. }
  53. public boolean equals(Point other)
  54. {
  55. return ((_radius == other._radius) & (_alpha == other._alpha)); // need to round number to check if they are equal
  56.  
  57.  
  58. }
  59. public boolean isAbove(Point other)
  60. {
  61. //check what to put here
  62. }
  63. public boolean isLeft(Point other)
  64. {
  65. // check what to put here
  66. }
  67. public boolean isRIght(Point other)
  68. {
  69. //check what to put here
  70. }
  71.  
  72.  
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement