public class Vector2D extends Object
| Constructor and Description |
|---|
Vector2D()
|
Vector2D(Coordinate
|
Vector2D(Coordinate
|
Vector2D(double x, double y)
|
Vector2D(Vector2D
|
| Modifier and Type | Method and Description |
|---|---|
Vector2D |
add(Vector2D
|
double |
angle()
|
double |
angle(Vector2D
|
double |
angleTo(Vector2D
|
Vector2D |
average(Vector2D
|
Object |
clone()
Creates a copy of this vector
|
static Vector2D |
create(Coordinate
Creates a vector from a
Coordinate.
|
static Vector2D |
create(Coordinate
Creates a vector with the direction and magnitude of the difference between the
to and
from
Coordinates.
|
static Vector2D |
create(double x, double y)
Creates a new vector with given X and Y components.
|
static Vector2D |
create(Vector2D
Creates a new vector from an existing one.
|
double |
distance(Vector2D
Computes the distance between this vector and another one.
|
Vector2D |
divide(double d)
Divides the vector by a scalar value.
|
double |
dot(Vector2D
Computes the dot-product of two vectors
|
boolean |
equals(Object
Tests if a vector
o has the same values for the x and y components.
|
double |
getComponent(int index)
|
double |
getX()
|
double |
getY()
|
int |
hashCode()
Gets a hashcode for this vector.
|
boolean |
isParallel(Vector2D
|
double |
length()
|
double |
lengthSquared()
|
Vector2D |
multiply(double d)
Multiplies the vector by a scalar value.
|
Vector2D |
negate()
|
Vector2D |
normalize()
|
Vector2D |
rotate(double angle)
|
Vector2D |
rotateByQuarterCircle(int numQuarters)
Rotates a vector by a given number of quarter-circles (i.e.
|
Vector2D |
subtract(Vector2D
|
Coordinate |
toCoordinate()
|
String |
toString()
Gets a string representation of this vector
|
Coordinate |
translate(Coordinate
|
Vector2D |
weightedSum(Vector2D
Computes the weighted sum of this vector with another vector, with this vector contributing a fraction of
frac to the total.
|
public Vector2D()
public Vector2D(double x,
double y)public Vector2D(Vector2Dv)
public Vector2D(Coordinatefrom, Coordinate to)
public Vector2D(Coordinatev)
public static Vector2Dcreate(double x, double y)
x - the x component
y - the y component
public static Vector2Dcreate(Vector2D v)
v - the vector to copy
public static Vector2Dcreate(Coordinate coord)
Coordinate.
coord - the Coordinate to copy
public static Vector2Dcreate(Coordinate from, Coordinate to)
Coordinates.
from - the origin Coordinate
to - the destination Coordinate
public double getX()
public double getY()
public double getComponent(int index)
public Vector2Dmultiply(double d)
d - the value to multiply by
public Vector2Ddivide(double d)
d - the value to divide by
public Vector2Dnegate()
public double length()
public double lengthSquared()
public Vector2Dnormalize()
public Vector2DweightedSum(Vector2D v, double frac)
In other words,
sum = frac * this + (1 - frac) * v
v - the vector to sum
frac - the fraction of the total contributed by this vector
public double distance(Vector2Dv)
v - a vector
public double dot(Vector2Dv)
v - a vector
public double angle()
public double angle(Vector2Dv)
public double angleTo(Vector2Dv)
public Vector2Drotate(double angle)
public Vector2DrotateByQuarterCircle(int numQuarters)
numQuarters - the number of quarter-circles to rotate by
public boolean isParallel(Vector2Dv)
public Coordinatetranslate(Coordinate coord)
public CoordinatetoCoordinate()
public Objectclone()
public StringtoString()
public boolean equals(Objecto)