public class AbstractVector extends Object implements Cloneable
clone()
in order to get a copy.Modifier and Type | Field and Description |
---|---|
protected double |
x |
protected double |
y |
protected double |
z |
Constructor and Description |
---|
AbstractVector()
Construct the vector with all components as 0.
|
AbstractVector(double x,
double y,
double z)
Construct the vector with provided double components.
|
AbstractVector(float x,
float y,
float z)
Construct the vector with provided float components.
|
AbstractVector(int x,
int y,
int z)
Construct the vector with provided integer components.
|
Modifier and Type | Method and Description |
---|---|
AbstractVector |
add(AbstractVector vec)
Adds a vector to this one
|
float |
angle(AbstractVector other)
Gets the angle between this vector and another in radians.
|
AbstractVector |
clone()
Get a new vector.
|
AbstractVector |
copy(AbstractVector vec)
Copies another vector
|
AbstractVector |
divide(AbstractVector vec)
Divides the vector by another.
|
double |
dot(AbstractVector other)
Calculates the dot product of this vector with another.
|
boolean |
equals(Object obj)
Checks to see if two objects are equal.
|
int |
getBlockX()
Gets the floored value of the X component, indicating the block that
this vector is contained with.
|
int |
getBlockY()
Gets the floored value of the Y component, indicating the block that
this vector is contained with.
|
int |
getBlockZ()
Gets the floored value of the Z component, indicating the block that
this vector is contained with.
|
static double |
getEpsilon()
Get the threshold used for equals().
|
double |
getX()
Gets the X component.
|
double |
getY()
Gets the Y component.
|
double |
getZ()
Gets the Z component.
|
int |
hashCode()
Returns a hash code for this vector
|
double |
length()
Gets the magnitude of the vector, defined as sqrt(x^2+y^2+z^2).
|
double |
lengthSquared()
Gets the magnitude of the vector squared.
|
AbstractVector |
multiply(AbstractVector vec)
Multiplies the vector by another.
|
AbstractVector |
multiply(double m)
Performs scalar multiplication, multiplying all components with a
scalar.
|
AbstractVector |
multiply(float m)
Performs scalar multiplication, multiplying all components with a
scalar.
|
AbstractVector |
multiply(int m)
Performs scalar multiplication, multiplying all components with a
scalar.
|
AbstractVector |
normalize()
Converts this vector to a unit vector (a vector with length of 1).
|
AbstractVector |
rotate(float degrees)
Rotates the vector a certain number of degrees.
|
AbstractVector |
setX(double x)
Set the X component.
|
AbstractVector |
setX(float x)
Set the X component.
|
AbstractVector |
setX(int x)
Set the X component.
|
AbstractVector |
setY(double y)
Set the Y component.
|
AbstractVector |
setY(float y)
Set the Y component.
|
AbstractVector |
setY(int y)
Set the Y component.
|
AbstractVector |
setZ(double z)
Set the Z component.
|
AbstractVector |
setZ(float z)
Set the Z component.
|
AbstractVector |
setZ(int z)
Set the Z component.
|
AbstractVector |
subtract(AbstractVector vec)
Subtracts a vector from this one.
|
AbstractLocation |
toLocation(AbstractWorld world)
Gets a Location version of this vector with yaw and pitch being 0.
|
AbstractLocation |
toLocation(AbstractWorld world,
float yaw,
float pitch)
Gets a Location version of this vector.
|
String |
toString()
Returns this vector's components as x,y,z.
|
public AbstractVector(int x, int y, int z)
x
- X componenty
- Y componentz
- Z componentpublic AbstractVector(double x, double y, double z)
x
- X componenty
- Y componentz
- Z componentpublic AbstractVector(float x, float y, float z)
x
- X componenty
- Y componentz
- Z componentpublic AbstractVector()
public AbstractVector add(AbstractVector vec)
vec
- The other vectorpublic AbstractVector subtract(AbstractVector vec)
vec
- The other vectorpublic AbstractVector multiply(AbstractVector vec)
vec
- The other vectorpublic AbstractVector multiply(int m)
m
- The factorpublic AbstractVector multiply(double m)
m
- The factorpublic AbstractVector multiply(float m)
m
- The factorpublic AbstractVector divide(AbstractVector vec)
vec
- The other vectorpublic AbstractVector copy(AbstractVector vec)
vec
- The other vectorpublic double length()
public double lengthSquared()
public double getX()
public int getBlockX()
public double getY()
public int getBlockY()
public double getZ()
public int getBlockZ()
public AbstractVector setX(int x)
x
- The new X component.public AbstractVector setX(double x)
x
- The new X component.public AbstractVector setX(float x)
x
- The new X component.public AbstractVector setY(int y)
y
- The new Y component.public AbstractVector setY(double y)
y
- The new Y component.public AbstractVector setY(float y)
y
- The new Y component.public AbstractVector setZ(int z)
z
- The new Z component.public AbstractVector setZ(double z)
z
- The new Z component.public AbstractVector setZ(float z)
z
- The new Z component.public AbstractVector normalize()
public AbstractVector rotate(float degrees)
public boolean equals(Object obj)
Only two Vectors can ever return true. This method uses a fuzzy match to account for floating point errors. The epsilon can be retrieved with epsilon.
public int hashCode()
public AbstractVector clone()
public String toString()
public AbstractLocation toLocation(AbstractWorld world)
world
- The world to link the location to.public AbstractLocation toLocation(AbstractWorld world, float yaw, float pitch)
world
- The world to link the location to.yaw
- The desired yaw.pitch
- The desired pitch.public static double getEpsilon()
public double dot(AbstractVector other)
other
- The other vectorpublic float angle(AbstractVector other)
other
- The other vectorCopyright © 2020. All rights reserved.