cs2110.collision
Class Vector2D

java.lang.Object
  extended by cs2110.collision.Vector2D

public class Vector2D
extends java.lang.Object

A 2D vector with components of double precision. We also think of this as a point on a 2D plane. Remark: This data structure can be used both for something that is conceptually a vector (e.g. a displacement vector) and for something that is conceptually a point on the plane (because a point can be identified with the vector from the origin to the point).


Field Summary
 double x
          The first component of the vector.
 double y
          The second component of the vector.
 
Constructor Summary
Vector2D(double x, double y)
          Constructor a Vector with components x and y.
Vector2D(javax.vecmath.Point2d p)
          Constructor: a copy of p.
Vector2D(Vector2D p)
          Constructor: A copy of p.
 
Method Summary
 Vector2D add(Vector2D a)
          Return the result of adding this vector to a.
static Vector2D add(Vector2D a, Vector2D b)
          Return the result of adding a and b.
 void addOn(Vector2D v)
          Add v to this vector.
static double dist(Vector2D a, Vector2D b)
          Return the Euclidean distance between a and b.
 Vector2D minus(Vector2D b)
          Subtract b from this vector.
 java.lang.String toString()
          Return a representation (x, y) of this instance.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

x

public double x
The first component of the vector.


y

public double y
The second component of the vector.

Constructor Detail

Vector2D

public Vector2D(Vector2D p)
Constructor: A copy of p.

Parameters:
p - A vector.

Vector2D

public Vector2D(javax.vecmath.Point2d p)
Constructor: a copy of p.

Parameters:
p - A Point2d object from the javax.vecmath package.

Vector2D

public Vector2D(double x,
                double y)
Constructor a Vector with components x and y.

Parameters:
x - First component of vector.
y - Second component of vector.
Method Detail

toString

public java.lang.String toString()
Return a representation (x, y) of this instance.

Overrides:
toString in class java.lang.Object

add

public Vector2D add(Vector2D a)
Return the result of adding this vector to a.

Parameters:
a - A vector.
Returns:
The result of adding this vector to the vector a.

add

public static Vector2D add(Vector2D a,
                           Vector2D b)
Return the result of adding a and b.

Parameters:
a - A vector.
b - A vector.
Returns:
The result of adding vectors a and b.

dist

public static double dist(Vector2D a,
                          Vector2D b)
Return the Euclidean distance between a and b.

Parameters:
a - A vector (point).
b - A vector (point).
Returns:
The Euclidean distance between the points a and b.

addOn

public void addOn(Vector2D v)
Add v to this vector.

Parameters:
v - Vector to add on to this vector.

minus

public Vector2D minus(Vector2D b)
Subtract b from this vector.

Parameters:
b - A Vector.
Returns:
The result of subtracting b from this vector.