public class Vector2D
extends java.lang.Object
Constructor | Description |
---|---|
Vector2D() |
|
Vector2D(double x,
double y) |
|
Vector2D(Coordinate v) |
|
Vector2D(Coordinate from,
Coordinate to) |
|
Vector2D(Vector2D v) |
Modifier and Type | Method | Description |
---|---|---|
Vector2D |
add(Vector2D v) |
|
double |
angle() |
|
double |
angle(Vector2D v) |
|
double |
angleTo(Vector2D v) |
|
Vector2D |
average(Vector2D v) |
|
java.lang.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(Coordinate coord) |
Creates a vector from a
Coordinate . |
static Vector2D |
create(Coordinate from,
Coordinate to) |
Creates a vector with the direction and magnitude
of the difference between the
to and from
Coordinate s. |
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(java.lang.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) |
|
Coordinate |
toCoordinate() |
|
java.lang.String |
toString() |
Gets a string representation of this vector
|
Coordinate |
translate(Coordinate 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(Vector2D v)
public Vector2D(Coordinate from, Coordinate to)
public Vector2D(Coordinate v)
public static Vector2D create(double x, double y)
x
- the x componenty
- the y componentpublic static Vector2D create(Vector2D v)
v
- the vector to copypublic static Vector2D create(Coordinate coord)
Coordinate
.coord
- the Coordinate to copypublic static Vector2D create(Coordinate from, Coordinate to)
Coordinate
s.from
- the origin Coordinateto
- the destination Coordinatepublic double getX()
public double getY()
public double getComponent(int index)
public Vector2D multiply(double d)
d
- the value to multiply bypublic Vector2D divide(double d)
d
- the value to divide bypublic Vector2D negate()
public double length()
public double lengthSquared()
public Vector2D normalize()
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 vectorpublic double distance(Vector2D v)
v
- a vectorpublic double dot(Vector2D v)
v
- a vectorpublic double angle()
public double angle(Vector2D v)
public double angleTo(Vector2D v)
public Vector2D rotate(double angle)
public Vector2D rotateByQuarterCircle(int numQuarters)
numQuarters
- the number of quarter-circles to rotate bypublic boolean isParallel(Vector2D v)
public Coordinate translate(Coordinate coord)
public Coordinate toCoordinate()
public java.lang.Object clone()
public java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
o
- a Vector2D with which to do the comparison.public int hashCode()
hashCode
in class java.lang.Object
Copyright © 2018. All rights reserved.