java.lang.ObjectVector
public final class Vector
A 2D vector. The vector can be read and manipulated in Cartesian coordinates (as an x,y-offset pair) or in polar coordinates (as a direction and a length).
Constructor Summary | |
---|---|
Vector()
Create a new, neutral vector. |
|
Vector(double dx,
double dy)
Create a vector by specifying the x and y offsets from start to end points. |
|
Vector(int direction,
double length)
Create a vector with given direction and length. |
Method Summary | |
---|---|
void |
add(Vector other)
Add another vector to this vector. |
int |
getDirection()
Return the direction of this vector (in degrees). |
double |
getLength()
Return the length of this vector. |
double |
getX()
Return the x offset of this vector (start to end point). |
double |
getY()
Return the y offset of this vector (start to end point). |
void |
revertHorizontal()
Revert to horizontal component of this movement vector. |
void |
revertVertical()
Revert to vertical component of this movement vector. |
void |
scale(double factor)
Scale this vector up (factor greater than 1) or down (factor less than 1). |
void |
setDirection(int direction)
Set the direction of this vector, leaving the length intact. |
void |
setLength(double length)
Set the length of this vector, leaving the direction intact. |
void |
setNeutral()
Set this vector to the neutral vector (length 0). |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Vector()
public Vector(double dx, double dy)
public Vector(int direction, double length)
Method Detail |
---|
public void add(Vector other)
public int getDirection()
public double getLength()
public double getX()
public double getY()
public void revertHorizontal()
public void revertVertical()
public void scale(double factor)
public void setDirection(int direction)
public void setLength(double length)
public void setNeutral()