
// This is a polar-coordinates based Point class
// which is plug-compatible to the XY-based Point class
public class Point {
  
  private double radius = 0.0;
  private double angle = 0.0;

  public double getRadius() { return radius; }
  public void setRadius(double r) { radius = r;}

  public double getAngle() { return angle; }
  public void setAngle(double a) { angle = a; }
  

  public double getX() { return getRadius() * Math.cos(getAngle()); }
  public void setX(double x) { 
    double y = getY();
    double newRadius = Math.sqrt(x*x + y*y);
    setRadius(newRadius);
    double newAngle = Math.atan2(y,x);
    setAngle(newAngle);
  }
    

  public double getY() { return getRadius() * Math.sin(getAngle()); }
  public void setY(double x) { 
    // left as an exercise :-)
  }

  public Point(double x, double y) {
    setX(x);
    setY(y);
  }

  public Point() {
    this(0,0);
  }

  // ???
  public static Point makePoint(double radius, double angle) {
    Point point = new Point();
    point.setRadius(radius);
    point.setAngle(angle);
    return point;
  }

  public String toString() {
    return "<Point " + getX() + "/" + getY() + ">";
  }

}


      
