public class Vector2D
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static Vector2D |
ONE |
static Vector2D |
UNIT_X |
static Vector2D |
UNIT_Z |
protected double |
x |
protected double |
z |
static Vector2D |
ZERO |
Constructor and Description |
---|
Vector2D()
Construct a new instance with X and Z coordinates set to 0.
|
Vector2D(double x,
double z)
Construct an instance.
|
Vector2D(float x,
float z)
Construct an instance.
|
Vector2D(int x,
int z)
Construct an instance.
|
Vector2D(Vector2D other)
Copy another vector.
|
Modifier and Type | Method and Description |
---|---|
Vector2D |
add(double x,
double z)
Add another vector to this vector and return the result as a new vector.
|
Vector2D |
add(int x,
int z)
Add another vector to this vector and return the result as a new vector.
|
Vector2D |
add(Vector2D... others)
Add a list of vectors to this vector and return the
result as a new vector.
|
Vector2D |
add(Vector2D other)
Add another vector to this vector and return the result as a new vector.
|
Vector2D |
ceil()
Rounds all components up.
|
boolean |
containedWithin(Vector2D min,
Vector2D max)
Checks to see if a vector is contained with another.
|
boolean |
containedWithinBlock(Vector2D min,
Vector2D max)
Checks to see if a vector is contained with another.
|
double |
distance(Vector2D other)
Get the distance between this vector and another vector.
|
double |
distanceSq(Vector2D other)
Get the distance between this vector and another vector, squared.
|
Vector2D |
divide(double n)
Perform scalar division and return a new vector.
|
Vector2D |
divide(double x,
double z)
Divide this vector by another vector on each component.
|
Vector2D |
divide(float n)
Perform scalar division and return a new vector.
|
Vector2D |
divide(int n)
Perform scalar division and return a new vector.
|
Vector2D |
divide(int x,
int z)
Divide this vector by another vector on each component.
|
Vector2D |
divide(Vector2D other)
Divide this vector by another vector on each component.
|
double |
dot(Vector2D other)
Gets the dot product of this and another vector.
|
boolean |
equals(java.lang.Object obj) |
Vector2D |
floor()
Floors the values of all components.
|
int |
getBlockX()
Get the X coordinate rounded.
|
int |
getBlockZ()
Get the Z coordinate rounded.
|
static Vector2D |
getMaximum(Vector2D v1,
Vector2D v2)
Gets the maximum components of two vectors.
|
static Vector2D |
getMinimum(Vector2D v1,
Vector2D v2)
Gets the minimum components of two vectors.
|
double |
getX()
Get the X coordinate.
|
double |
getZ()
Get the Z coordinate.
|
int |
hashCode() |
boolean |
isCollinearWith(Vector2D other)
Returns whether this vector is collinear with another vector.
|
double |
length()
Get the length of the vector.
|
double |
lengthSq()
Get the length, squared, of the vector.
|
Vector2D |
multiply(double n)
Perform scalar multiplication and return a new vector.
|
Vector2D |
multiply(double x,
double z)
Multiply this vector by another vector on each component.
|
Vector2D |
multiply(float n)
Perform scalar multiplication and return a new vector.
|
Vector2D |
multiply(int n)
Perform scalar multiplication and return a new vector.
|
Vector2D |
multiply(int x,
int z)
Multiply this vector by another vector on each component.
|
Vector2D |
multiply(Vector2D... others)
Multiply this vector by zero or more vectors on each component.
|
Vector2D |
multiply(Vector2D other)
Multiply this vector by another vector on each component.
|
Vector2D |
normalize()
Get the normalized vector, which is the vector divided by its
length, as a new vector.
|
Vector2D |
positive()
Returns a vector with the absolute values of the components of
this vector.
|
Vector2D |
round()
Rounds all components to the closest integer.
|
Vector2D |
setX(double x)
Set the X coordinate.
|
Vector2D |
setX(int x)
Set the X coordinate.
|
Vector2D |
setZ(double z)
Set the Z coordinate.
|
Vector2D |
setZ(int z)
Set the Z coordinate.
|
Vector2D |
subtract(double x,
double z)
Subtract another vector from this vector and return the result
as a new vector.
|
Vector2D |
subtract(int x,
int z)
Subtract another vector from this vector and return the result
as a new vector.
|
Vector2D |
subtract(Vector2D... others)
Subtract a list of vectors from this vector and return the result
as a new vector.
|
Vector2D |
subtract(Vector2D other)
Subtract another vector from this vector and return the result
as a new vector.
|
BlockVector2D |
toBlockVector2D()
Create a new
BlockVector2D from this vector. |
java.lang.String |
toString() |
Vector |
toVector()
Creates a 3D vector by adding a zero Y component to this vector.
|
Vector |
toVector(double y)
Creates a 3D vector by adding the specified Y component to this vector.
|
Vector2D |
transform2D(double angle,
double aboutX,
double aboutZ,
double translateX,
double translateZ)
Perform a 2D transformation on this vector and return a new one.
|
public static final Vector2D ZERO
public static final Vector2D UNIT_X
public static final Vector2D UNIT_Z
public static final Vector2D ONE
protected final double x
protected final double z
public Vector2D(double x, double z)
x
- the X coordinatez
- the Z coordinatepublic Vector2D(int x, int z)
x
- the X coordinatez
- the Z coordinatepublic Vector2D(float x, float z)
x
- the X coordinatez
- the Z coordinatepublic Vector2D(Vector2D other)
other
- the other vectorpublic Vector2D()
One can also refer to a static ZERO
.
public double getX()
public int getBlockX()
public Vector2D setX(double x)
x
- the new Xpublic Vector2D setX(int x)
x
- the new Xpublic double getZ()
public int getBlockZ()
public Vector2D setZ(double z)
z
- the new Zpublic Vector2D setZ(int z)
z
- the new Zpublic Vector2D add(Vector2D other)
other
- the other vectorpublic Vector2D add(double x, double z)
x
- the value to addz
- the value to addpublic Vector2D add(int x, int z)
x
- the value to addz
- the value to addpublic Vector2D add(Vector2D... others)
others
- an array of vectorspublic Vector2D subtract(Vector2D other)
other
- the other vectorpublic Vector2D subtract(double x, double z)
x
- the value to subtractz
- the value to subtractpublic Vector2D subtract(int x, int z)
x
- the value to subtractz
- the value to subtractpublic Vector2D subtract(Vector2D... others)
others
- an array of vectorspublic Vector2D multiply(Vector2D other)
other
- the other vectorpublic Vector2D multiply(double x, double z)
x
- the value to multiplyz
- the value to multiplypublic Vector2D multiply(int x, int z)
x
- the value to multiplyz
- the value to multiplypublic Vector2D multiply(Vector2D... others)
others
- an array of vectorspublic Vector2D multiply(double n)
n
- the value to multiplypublic Vector2D multiply(float n)
n
- the value to multiplypublic Vector2D multiply(int n)
n
- the value to multiplypublic Vector2D divide(Vector2D other)
other
- the other vectorpublic Vector2D divide(double x, double z)
x
- the value to divide byz
- the value to divide bypublic Vector2D divide(int x, int z)
x
- the value to divide byz
- the value to divide bypublic Vector2D divide(int n)
n
- the value to divide bypublic Vector2D divide(double n)
n
- the value to divide bypublic Vector2D divide(float n)
n
- the value to divide bypublic double length()
public double lengthSq()
public double distance(Vector2D other)
other
- the other vectorpublic double distanceSq(Vector2D other)
other
- the other vectorpublic Vector2D normalize()
public double dot(Vector2D other)
other
- the other vectorpublic boolean containedWithin(Vector2D min, Vector2D max)
min
- the minimum point (X, Y, and Z are the lowest)max
- the maximum point (X, Y, and Z are the lowest)public boolean containedWithinBlock(Vector2D min, Vector2D max)
min
- the minimum point (X, Y, and Z are the lowest)max
- the maximum point (X, Y, and Z are the lowest)public Vector2D floor()
public Vector2D ceil()
public Vector2D round()
Components < 0.5 are rounded down, otherwise up.
public Vector2D positive()
public Vector2D transform2D(double angle, double aboutX, double aboutZ, double translateX, double translateZ)
angle
- in degreesaboutX
- about which x coordinate to rotateaboutZ
- about which z coordinate to rotatetranslateX
- what to add after rotationtranslateZ
- what to add after rotationanother method to transform vectors
public boolean isCollinearWith(Vector2D other)
other
- the other vectorpublic BlockVector2D toBlockVector2D()
BlockVector2D
from this vector.BlockVector2D
public Vector toVector()
public Vector toVector(double y)
y
- the Y componentpublic boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public static Vector2D getMinimum(Vector2D v1, Vector2D v2)
v1
- the first vectorv2
- the second vector