java.lang.Objectjrobots.utils.Vector
public class Vector
This class represents a two dimensional vector.
The internal fields are immutable - they are set once at the construction of the vector. All methods returning a vector construct a new vector.
The vector can be treated both in Cartesian and in polar form. Like below:
getAngle(),
getLength(),
add(Vector),
sub(Vector),
mult(double),
getX(),
getY(),
ZERO,
rotate(Angle),
projection(Angle),
vectorProduct(Vector),
Serialized Form| Field Summary | |
|---|---|
static Vector |
ZERO
|
| Constructor Summary | |
|---|---|
Vector()
Constructs the zero vector. |
|
Vector(Angle angle,
double length)
Constructs a vector by polar coordinates. |
|
Vector(double length,
Angle angle)
Constructs a vector by polar coordinates. |
|
Vector(double x,
double y)
Constructs a vector by Cartesian coordinates (x,y). |
|
| Method Summary | |
|---|---|
Vector |
add(Vector v)
Addition of two vectors. |
Vector |
clone()
|
double |
distanceTo(Vector b)
Calculates the distance between two vectors. |
boolean |
equals(java.lang.Object obj)
|
Angle |
getAngle()
Gets the polar angle of this vector. |
double |
getLength()
Returns the length of this vector |
Vector |
getNegative()
The inverse vector has same length and opposite direction. |
Vector |
getNormal()
Scales this vector to a length of 1. |
double |
getX()
Returns the Cartesian x component. |
double |
getY()
Returns the Cartesian y component. |
int |
hashCode()
|
Vector |
mult(double factor)
Scales this vector by a given factor. |
double |
projection(Angle angle)
Projects the vector onto a given Angle. |
Vector |
rotate(Angle angle)
Rotates a vector in clockwise direction. |
Vector |
sub(Vector v)
Subtracts a given vector from this vector. |
java.lang.String |
toString()
|
double |
vectorProduct(Vector b)
The vector product in the two dimensional space results in a scalar value. |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final Vector ZERO
| Constructor Detail |
|---|
public Vector()
public Vector(Angle angle,
double length)
angle - length -
public Vector(double length,
Angle angle)
length - angle -
public Vector(double x,
double y)
x - doubley - double| Method Detail |
|---|
public Vector add(Vector v)
v - Summand
public Vector clone()
clone in class java.lang.Objectpublic double distanceTo(Vector b)
Note that the vectors must share the same reference system.
b - Vector
public boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic Angle getAngle()
public double getLength()
public Vector getNegative()
public Vector getNormal()
public double getX()
public double getY()
public int hashCode()
hashCode in class java.lang.Objectpublic Vector mult(double factor)
factor -
public double projection(Angle angle)
angle - - projection angle
public Vector rotate(Angle angle)
angle - rotation angle (>0 for clockwise rotation)
public Vector sub(Vector v)
v - Subtrahend
public java.lang.String toString()
toString in class java.lang.Objectpublic double vectorProduct(Vector b)
b - - second parameter of the vector product