public class Vector extends java.lang.Object implements java.lang.Comparable<Vector>
Modifier and Type | Field and Description |
---|---|
static Vector |
ONE |
static Vector |
UNIT_X |
static Vector |
UNIT_Y |
static Vector |
UNIT_Z |
protected double |
x |
protected double |
y |
protected double |
z |
static Vector |
ZERO |
Constructor and Description |
---|
Vector()
Construct a new instance with X, Y, and Z coordinates set to 0.
|
Vector(double x,
double y,
double z)
Construct an instance.
|
Vector(float x,
float y,
float z)
Construct an instance.
|
Vector(int x,
int y,
int z)
Construct an instance.
|
Vector(Vector other)
Copy another vector.
|
Modifier and Type | Method and Description |
---|---|
Vector |
add(double x,
double y,
double z)
Add another vector to this vector and return the result as a new vector.
|
Vector |
add(int x,
int y,
int z)
Add another vector to this vector and return the result as a new vector.
|
Vector |
add(Vector... others)
Add a list of vectors to this vector and return the
result as a new vector.
|
Vector |
add(Vector other)
Add another vector to this vector and return the result as a new vector.
|
Vector |
ceil()
Rounds all components up.
|
Vector |
clampY(int min,
int max)
Clamp the Y component.
|
int |
compareTo(Vector other) |
boolean |
containedWithin(Vector min,
Vector max)
Checks to see if a vector is contained with another.
|
boolean |
containedWithinBlock(Vector min,
Vector max)
Checks to see if a vector is contained with another, comparing
using discrete comparisons, inclusively.
|
Vector |
cross(Vector other)
Gets the cross product of this and another vector.
|
double |
distance(Vector other)
Get the distance between this vector and another vector.
|
double |
distanceSq(Vector other)
Get the distance between this vector and another vector, squared.
|
Vector |
divide(double n)
Perform scalar division and return a new vector.
|
Vector |
divide(double x,
double y,
double z)
Divide this vector by another vector on each component.
|
Vector |
divide(float n)
Perform scalar division and return a new vector.
|
Vector |
divide(int n)
Perform scalar division and return a new vector.
|
Vector |
divide(int x,
int y,
int z)
Divide this vector by another vector on each component.
|
Vector |
divide(Vector other)
Divide this vector by another vector on each component.
|
double |
dot(Vector other)
Gets the dot product of this and another vector.
|
boolean |
equals(java.lang.Object obj) |
Vector |
floor()
Floors the values of all components.
|
int |
getBlockX()
Get the X coordinate rounded.
|
int |
getBlockY()
Get the Y coordinate rounded.
|
int |
getBlockZ()
Get the Z coordinate rounded.
|
static Vector |
getMaximum(Vector v1,
Vector v2)
Gets the maximum components of two vectors.
|
static Vector |
getMidpoint(Vector v1,
Vector v2)
Gets the midpoint of two vectors.
|
static Vector |
getMinimum(Vector v1,
Vector v2)
Gets the minimum components of two vectors.
|
double |
getX()
Get the X coordinate.
|
double |
getY()
Get the Y coordinate.
|
double |
getZ()
Get the Z coordinate.
|
int |
hashCode() |
boolean |
isCollinearWith(Vector 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.
|
Vector |
multiply(double n)
Perform scalar multiplication and return a new vector.
|
Vector |
multiply(double x,
double y,
double z)
Multiply this vector by another vector on each component.
|
Vector |
multiply(float n)
Perform scalar multiplication and return a new vector.
|
Vector |
multiply(int n)
Perform scalar multiplication and return a new vector.
|
Vector |
multiply(int x,
int y,
int z)
Multiply this vector by another vector on each component.
|
Vector |
multiply(Vector... others)
Multiply this vector by zero or more vectors on each component.
|
Vector |
multiply(Vector other)
Multiply this vector by another vector on each component.
|
Vector |
normalize()
Get the normalized vector, which is the vector divided by its
length, as a new vector.
|
Vector |
positive()
Returns a vector with the absolute values of the components of
this vector.
|
Vector |
round()
Rounds all components to the closest integer.
|
Vector |
setX(double x)
Set the X coordinate.
|
Vector |
setX(int x)
Set the X coordinate.
|
Vector |
setY(double y)
Set the Y coordinate.
|
Vector |
setY(int y)
Set the Y coordinate.
|
Vector |
setZ(double z)
Set the Z coordinate.
|
Vector |
setZ(int z)
Set the Z coordinate.
|
Vector |
subtract(double x,
double y,
double z)
Subtract another vector from this vector and return the result
as a new vector.
|
Vector |
subtract(int x,
int y,
int z)
Subtract another vector from this vector and return the result
as a new vector.
|
Vector |
subtract(Vector... others)
Subtract a list of vectors from this vector and return the result
as a new vector.
|
Vector |
subtract(Vector other)
Subtract another vector from this vector and return the result
as a new vector.
|
BlockVector |
toBlockPoint()
Create a new
BlockVector from this vector. |
static BlockVector |
toBlockPoint(double x,
double y,
double z)
Create a new
BlockVector using the given components. |
BlockVector |
toBlockVector()
Create a new
BlockVector from this vector. |
float |
toPitch()
Get this vector's pitch as used within the game.
|
java.lang.String |
toString() |
Vector2D |
toVector2D()
Creates a 2D vector by dropping the Y component from this vector.
|
float |
toYaw()
Get this vector's yaw as used within the game.
|
Vector |
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 Vector ZERO
public static final Vector UNIT_X
public static final Vector UNIT_Y
public static final Vector UNIT_Z
public static final Vector ONE
protected final double x
protected final double y
protected final double z
public Vector(double x, double y, double z)
x
- the X coordinatey
- the Y coordinatez
- the Z coordinatepublic Vector(int x, int y, int z)
x
- the X coordinatey
- the Y coordinatez
- the Z coordinatepublic Vector(float x, float y, float z)
x
- the X coordinatey
- the Y coordinatez
- the Z coordinatepublic Vector(Vector other)
other
- another vector to make a copy ofpublic Vector()
One can also refer to a static ZERO
.
public double getX()
public int getBlockX()
public Vector setX(double x)
x
- the new Xpublic Vector setX(int x)
x
- the X coordinatepublic double getY()
public int getBlockY()
public Vector setY(double y)
y
- the new Ypublic Vector setY(int y)
y
- the new Ypublic double getZ()
public int getBlockZ()
public Vector setZ(double z)
z
- the new Zpublic Vector setZ(int z)
z
- the new Zpublic Vector add(Vector other)
other
- the other vectorpublic Vector add(double x, double y, double z)
x
- the value to addy
- the value to addz
- the value to addpublic Vector add(int x, int y, int z)
x
- the value to addy
- the value to addz
- the value to addpublic Vector add(Vector... others)
others
- an array of vectorspublic Vector subtract(Vector other)
other
- the other vectorpublic Vector subtract(double x, double y, double z)
x
- the value to subtracty
- the value to subtractz
- the value to subtractpublic Vector subtract(int x, int y, int z)
x
- the value to subtracty
- the value to subtractz
- the value to subtractpublic Vector subtract(Vector... others)
others
- an array of vectorspublic Vector multiply(Vector other)
other
- the other vectorpublic Vector multiply(double x, double y, double z)
x
- the value to multiplyy
- the value to multiplyz
- the value to multiplypublic Vector multiply(int x, int y, int z)
x
- the value to multiplyy
- the value to multiplyz
- the value to multiplypublic Vector multiply(Vector... others)
others
- an array of vectorspublic Vector multiply(double n)
n
- the value to multiplypublic Vector multiply(float n)
n
- the value to multiplypublic Vector multiply(int n)
n
- the value to multiplypublic Vector divide(Vector other)
other
- the other vectorpublic Vector divide(double x, double y, double z)
x
- the value to divide byy
- the value to divide byz
- the value to divide bypublic Vector divide(int x, int y, int z)
x
- the value to divide byy
- the value to divide byz
- the value to divide bypublic Vector divide(int n)
n
- the value to divide bypublic Vector divide(double n)
n
- the value to divide bypublic Vector divide(float n)
n
- the value to divide bypublic double length()
public double lengthSq()
public double distance(Vector other)
other
- the other vectorpublic double distanceSq(Vector other)
other
- the other vectorpublic Vector normalize()
public double dot(Vector other)
other
- the other vectorpublic Vector cross(Vector other)
other
- the other vectorpublic boolean containedWithin(Vector min, Vector 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(Vector min, Vector max)
min
- the minimum point (X, Y, and Z are the lowest)max
- the maximum point (X, Y, and Z are the lowest)public Vector clampY(int min, int max)
min
- the minimum valuemax
- the maximum valuepublic Vector floor()
public Vector ceil()
public Vector round()
Components < 0.5 are rounded down, otherwise up.
public Vector positive()
public Vector 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(Vector other)
other
- the other vectorpublic float toPitch()
public float toYaw()
public static BlockVector toBlockPoint(double x, double y, double z)
BlockVector
using the given components.x
- the X coordinatey
- the Y coordinatez
- the Z coordinateBlockVector
public BlockVector toBlockPoint()
BlockVector
from this vector.BlockVector
public BlockVector toBlockVector()
BlockVector
from this vector.BlockVector
public Vector2D toVector2D()
Vector2D
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int compareTo(@Nullable Vector other)
compareTo
in interface java.lang.Comparable<Vector>
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public static Vector getMinimum(Vector v1, Vector v2)
v1
- the first vectorv2
- the second vectorpublic static Vector getMaximum(Vector v1, Vector v2)
v1
- the first vectorv2
- the second vector