public class Vector2D extends Object
| Constructor and Description |
|---|
Vector2D() |
Vector2D(double x,
double y) |
Vector2D(Point v) |
Vector2D(Point from,
Point to) |
Vector2D(Vector2D v) |
| Modifier and Type | Method and Description |
|---|---|
Vector2D |
add(Vector2D v) |
double |
angle() |
double |
angle(Vector2D v) |
double |
angleTo(Vector2D v) |
Vector2D |
average(Vector2D v) |
Object |
clone()
Creates a copy of this vector
|
static Vector2D |
create(double x,
double y)
Creates a new vector with given X and Y components.
|
static Vector2D |
create(Point coord)
Creates a vector from a
Coordinates. |
static Vector2D |
create(Point from,
Point to)
Creates a vector with the direction and magnitude
of the difference between the
to and from
Coordinatess. |
static Vector2D |
create(Vector2D v)
Creates a new vector from an existing one.
|
double |
distance(Vector2D v)
Computes the distance between this vector and another one.
|
Vector2D |
divide(double d)
Divides the vector by a scalar value.
|
double |
dot(Vector2D v)
Computes the dot-product of two vectors
|
boolean |
equals(Object o)
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 v) |
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 v) |
Point |
toCoordinate() |
String |
toString()
Gets a string representation of this vector
|
Point |
translate(Point coord) |
Vector2D |
weightedSum(Vector2D v,
double frac)
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(Point v)
public Vector2D(Vector2D v)
public static Vector2D create(double x, double y)
x - the x componenty - the y componentpublic static Vector2D create(Point coord)
Coordinates.coord - the Point to copypublic static Vector2D create(Point from, Point to)
Coordinatess.from - the origin Coordinateto - the destination Coordinatepublic static Vector2D create(Vector2D v)
v - the vector to copypublic double angle()
public double angle(Vector2D v)
public double angleTo(Vector2D v)
public Object clone()
public double distance(Vector2D v)
v - a vectorpublic Vector2D divide(double d)
d - the value to divide bypublic double dot(Vector2D v)
v - a vectorpublic boolean equals(Object o)
public double getComponent(int index)
public double getX()
public double getY()
public int hashCode()
public boolean isParallel(Vector2D v)
public double length()
public double lengthSquared()
public Vector2D multiply(double d)
d - the value to multiply bypublic Vector2D negate()
public Vector2D normalize()
public Vector2D rotate(double angle)
public Vector2D rotateByQuarterCircle(int numQuarters)
numQuarters - the number of quarter-circles to rotate bypublic Point toCoordinate()
public String toString()
public Vector2D weightedSum(Vector2D v, double frac)
In other words,
sum = frac * this + (1 - frac) * v
v - the vector to sumfrac - the fraction of the total contributed by this vectorCopyright © 2015 Revolution Systems Inc.. All rights reserved.