Class Vector3d
java.lang.Object
net.risingworld.api.utils.Vector3d
- All Implemented Interfaces:
Serializable
A Vector which holds three double values: X, Y and Z
It can be used to represent a three dimensional value, like a position or a direction.
Note that this explicitly uses 64 bit values (double precision). For regular calculations you should use
It can be used to represent a three dimensional value, like a position or a direction.
Note that this explicitly uses 64 bit values (double precision). For regular calculations you should use
Vector3f instead!- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Vector3dA unit vector along the -Z axis (backward direction)static final Vector3dA unit vector along the -Y axis (down direction)static final Vector3dA unit vector along the Z axis (forward direction)static final Vector3dA unit vector along the -X axis (left direction)static final Vector3dA vector with values 1, 1, 1static final Vector3dA unit vector along the X axis (right direction)static final Vector3dA unit vector along the Y axis (up direction)doubleThe X value of this vectordoubleThe Y value of this vectordoubleThe Z value of this vectorstatic final Vector3dA vector with values 0, 0, 0 -
Constructor Summary
ConstructorsConstructorDescriptionVector3d()Creates a new vector with default values 0, 0, 0.Vector3d(double x, double y, double z) Creates a new vector with the provided values.Creates a new vector and copies the X, Y and Z values from the provided vector.Creates a new vector and copies the X, Y and Z values from the provided vector. -
Method Summary
Modifier and TypeMethodDescriptionadd(double addX, double addY, double addZ) Creates a new vector with the same values of this vector and adds the provided values.Creates a new vector with the same values of this vector and adds the values of the provided vector.addLocal(double addX, double addY, double addZ) Adds the provided values to the values of this vector.Adds the values of the provided vector to the values of this vector.doubleangleBetween(Vector3d other) Gets the angle between this vector and another vector.copy()Creates a copy of this vector.Creates a new vector containing the cross product of this vector and another vector.crossLocal(double v2x, double v2y, double v2z) Calculates the cross product of this vector and the provided coordinates.crossLocal(Vector3d other) Calculates the cross product of this vector and another vector.doubledistance(double x, double y, double z) Gets the distance between this vector and the provided coordinates.doubleGets the distance between this vector and another vector.doubledistanceSquared(double x, double y, double z) Gets the squared distance between this vector and the provided coordinates.doubledistanceSquared(Vector3d other) Gets the squared distance between this vector and another Vector3d.Creates a new vector with the same values of this vector and divides the values of the provided vector.divideLocal(double scalar) divideLocal(Vector3d other) doubledot(double x, double y, double z) Gets the dot product of this vector with the provided coordinates.doubleGets the dot product of this vector with the provided vector.booleanequals(double x, double y, double z) booleanGets whether or not this vector is equal to another object.fromString(String input) doublegetX()Returns the x value of this vector.doublegetY()Returns the y value of this vector.doublegetZ()Returns the z value of this vector.inthashCode()Gets a unique* hash code for this vector, based on its values.interpolate(Vector3d startVector, Vector3d finalVector, double mu) Creates a new vector containing the interpolated values between the start vector and the final vector.interpolateLocal(Vector3d finalVector, double mu) Interpolates this vector to the provided final vector, e.g if this vector is (0, 5, 10), and the final vector is (-10, 0, 10), the result (by using a mu-value of 0.5d) would be (-5, 2.5, 10)interpolateLocal(Vector3d startVector, Vector3d finalVector, double mu) Interpolates between the provided start and end vector and stores the result in this vector.booleanisOrthogonal(double x, double y, double z) Checks if this vector is orthogonal to another vector (i.e the angle between both vectors is ~ 90° degree).booleanisOrthogonal(Vector3d other) Checks if this vector is orthogonal to another vector (i.e the angle between both vectors is ~ 90° degree).booleanChecks if this vector is a unit vector.doublelength()Gets the length of this vector.doubleGets the squared length of this vector.mult(double scalar) Creates a new vector with the same values of this vector and multiplies them with the provided scalar.mult(double multX, double multY, double multZ) Creates a new vector with the same values of this vector and multiplies the provided values.Creates a new vector with the same values of this vector and multiplies the values of the provided vector.multLocal(double scalar) Multiplies the values of this vector with the provided scalar.multLocal(double multX, double multY, double multZ) Multiplies the values of this vector with the provided values.Multiplies the values of this vector with the values of the provided vector.negate()Creates a new vector which contains negated values of this vector.Negates all values of this vector.Creates a new vector containing normalized values of this vector (i.e as a unit vector).Normalizes this vector (i.e turn it into a unit vector).set(double x, double y, double z) Sets the x, y and z values of this vector to the provided values.Sets the x, y and z values of this vector to the values of the provided vector.Sets the x, y and z values of this vector to the values of the provided vector.setX(double x) Sets the x value of this vector.setY(double y) Sets the y value of this vector.setZ(double z) Sets the z value of this vector.subtract(double subtractX, double subtractY, double subtractZ) Creates a new vector with the same values of this vector and subtracts the provided values.Creates a new vector with the same values of this vector and subtracts the values of the provided vector.subtractLocal(double subtractX, double subtractY, double subtractZ) Subtracts the provided values from the values of this vector.subtractLocal(Vector3d other) Subtracts the values of the provided vector from the values of this vector.toString()Gets a String representation of this vector, for example(4.0, 5.25, 10.998)
-
Field Details
-
ZERO
A vector with values 0, 0, 0 -
ONE
A vector with values 1, 1, 1 -
RIGHT
A unit vector along the X axis (right direction) -
LEFT
A unit vector along the -X axis (left direction) -
UP
A unit vector along the Y axis (up direction) -
DOWN
A unit vector along the -Y axis (down direction) -
FORWARD
A unit vector along the Z axis (forward direction) -
BACK
A unit vector along the -Z axis (backward direction) -
x
public double xThe X value of this vector -
y
public double yThe Y value of this vector -
z
public double zThe Z value of this vector
-
-
Constructor Details
-
Vector3d
public Vector3d()Creates a new vector with default values 0, 0, 0. -
Vector3d
public Vector3d(double x, double y, double z) Creates a new vector with 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.
-
Vector3d
Creates a new vector and copies the X, Y and Z values from the provided vector.- Parameters:
copy- the Vector3d to copy.
-
Vector3d
Creates a new vector and copies the X, Y and Z values from the provided vector.- Parameters:
copy- the Vector3f to copy.
-
-
Method Details
-
copy
Creates a copy of this vector.- Returns:
- a new instance with the same values of this vector.
-
set
-
set
-
set
Sets the x, y and z values of this vector to the provided values.- Parameters:
x- the x value.y- the y value.z- the z value.- Returns:
- this vector.
-
setX
Sets the x value of this vector.- Parameters:
x- the new x value.- Returns:
- this vector.
-
setY
Sets the y value of this vector.- Parameters:
y- the new y value.- Returns:
- this vector.
-
setZ
Sets the z value of this vector.- Parameters:
z- the new z value.- Returns:
- this vector.
-
getX
public double getX()Returns the x value of this vector.- Returns:
- the current x value.
-
getY
public double getY()Returns the y value of this vector.- Returns:
- the current y value.
-
getZ
public double getZ()Returns the z value of this vector.- Returns:
- the current z value.
-
dot
Gets the dot product of this vector with the provided vector.- Parameters:
other- the vector to calculate the dot product with.- Returns:
- the resulting dot product.
-
dot
public double dot(double x, double y, double z) Gets the dot product of this vector with the provided coordinates.- Parameters:
x- the x coordinate.y- the y coordinate.z- the z coordinate.- Returns:
- the resulting dot product.
-
length
public double length()Gets the length of this vector.- Returns:
- the length of this vector.
- See Also:
-
lengthSquared
public double lengthSquared()Gets the squared length of this vector. Use this function to avoid calculating the squareroot.- Returns:
- the squared length of this vector.
- See Also:
-
distance
Gets the distance between this vector and another vector.- Parameters:
other- the other vector.- Returns:
- the distance between this vector and another vector.
- See Also:
-
distance
public double distance(double x, double y, double z) Gets the distance between this vector and the provided coordinates.- Parameters:
x- the other x coordinate.y- the other y coordinate.z- the other z coordinate.- Returns:
- the distance between this vector and the provided coordinates.
- See Also:
-
distanceSquared
Gets the squared distance between this vector and another Vector3d. Use this function to avoid calculating the squareroot.- Parameters:
other- the other Vector3d.- Returns:
- the squared distance between this vector and the provided Vector3d.
-
distanceSquared
public double distanceSquared(double x, double y, double z) Gets the squared distance between this vector and the provided coordinates. Use this function to avoid calculating the squareroot.- Parameters:
x- the other x coordinate.y- the other y coordinate.z- the other z coordinate.- Returns:
- the squared distance between this vector and the provided coordinates.
-
add
-
add
Creates a new vector with the same values of this vector and adds the provided values. Same asnew Vector3d(this).addLocal(x, y, z);- Parameters:
addX- the x value to add.addY- the y value to add.addZ- the z value to add.- Returns:
- the newly created vector.
-
addLocal
-
addLocal
Adds the provided values to the values of this vector.- Parameters:
addX- the x value to add.addY- the y value to add.addZ- the z value to add.- Returns:
- this vector.
-
subtract
-
subtract
Creates a new vector with the same values of this vector and subtracts the provided values. Same asnew Vector3d(this).subtractLocal(x, y, z);- Parameters:
subtractX- the x value to subtract.subtractY- the y value to subtract.subtractZ- the z value to subtract.- Returns:
- the newly created vector.
-
subtractLocal
-
subtractLocal
Subtracts the provided values from the values of this vector.- Parameters:
subtractX- the x value to subtract.subtractY- the y value to subtract.subtractZ- the z value to subtract.- Returns:
- this vector.
-
mult
Creates a new vector with the same values of this vector and multiplies them with the provided scalar.- Parameters:
scalar- the value to multiply the vector by.- Returns:
- the newly created vector.
-
mult
-
mult
Creates a new vector with the same values of this vector and multiplies the provided values. Same asnew Vector3d(this).multLocal(x, y, z);- Parameters:
multX- the x value to multiply.multY- the y value to multiply.multZ- the z value to multiply.- Returns:
- the newly created vector.
-
multLocal
Multiplies the values of this vector with the provided scalar.- Parameters:
scalar- the value to multiply this vector by.- Returns:
- this vector.
-
multLocal
-
multLocal
Multiplies the values of this vector with the provided values.- Parameters:
multX- the x value to multiply the x coordinate of this vector by.multY- the y value to multiply the y coordinate of this vector by.multZ- the z value to multiply the z coordinate of this vector by.- Returns:
- this vector.
-
divide
-
divideLocal
-
divideLocal
-
negate
Creates a new vector which contains negated values of this vector.- Returns:
- the newly created vector.
-
negateLocal
-
cross
-
crossLocal
-
crossLocal
Calculates the cross product of this vector and the provided coordinates.- Parameters:
v2x- the other x coordinate.v2y- the other y coordinate.v2z- the other z coordinate.- Returns:
- this vector.
-
normalize
Creates a new vector containing normalized values of this vector (i.e as a unit vector).- Returns:
- a newly created, normalized vector.
-
normalizeLocal
Normalizes this vector (i.e turn it into a unit vector).- Returns:
- this vector (normalized).
-
angleBetween
Gets the angle between this vector and another vector.- Parameters:
other- the other vector (unit vector).- Returns:
- the angle in degrees.
-
isUnitVector
public boolean isUnitVector()Checks if this vector is a unit vector.- Returns:
- true if this is a unit vector, false if not.
-
isOrthogonal
Checks if this vector is orthogonal to another vector (i.e the angle between both vectors is ~ 90° degree).- Parameters:
other- the other vector.- Returns:
- true if this vector is orthogonal to the other vector, false if not.
-
isOrthogonal
public boolean isOrthogonal(double x, double y, double z) Checks if this vector is orthogonal to another vector (i.e the angle between both vectors is ~ 90° degree).- Parameters:
x- the x coordinate of the other vector.y- the y coordinate of the other vector.z- the z coordinate of the other vector.- Returns:
- true if this vector is orthogonal to the other vector, false if not.
-
interpolateLocal
Interpolates this vector to the provided final vector, e.g if this vector is (0, 5, 10), and the final vector is (-10, 0, 10), the result (by using a mu-value of 0.5d) would be (-5, 2.5, 10)- Parameters:
finalVector- the final vector to interpolate towards.mu- the mu value between 0.0 and 1.0 (i.e the percentage change from this vector to towards the final vector).- Returns:
- this vector containing the interpolated values.
-
interpolateLocal
Interpolates between the provided start and end vector and stores the result in this vector.- Parameters:
startVector- the start vector to interpolate from.finalVector- the final vector to interpolate towards.mu- the mu value between 0.0 and 1.0 (i.e the percentage change from the start vector to towards the final vector).- Returns:
- this vector containing the interpolated values.
-
interpolate
Creates a new vector containing the interpolated values between the start vector and the final vector.- Parameters:
startVector- the start vector to interpolate from.finalVector- the final vector to interpolate towards.mu- the mu value between 0.0 and 1.0 (i.e the percentage change from the start vector to towards the final vector).- Returns:
- a new vector containing the interpolated values.
-
equals
Gets whether or not this vector is equal to another object. This function returns true, if the other object is aVector3dand if it has exactly the same x, y and z values. -
equals
public boolean equals(double x, double y, double z) -
hashCode
public int hashCode()Gets a unique* hash code for this vector, based on its values. If two vectors have the same x, y and z values, they will return the same hash code.
* Please keep in mind that the uniqueness is not fully reliable. There is always a small chance that collisions occur (i.e two completely different vectors return the same hash code). But usually the reliability is sufficient. -
toString
-
fromString
-