Modifier and Type | Field and Description |
---|---|
double |
x
x-coordinate of the vector
|
double |
y
y-coordinate of the vector
|
Constructor and Description |
---|
Vector2()
Initializes vector coordinates to (0,0).
|
Vector2(double x,
double y)
Initializes vector coordinates to (x,y).
|
Modifier and Type | Method and Description |
---|---|
void |
addValues(double dx,
double dy)
Add values to the coordinates of this vector.
|
void |
addVector(Vector2 other)
Add the values of the coordinates of other vector
to the coordinates of this vector.
|
int |
compareTo(Vector2 other)
Required method from Comparable interface; used to sort collections of Vector2 objects by length, particularly for use in determining the minimum (shortest) translation vector for use in resolving collisions with solid objects.
|
double |
getAngle()
Calculate the angle (in degrees) between this vector
and the x-axis (the vector (1,0)).
|
double |
getLength()
Calculate the length of this vector
|
void |
multiply(double scalar)
Multiple the coordinates of this vector by
a given value.
|
void |
setAngle(double angleDegrees)
Changes the angle of this vector to angleDegrees
while preserving the length of this vector.
|
void |
setLength(double length)
Changes the length of this vector to length while
preserving the angle of this vector.
|
void |
setValues(double x,
double y)
Set the values of the x- and y- coordinates.
|
java.lang.String |
toString() |
public double x
public double y
public Vector2()
public Vector2(double x, double y)
x
- x-coordinatey
- y-coordinatepublic void setValues(double x, double y)
x
- x-coordinatey
- y-coordinatepublic void addVector(Vector2 other)
other
- vector to be added to this vectorpublic void addValues(double dx, double dy)
dx
- value to add to the x-coordinatedy
- value to add to the y-coordinatepublic void multiply(double scalar)
scalar
- the value to multiply the coordinates of this vector bypublic double getLength()
public double getAngle()
public void setLength(double length)
length
- the new length of this vectorpublic void setAngle(double angleDegrees)
angleDegrees
- the new angle (in degrees) between this vector and the x-axispublic int compareTo(Vector2 other)
compareTo
in interface java.lang.Comparable<Vector2>
other
- the vector being compared against this vectorComparable.compareTo(java.lang.Object)
public java.lang.String toString()
toString
in class java.lang.Object