Class Vector2D

java.lang.Object
  |
  +--Vector2D

class Vector2D
extends java.lang.Object

Represents a vector containing two components.

All of the methods execpt for setX(), setY() and set() will leave the vector unchanged; the result will be returned rather than assigned. Although it is possible to modify the components, one should bear in mind that other classes may store vectors, and may not anticipate a change.


Field Summary
protected  double x
           
protected  double y
           
 
Constructor Summary
Vector2D()
          Creates a new zero vector.
Vector2D(double x, double y)
          Creates a new vector.
 
Method Summary
 Vector2D add(Vector2D v)
          Adds the supplied vector to this one, and returns the result.
 double argument()
          Returns the argument of this vector (radians widdershins from (1,0)).
 double getX()
           
 double getY()
           
 boolean isNaN()
          Returns true if either of the components are NaNs, else false
 double modulus()
          Returns the modulus of this vector.
 double modulusSquared()
          Returns the square of the modulus of this vector.
 Vector2D multiply(double d)
          Multiplies this vector by the supplied constant, and returns the result.
 double scalarProduct(Vector2D v)
          Returns the scalar product of the supplied vector with the this one.
 void set(double x, double y)
          Sets both components of this vector.
 void setX(double x)
           
 void setY(double y)
           
 Vector2D subtract(Vector2D v)
          Subtracts the supplied vector from this one, and returns the result.
 Vector2D unitVector()
          Returns a vector with modulus 1, and the same argument as this vector.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

x

protected double x

y

protected double y
Constructor Detail

Vector2D

public Vector2D(double x,
                double y)
Creates a new vector.
Parameters:
x - The 'x' component
y - The 'y' component

Vector2D

public Vector2D()
Creates a new zero vector.
Method Detail

add

public Vector2D add(Vector2D v)
Adds the supplied vector to this one, and returns the result.

subtract

public Vector2D subtract(Vector2D v)
Subtracts the supplied vector from this one, and returns the result.

multiply

public Vector2D multiply(double d)
Multiplies this vector by the supplied constant, and returns the result.

scalarProduct

public double scalarProduct(Vector2D v)
Returns the scalar product of the supplied vector with the this one.

modulus

public double modulus()
Returns the modulus of this vector.

modulusSquared

public double modulusSquared()
Returns the square of the modulus of this vector.

argument

public double argument()
Returns the argument of this vector (radians widdershins from (1,0)).

unitVector

public Vector2D unitVector()
Returns a vector with modulus 1, and the same argument as this vector.

getX

public double getX()

getY

public double getY()

setX

public void setX(double x)

setY

public void setY(double y)

set

public void set(double x,
                double y)
Sets both components of this vector.
Parameters:
x - The new 'x' component
y - The new 'y' component

isNaN

public boolean isNaN()
Returns true if either of the components are NaNs, else false