net.jimmc.spelsim
Class DVector

java.lang.Object
  extended by net.jimmc.spelsim.DVector

public class DVector
extends java.lang.Object

Immutable 2D vector.


Constructor Summary
DVector()
          Create a vector with values (0,0).
DVector(double x, double y)
          Create a vector by specifying rectangular coordinates.
 
Method Summary
 double dot(DVector that)
          Get the dot product of this vector and another vector.
 double getAngle()
          Get the angle of the current point in polar coordinates.
 double getRadius()
          Get the radius of the current point in polar coordinates.
 double getX()
          Get the x coordinate of this point.
 double getY()
          Get the y coordinate of this point.
 double length()
          Get the length of this vector.
 double lengthSquared()
          Get the length squared of this vector.
 DVector minus(DVector that)
          Return a vector which is this vector minus another one.
static DVector newPolar(double r, double theta)
          Create a vector by specifying polar coordinates.
 DVector normal()
          Get a vector normal to this vector and of the same magnitude.
 DVector plus(DVector that)
          Return a new vector which is the sum of this vector plus another one.
 DVector rotated(double theta)
          Get a new vector which is a rotated version of this vector.
 DVector times(double k)
          Return a new vector which is this vector times a constant.
 java.lang.String toString()
           
 DVector unit()
          Get a vector of unit length pointing in the same direction as this vector.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DVector

public DVector()
Create a vector with values (0,0).


DVector

public DVector(double x,
               double y)
Create a vector by specifying rectangular coordinates.

Method Detail

newPolar

public static DVector newPolar(double r,
                               double theta)
Create a vector by specifying polar coordinates.


times

public DVector times(double k)
Return a new vector which is this vector times a constant.


plus

public DVector plus(DVector that)
Return a new vector which is the sum of this vector plus another one.


minus

public DVector minus(DVector that)
Return a vector which is this vector minus another one.


rotated

public DVector rotated(double theta)
Get a new vector which is a rotated version of this vector.


normal

public DVector normal()
Get a vector normal to this vector and of the same magnitude. The normal vector will have an angle of PI/2 greater than the original vector (modulo 2 PI).


unit

public DVector unit()
Get a vector of unit length pointing in the same direction as this vector. If this vector is (0,0), then (0,0) is returned.


lengthSquared

public double lengthSquared()
Get the length squared of this vector.


length

public double length()
Get the length of this vector.


getX

public double getX()
Get the x coordinate of this point.


getY

public double getY()
Get the y coordinate of this point.


getRadius

public double getRadius()
Get the radius of the current point in polar coordinates.


getAngle

public double getAngle()
Get the angle of the current point in polar coordinates.

Returns:
The angle in radians, with 0 being the x axis. If the point is (0,0), the returned value is 0.

dot

public double dot(DVector that)
Get the dot product of this vector and another vector.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object