public class Vector2D
extends java.lang.Object
implements java.io.Serializable
Modifier and Type | Field and Description |
---|---|
static int |
ANTI_CLOCKWISE |
static int |
CLOCKWISE |
static double |
EPSILON |
static Vector2D |
MINUS_I
Opposite of the first canonical vector (coordinates: -1, 0).
|
static Vector2D |
MINUS_J
Opposite of the second canonical vector (coordinates: 0, -1).
|
static Vector2D |
NaN
A vector with all coordinates set to NaN.
|
static Vector2D |
NEGATIVE_INFINITY
A vector with all coordinates set to negative infinity.
|
static Vector2D |
ONE
Null vector (coordinates: 1, 1).
|
static Vector2D |
PLUS_I
First canonical vector (coordinates: 1, 0).
|
static Vector2D |
PLUS_J
Second canonical vector (coordinates: 0, 1).
|
static Vector2D |
POSITIVE_INFINITY
A vector with all coordinates set to positive infinity.
|
double |
x |
double |
y |
static Vector2D |
ZERO
Null vector (coordinates: 0, 0).
|
Constructor and Description |
---|
Vector2D()
Default to the zero vector
|
Vector2D(double x,
double y)
Create a vector based on parameter values.
|
Vector2D(Vector2D v)
Copy constructor
|
Modifier and Type | Method and Description |
---|---|
Vector2D |
add(double dx,
double dy)
Change the vector by the values specified
|
Vector2D |
add(Vector2D v)
Add a vector to this one
|
static Vector2D |
add(Vector2D v0,
Vector2D v1)
Get a new vector that is the sum of 2 vectors.
|
double |
angleBetween(Vector2D v)
Calculate the angle between this and another vector.
|
static double |
angleBetween(Vector2D v0,
Vector2D v1)
Calculate the angle between two vectors.
|
static boolean |
areEqual(Vector2D v0,
Vector2D v1) |
static double |
dist(Vector2D v0,
Vector2D v1)
The distance between two vectors
|
double |
distance(Vector2D v)
Get the distance between this and an other point.
|
double |
distanceSq(Vector2D v)
Get the distance squared between this and another
point.
|
static double |
distSq(Vector2D v0,
Vector2D v1)
The square of the distance between two vectors
|
Vector2D |
div(double d)
Divide the vector by a scalar
|
static Vector2D |
div(Vector2D v,
double d)
Get a new vector that is a vector divided by a scalar
|
double |
dot(Vector2D v)
Calculate the dot product between two un-normalised vectors.
|
double |
dotNorm(Vector2D v)
Calculate the dot product between two vectors using normalised values
i.e.
|
Vector2D |
get()
Get a copy (new object) of this vector.
|
Vector2D |
getPerp()
Get a vector perpendicular to this one.
|
Vector2D |
getReflect(Vector2D norm)
Return the reflection vector about the norm
|
Vector2D |
getReverse()
Get a vector that is the reverse of this vector
|
static boolean |
isSecondInFOVofFirstXXX(Vector2D posFirst,
Vector2D facingFirst,
double fovFirst,
Vector2D posSecond)
Determines whether entity 2 is visible from entity 1.
|
double |
length()
Get the vector length
|
double |
lengthSq()
Get the vector length squared
|
Vector2D |
mult(double d)
Multiply the vector by a scalar
|
static Vector2D |
mult(Vector2D v,
double d)
Get a new vector that is the product of a vector and a scalar
|
Vector2D |
normalize()
Normalise this vector
|
static Vector2D |
normalize(Vector2D v)
Get a new vector that is the given vector normalised
|
static Vector2D |
random(Vector2D target)
Create a random normalised vector.
|
void |
set(double x,
double y) |
void |
set(Vector2D v) |
int |
sign(Vector2D v)
Determines whether vector v is clockwise of this vector.
|
Vector2D |
sub(Vector2D v) |
static Vector2D |
sub(Vector2D v0,
Vector2D v1)
Get a new vector that is the difference between the
2 vectors.
|
double[] |
toArray()
Get the coordinates as an array.
|
java.lang.String |
toShortString() |
java.lang.String |
toString() |
Vector2D |
truncate(double max)
Truncate this vector so its length is no greater than
the value provided.
|
public static final Vector2D ZERO
public static final Vector2D ONE
public static final Vector2D PLUS_I
public static final Vector2D MINUS_I
public static final Vector2D PLUS_J
public static final Vector2D MINUS_J
public static final Vector2D NaN
public static final Vector2D POSITIVE_INFINITY
public static final Vector2D NEGATIVE_INFINITY
public static final double EPSILON
public static final int CLOCKWISE
public static final int ANTI_CLOCKWISE
public double x
public double y
public Vector2D()
public Vector2D(double x, double y)
x
- y
- public Vector2D(Vector2D v)
v
- the vector to copypublic void set(Vector2D v)
public void set(double x, double y)
public double lengthSq()
public double length()
public double dot(Vector2D v)
v
- the other vectorpublic double dotNorm(Vector2D v)
v
- the other vectorpublic double angleBetween(Vector2D v)
v
- the other vectorpublic int sign(Vector2D v)
v
- a vectorpublic Vector2D get()
public Vector2D getPerp()
public double distanceSq(Vector2D v)
v
- the other pointpublic double distance(Vector2D v)
v
- the other pointpublic Vector2D normalize()
public Vector2D truncate(double max)
max
- maximum size for this vectorpublic Vector2D getReverse()
public Vector2D getReflect(Vector2D norm)
norm
- public Vector2D add(double dx, double dy)
dx
- dy
- public Vector2D mult(double d)
d
- public Vector2D div(double d)
d
- public static Vector2D add(Vector2D v0, Vector2D v1)
v0
- first vectorv1
- second vectorpublic static Vector2D sub(Vector2D v0, Vector2D v1)
v0
- first vectorv1
- second vectorpublic static Vector2D mult(Vector2D v, double d)
v
- the original vectord
- the multiplierpublic static Vector2D div(Vector2D v, double d)
v
- the original vectord
- the divisorpublic static double distSq(Vector2D v0, Vector2D v1)
v0
- the first vectorv1
- the second vectorpublic static double dist(Vector2D v0, Vector2D v1)
v0
- the first vectorv1
- the second vectorpublic static Vector2D normalize(Vector2D v)
v
- the original vectorpublic static double angleBetween(Vector2D v0, Vector2D v1)
v0
- first vectorv1
- second vectorpublic static boolean isSecondInFOVofFirstXXX(Vector2D posFirst, Vector2D facingFirst, double fovFirst, Vector2D posSecond)
posFirst
- position of first entityfacingFirst
- direction first entity is facingfovFirst
- field of view (radians)posSecond
- position of second entitypublic static Vector2D random(Vector2D target)
target
- the vector to randomise, create a vector if nullpublic double[] toArray()
public java.lang.String toShortString()
public java.lang.String toString()
toString
in class java.lang.Object
Processing library AI_for_2D_Games by Peter Lager. (C) 2013