public class PolarVector2D extends Vector2D {

    public PolarVector2D() { super(); }
    
    public PolarVector2D(double r, double phi) { super(r, phi); }

    public PolarVector2D(PolarVector2D template) { super((Vector2D) template); }

    public void scale(double value) { x *= value; }

    public void rotate(double angle) { y += angle; }
    
    public double norm() { return x * x; }

    public double length() { return Math.abs(x); }

    public double angle() { return y; }
	
    public void normalize() throws IllegalStateException {
	if(x == 0.0) throw new IllegalStateException("Null Vector");
	x /= length();
    }

    public void invert() { y *= -1; }

    public double r() { return x; }
    
    public void r(double value) { x = value; }
    
    public void angle(double value) { y = value; }

    public Vector2D cartesian() { 
	Vector2D v = new Vector2D();
	v.x = x * Math.cos(y);
	v.y = x * Math.sin(y);
	return v;
    }

    public void math(char op, double b) throws IllegalArgumentException {
	switch(op) {
	case '*': x *= b; break;
	case '/': x /= b; break;
	case '^': x = Math.pow(x, b); break;
	default: throw new IllegalArgumentException("Illegal Operation");
	}
    }

    public static Vector2D math(Vector2D a, char op, double b) throws IllegalArgumentException {
	Vector2D result = new Vector2D();

	switch(op) {
	case '*': result.x = a.x * b; result.y = a.y; break;
	case '/': result.x = a.x / b; result.y = a.y; break;
	default: throw new IllegalArgumentException("Illegal Operation");
	}

	return result;
    }
	
    public String toString() { return "(" + x + "," + y + ")"; }		
}
