package rebelsky.twodim; /** * A vector in two space, internally represented by angle * and radius. * * @author CSC152 2004F * @version 0.1 of September 2004 */ public class NewTwoDimVector { // +--------+------------------------------------------------------- // | Fields | // +--------+ double radius; double theta; // +--------------+------------------------------------------------- // | Constructors | // +--------------+ public NewTwoDimVector(double _radius, double _theta) { this.radius = _radius; this.theta = _theta; } // NewTwoDimVector(double,double) // +----------+----------------------------------------------------- // | Mutators | // +----------+ public void setX(double newx) { double oldy= this.getY(); this.radius = Math.sqrt(newx*newx + oldy*oldy); this.theta = Math.atan(oldy/newx); } // setX(double) // +-----------+---------------------------------------------------- // | Observers | // +-----------+ public double dotProduct(NewTwoDimVector other) { return 0.0; // STUB! } // dotProduct public double getX() { return Math.cos(this.theta) * this.radius; } // getX() public double getY() { return Math.sin(this.theta) * this.radius; } // getY() public double getDistanceFromOrigin() { return this.radius; } // getDistanceFromOrigin() /** * Return a new vector that is a scaled version of the current vector. */ public NewTwoDimVector stretch(double factor) { return new NewTwoDimVector(this.radius*factor, this.theta); } // stretch(double) } // class NewTwoDimVector