package W01H06a_Cartesianas;

// https://es.wikipedia.org/wiki/Coordenadas_polares

public class Point {
    
    private double x;
    private double y;

    public Point(double x, double y) {
        this.x = x;
        this.y = y;
    }
    public double getX() {
        return this.x;
    }

    public double getY() {
        return this.y;
    }

    public double getR() {
        return Math.sqrt(Math.pow(this.x,2) + Math.pow(this.y,2));
    }

    public double getAngulo() {
        double a;

             if (x> 0 && y>=0) a = Math.atan(y/x);
        else if (x>0  && y< 0) a = (2*Math.PI + Math.atan(y/x)) ;
        else if (x==0 && y> 0) a = Math.PI/2;
        else if (x< 0        ) a = Math.atan(y/x) + Math.PI;
        else if (x==0 && y< 0) a = 3*Math.PI/2;
        else                   a = 0; 
        a = a * 180 / Math.PI;
        
        return a;
    }

    @Override
    public String toString() {
        return "(x=" + this.x + ",y=" + this.y + ")";
    }

    public String toStringPolar() {
        return "(r=" + getR() + ",angulo=" + getAngulo() + ")";
    }
}
