public class Vector2D
extends java.lang.Object
     (0, 0) o------------------>x-axis
            | .  / direction
            |  .
            |   .vector
            |    .
            |     .
            |      *
            v
          y-axis
 
 The direction of the vector is defined as the angle (0..2*pi) of the
 vector direction clockwise with reference to the x-coordinate direction.| Modifier and Type | Field and Description | 
|---|---|
double | 
x
The public x-coordinate. 
 | 
double | 
y
The public y-coordinate. 
 | 
| Constructor and Description | 
|---|
Vector2D()
Constructs a zero vector (with coordinates (0, 0)). 
 | 
Vector2D(double x,
        double y)
Constructs a vector from given double x-y-coordinates. 
 | 
Vector2D(float x,
        float y)
Constructs a vector from given float x-y-coordinates. 
 | 
Vector2D(int x,
        int y)
Constructs a vector from given integer x-y-coordinates. 
 | 
| Modifier and Type | Method and Description | 
|---|---|
Vector2D | 
add(Vector2D v)
Returns a new vector that is the vector sum of the current vector and the given vector. 
 | 
Vector2D | 
clone()
Returns a new vector with the same coordinates as the current vector. 
 | 
double | 
distanceTo(Vector2D v)
Returns the distance between the current vector and the given vector. 
 | 
double | 
dot(Vector2D v)
Returns the scalar product (dot product) of the current vector with the given vector. 
 | 
double | 
getDirection()
Returns the direction of the vector (range 0..2*pi) 
 | 
Vector2D | 
getNormalized()
Returns a new vector with magnitude 1 in the direction of the given vector. 
 | 
Vector2D | 
invert()
Returns a new vector with inverted coordinates. 
 | 
boolean | 
isEqual(Vector2D v)
Returns true, if the current vector is identical to the given vector. 
 | 
double | 
magnitude()
Returns the magnitude (length) of the vector. 
 | 
double | 
magnitude2()
Returns the square of the magnitude, without squareroot calculation. 
 | 
Vector2D | 
mult(double b)
Returns a new vector that is the product by a scalar of the current vector and the given double. 
 | 
Vector2D | 
mult(float b)
Returns a new vector that is the product by a scalar of the current vector and the given float. 
 | 
Vector2D | 
mult(int b)
Returns a new vector that is the product by a scalar of the current vector and the given integer. 
 | 
void | 
normalize()
Modifies the vector to unit magnitude. 
 | 
void | 
rotate(double angle)
Rotates the vector by the specified angle. 
 | 
Vector2D | 
sub(Vector2D v)
Returns a new vector that is the vector difference of the current vector and the given vector. 
 | 
java.lang.String | 
toString()
Returns a string with the x-y-coordinates in the format (x,y). 
 | 
public Vector2D()
public Vector2D(int x,
        int y)
x - the x-coordinate of the vectory - the y-coordinate of the vectorpublic Vector2D(float x,
        float y)
x - the x-coordinate of the vectory - the y-coordinate of the vectorpublic Vector2D(double x,
        double y)
x - the x-coordinate of the vectory - the y-coordinate of the vectorpublic double magnitude()
public double magnitude2()
public void normalize()
public Vector2D getNormalized()
public double getDirection()
public void rotate(double angle)
angle - the rotation angle (in radian, clockwise)public double dot(Vector2D v)
v - the vector to take for the dot productpublic double distanceTo(Vector2D v)
v - the vector to take for the distance measurementpublic Vector2D add(Vector2D v)
v - the vector to be added to the current vectorpublic Vector2D invert()
public Vector2D sub(Vector2D v)
v - the vector to be substracted from the current vectorpublic Vector2D mult(int b)
b - the integer scale factorpublic Vector2D mult(float b)
b - the float scale factorpublic Vector2D mult(double b)
b - the double scale factorpublic Vector2D clone()
clone in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Objectpublic boolean isEqual(Vector2D v)
v - the vector to compare