@ThreadSafe public class Vector extends Object implements Serializable, Cloneable
This class is essentially just 3 arbitrary values
Modifier and Type | Field and Description |
---|---|
protected double |
x |
protected double |
y |
protected double |
z |
Constructor and Description |
---|
Vector()
Creates a default vector with x, y, and z set to (0, 0, 0)
|
Vector(double x,
double y,
double z)
Creates a vector with the directional values set to the provided values
|
Vector(int x,
int y,
int z)
Creates a vector with the directional values set to the provided values
|
Modifier and Type | Method and Description |
---|---|
Vector |
add(double x,
double y,
double z)
Adds the coordinate values to the current vector's coordinates with double accuracy
|
Vector |
add(int x,
int y,
int z)
Adds the coordinate values to the current vector's coordinates
|
Vector |
add(Vector vector)
Adds the vector x, y, and z to the current vector coordinates
|
Position |
asLocation(World world)
Returns a new position in this world, with the coordinates the x, y, and z values
|
Vector |
clone()
Clones this Vector.
|
Vector |
crossProduct(Vector vector)
Sets the current vector to the crossproduct between this vector and another one
|
Vector |
divide(double amount)
Divides the magnitude of this vector by a given amount.
|
Vector |
divide(double x,
double y,
double z)
Takes the the current vector's coordinates and divides them from the coordinate values with double accuracy
|
Vector |
divide(int x,
int y,
int z)
Takes the the current vector's coordinates and divides them from the coordinate values
|
Vector |
divide(Vector vec)
Takes the current vector coordinates and divide them with the vector x, y, and z
|
double |
dotProduct(Vector vec)
Calculates the dot product of this vector and another
|
boolean |
equals(Object obj) |
int |
hashCode() |
double |
magnitude()
Gets the magnitude for this vector Note that this is an expensive operation, and if possible, you should use
magnitudeSquared() instead
|
double |
magnitudeSquared()
Gets the square of the magnitude of this vector
|
Vector |
multiply(double amount)
Multiplies the magnitude of this vector by a double
|
Vector |
multiply(double x,
double y,
double z)
Multiplies the coordinate values to the current vector's coordinates with double accuracy
|
Vector |
multiply(int x,
int y,
int z)
Multiplies the coordinate values to the current vector's coordinates
|
Vector |
multiply(Vector vec)
Multiplies the vector x, y, and z to the current vector coordinates
|
Vector |
normalize()
Normalizes this vector (changes the magnitude to 1 without changing the direction)
|
void |
setX(double x)
Sets this vector's x value
|
void |
setY(double y)
Sets this vector's y value
|
void |
setZ(double z)
Sets this vector's z value
|
Vector |
subtract(double x,
double y,
double z)
Takes the the current vector's coordinates and subtracts them from the coordinate values with double accuracy
|
Vector |
subtract(int x,
int y,
int z)
Takes the the current vector's coordinates and subtracts them from the coordinate values
|
Vector |
subtract(Vector vector)
Takes the current vector coordinates and subtract them with the vector x, y, and z
|
String |
toString() |
double |
x()
Gets the x directional-magnitude value
|
double |
y()
Gets the y directional-magnitude value
|
double |
z()
Gets the z directional-magnitude value
|
protected volatile double x
protected volatile double y
protected volatile double z
public Vector()
public Vector(double x, double y, double z)
x
- the x value of the vectory
- the y value of the vectorz
- the z value of the vectorpublic Vector(int x, int y, int z)
x
- the x value of the vectory
- the y value of the vectorz
- the z value of the vectorpublic Vector add(Vector vector)
vector
- the vector to retrieve the values to be addedpublic Vector add(double x, double y, double z)
x
- the x value of the vector to addy
- the y value of the vector to addz
- the z value of the vector to addpublic Vector add(int x, int y, int z)
x
- the x value of the vector to addy
- the y value of the vector to addz
- the z value of the vector to addpublic Vector subtract(Vector vector)
vector
- the vector to retrieve the values to be subtractedpublic Vector subtract(double x, double y, double z)
x
- the x value of the vector to subtracty
- the y value of the vector to subtractz
- the z value of the vector to subtractpublic Vector subtract(int x, int y, int z)
x
- the x value of the vector to subtracty
- the y value of the vector to subtractz
- the z value of the vector to subtractpublic Vector multiply(Vector vec)
vec
- the vector to retrieve the values to be multipliedpublic Vector multiply(double amount)
amount
- The amount to multiply bypublic Vector multiply(double x, double y, double z)
x
- the x value of the vector to multiplyy
- the y value of the vector to multiplyz
- the z value of the vector to multiplypublic Vector multiply(int x, int y, int z)
x
- the x value of the vector to multiplyy
- the y value of the vector to multiplyz
- the z value of the vector to multiplypublic Vector divide(Vector vec)
vec
- the vector to retrieve the values to be dividedpublic Vector divide(double amount)
amount
- The amount to divide bypublic Vector divide(double x, double y, double z)
x
- the x value of the vector to dividey
- the y value of the vector to dividez
- the z value of the vector to dividepublic Vector divide(int x, int y, int z)
x
- the x value of the vector to dividey
- the y value of the vector to dividez
- the z value of the vector to dividepublic Vector crossProduct(Vector vector)
vector
- the vector to crossproduct withpublic double magnitudeSquared()
public double magnitude()
public Vector normalize()
public double dotProduct(Vector vec)
vec
- the other vectorpublic Position asLocation(World world)
public double x()
public void setX(double x)
x
- the x value to set this vectorpublic double y()
public void setY(double y)
y
- the y value to set this vectorpublic double z()
public void setZ(double z)
z
- the z value to set this vectorCopyright © 2016. All rights reserved.