net.tridentsdk.util

## Class Vector

• All Implemented Interfaces:
Serializable, Cloneable
Direct Known Subclasses:
Position

```@ThreadSafe
public class Vector
extends Object
implements Serializable, Cloneable```
Just like in math, a vector represents magnitude and direction, where magnitude is usually the speed of an entity.

This class is essentially just 3 arbitrary values

Since:
0.3-alpha-DP
Author:
The TridentSDK Team
Serialized Form
• ### Field Summary

Fields
Modifier and Type Field and Description
`protected double` `x`
`protected double` `y`
`protected double` `z`
• ### Constructor Summary

Constructors
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
• ### Method Summary

All Methods
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
• ### Methods inherited from class java.lang.Object

`finalize, getClass, notify, notifyAll, wait, wait, wait`
• ### Field Detail

• #### x

`protected volatile double x`
• #### y

`protected volatile double y`
• #### z

`protected volatile double z`
• ### Constructor Detail

• #### Vector

`public Vector()`
Creates a default vector with x, y, and z set to (0, 0, 0)
• #### Vector

```public Vector(double x,
double y,
double z)```
Creates a vector with the directional values set to the provided values
Parameters:
`x` - the x value of the vector
`y` - the y value of the vector
`z` - the z value of the vector
• #### Vector

```public Vector(int x,
int y,
int z)```
Creates a vector with the directional values set to the provided values
Parameters:
`x` - the x value of the vector
`y` - the y value of the vector
`z` - the z value of the vector
• ### Method Detail

`public Vector add(Vector vector)`
Adds the vector x, y, and z to the current vector coordinates
Parameters:
`vector` - the vector to retrieve the values to be added
Returns:
the current vector with updated coordinates

```public Vector add(double x,
double y,
double z)```
Adds the coordinate values to the current vector's coordinates with double accuracy
Parameters:
`x` - the x value of the vector to add
`y` - the y value of the vector to add
`z` - the z value of the vector to add
Returns:
the current vector with updated coordinates

```public Vector add(int x,
int y,
int z)```
Adds the coordinate values to the current vector's coordinates
Parameters:
`x` - the x value of the vector to add
`y` - the y value of the vector to add
`z` - the z value of the vector to add
Returns:
the current vector with updated coordinates
• #### subtract

`public Vector subtract(Vector vector)`
Takes the current vector coordinates and subtract them with the vector x, y, and z
Parameters:
`vector` - the vector to retrieve the values to be subtracted
Returns:
the current vector with updated coordinates
• #### subtract

```public 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
Parameters:
`x` - the x value of the vector to subtract
`y` - the y value of the vector to subtract
`z` - the z value of the vector to subtract
Returns:
the current vector with updated coordinates
• #### subtract

```public Vector subtract(int x,
int y,
int z)```
Takes the the current vector's coordinates and subtracts them from the coordinate values
Parameters:
`x` - the x value of the vector to subtract
`y` - the y value of the vector to subtract
`z` - the z value of the vector to subtract
Returns:
the current vector with updated coordinates
• #### multiply

`public Vector multiply(Vector vec)`
Multiplies the vector x, y, and z to the current vector coordinates
Parameters:
`vec` - the vector to retrieve the values to be multiplied
Returns:
the current vector with updated coordinates
• #### multiply

`public Vector multiply(double amount)`
Multiplies the magnitude of this vector by a double
Parameters:
`amount` - The amount to multiply by
Returns:
This vector, with updated coordinates
• #### multiply

```public Vector multiply(double x,
double y,
double z)```
Multiplies the coordinate values to the current vector's coordinates with double accuracy
Parameters:
`x` - the x value of the vector to multiply
`y` - the y value of the vector to multiply
`z` - the z value of the vector to multiply
Returns:
the current vector with updated coordinates
• #### multiply

```public Vector multiply(int x,
int y,
int z)```
Multiplies the coordinate values to the current vector's coordinates
Parameters:
`x` - the x value of the vector to multiply
`y` - the y value of the vector to multiply
`z` - the z value of the vector to multiply
Returns:
the current vector with updated coordinates
• #### divide

`public Vector divide(Vector vec)`
Takes the current vector coordinates and divide them with the vector x, y, and z
Parameters:
`vec` - the vector to retrieve the values to be divided
Returns:
the current vector with updated coordinates
• #### divide

`public Vector divide(double amount)`
Divides the magnitude of this vector by a given amount.
Parameters:
`amount` - The amount to divide by
Returns:
this vector
• #### divide

```public 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
Parameters:
`x` - the x value of the vector to divide
`y` - the y value of the vector to divide
`z` - the z value of the vector to divide
Returns:
the current vector with updated coordinates
• #### divide

```public Vector divide(int x,
int y,
int z)```
Takes the the current vector's coordinates and divides them from the coordinate values
Parameters:
`x` - the x value of the vector to divide
`y` - the y value of the vector to divide
`z` - the z value of the vector to divide
Returns:
the current vector with updated coordinates
• #### crossProduct

`public Vector crossProduct(Vector vector)`
Sets the current vector to the crossproduct between this vector and another one
Parameters:
`vector` - the vector to crossproduct with
Returns:
this vector, updated with the crossproduct with the other vector
• #### magnitudeSquared

`public double magnitudeSquared()`
Gets the square of the magnitude of this vector
Returns:
The magnitude of this vector, squared
• #### magnitude

`public double magnitude()`
Gets the magnitude for this vector Note that this is an expensive operation, and if possible, you should use magnitudeSquared() instead
Returns:
The magnitude of this vector
• #### normalize

`public Vector normalize()`
Normalizes this vector (changes the magnitude to 1 without changing the direction)
Returns:
This vector
• #### dotProduct

`public double dotProduct(Vector vec)`
Calculates the dot product of this vector and another
Parameters:
`vec` - the other vector
Returns:
dot product of the two vectors
• #### asLocation

`public Position asLocation(World world)`
Returns a new position in this world, with the coordinates the x, y, and z values
• #### x

`public double x()`
Gets the x directional-magnitude value
Returns:
the vector x value
• #### setX

`public void setX(double x)`
Sets this vector's x value
Parameters:
`x` - the x value to set this vector
• #### y

`public double y()`
Gets the y directional-magnitude value
Returns:
the vector y value
• #### setY

`public void setY(double y)`
Sets this vector's y value
Parameters:
`y` - the y value to set this vector
• #### z

`public double z()`
Gets the z directional-magnitude value
Returns:
the vector z value
• #### setZ

`public void setZ(double z)`
Sets this vector's z value
Parameters:
`z` - the z value to set this vector
• #### clone

`public Vector clone()`
Clones this Vector.
Overrides:
`clone` in class `Object`
Returns:
the cloned vector
• #### equals

`public boolean equals(Object obj)`
Overrides:
`equals` in class `Object`
• #### hashCode

`public int hashCode()`
Overrides:
`hashCode` in class `Object`
• #### toString

`public String toString()`
Overrides:
`toString` in class `Object`