Class Vector
- All Implemented Interfaces:
- Cloneable,- ConfigurationSerializable
- Direct Known Subclasses:
- BlockVector
clone() in order to get a copy.- 
Field SummaryFields
- 
Constructor SummaryConstructorsConstructorDescriptionVector()Construct the vector with all components as 0.Vector(double x, double y, double z) Construct the vector with provided double components.Vector(float x, float y, float z) Construct the vector with provided float components.Vector(int x, int y, int z) Construct the vector with provided integer components.
- 
Method SummaryModifier and TypeMethodDescriptionAdds a vector to this onefloatGets the angle between this vector and another in radians.voidCheck if each component of this Vector is finite.clone()Get a new vector.Copies another vectorCalculates the cross product of this vector with another.deserialize(@NotNull Map<String, Object> args) doubleGet the distance between this vector and another.doubleGet the squared distance between this vector and another.Divides the vector by another.doubleCalculates the dot product of this vector with another.booleanChecks to see if two objects are equal.Gets a vector with components that match the provided JOMLVector3d.Gets a vector with components that match the provided JOMLVector3f.Gets a vector with components that match the provided JOMLVector3i.intGets the floored value of the X component, indicating the block that this vector is contained with.intGets the floored value of the Y component, indicating the block that this vector is contained with.intGets the floored value of the Z component, indicating the block that this vector is contained with.Calculates the cross product of this vector with another without mutating the original.static doubleGet the threshold used for equals().getMaximum(@NotNull Vector v1, @NotNull Vector v2) Gets the maximum components of two vectors.getMidpoint(@NotNull Vector other) Gets a new midpoint vector between this vector and another.getMinimum(@NotNull Vector v1, @NotNull Vector v2) Gets the minimum components of two vectors.Gets a random vector with components having a random value between 0 and 1.doublegetX()Gets the X component.doublegetY()Gets the Y component.doublegetZ()Gets the Z component.inthashCode()Returns a hash code for this vectorbooleanReturns whether this vector is in an axis-aligned bounding box.booleanisInSphere(@NotNull Vector origin, double radius) Returns whether this vector is within a sphere.booleanReturns if a vector is normalizedbooleanisZero()Check whether or not each component of this vector is equal to 0.doublelength()Gets the magnitude of the vector, defined as sqrt(x^2+y^2+z^2).doubleGets the magnitude of the vector squared.Sets this vector to the midpoint between this vector and another.multiply(double m) Performs scalar multiplication, multiplying all components with a scalar.multiply(float m) Performs scalar multiplication, multiplying all components with a scalar.multiply(int m) Performs scalar multiplication, multiplying all components with a scalar.Multiplies the vector by another.Converts this vector to a unit vector (a vector with length of 1).rotateAroundAxis(@NotNull Vector axis, double angle) Rotates the vector around a given arbitrary axis in 3 dimensional space.rotateAroundNonUnitAxis(@NotNull Vector axis, double angle) Rotates the vector around a given arbitrary axis in 3 dimensional space.rotateAroundX(double angle) Rotates the vector around the x axis.rotateAroundY(double angle) Rotates the vector around the y axis.rotateAroundZ(double angle) Rotates the vector around the z axisCreates a Map representation of this class.setX(double x) Set the X component.setX(float x) Set the X component.setX(int x) Set the X component.setY(double y) Set the Y component.setY(float y) Set the Y component.setY(int y) Set the Y component.setZ(double z) Set the Z component.setZ(float z) Set the Z component.setZ(int z) Set the Z component.Subtracts a vector from this one.Get the block vector of this vector.toLocation(@NotNull World world) Gets a Location version of this vector with yaw and pitch being 0.toLocation(@NotNull World world, float yaw, float pitch) Gets a Location version of this vector.toString()Returns this vector's components as x,y,z.@NotNull org.joml.Vector3dGet this vector as a JOMLVector3d.@NotNull org.joml.Vector3fGet this vector as a JOMLVector3f.@NotNull org.joml.Vector3iGet this vector as a JOMLVector3iwith its components floored.@NotNull org.joml.Vector3itoVector3i(int roundingMode) Get this vector as a JOMLVector3i.zero()Zero this vector's components.
- 
Field Details- 
xprotected double x
- 
yprotected double y
- 
zprotected double z
 
- 
- 
Constructor Details- 
Vectorpublic Vector()Construct the vector with all components as 0.
- 
Vectorpublic Vector(int x, int y, int z) Construct the vector with provided integer components.- Parameters:
- x- X component
- y- Y component
- z- Z component
 
- 
Vectorpublic Vector(double x, double y, double z) Construct the vector with provided double components.- Parameters:
- x- X component
- y- Y component
- z- Z component
 
- 
Vectorpublic Vector(float x, float y, float z) Construct the vector with provided float components.- Parameters:
- x- X component
- y- Y component
- z- Z component
 
 
- 
- 
Method Details- 
addAdds a vector to this one- Parameters:
- vec- The other vector
- Returns:
- the same vector
 
- 
subtractSubtracts a vector from this one.- Parameters:
- vec- The other vector
- Returns:
- the same vector
 
- 
multiplyMultiplies the vector by another.- Parameters:
- vec- The other vector
- Returns:
- the same vector
 
- 
divideDivides the vector by another.- Parameters:
- vec- The other vector
- Returns:
- the same vector
 
- 
copyCopies another vector- Parameters:
- vec- The other vector
- Returns:
- the same vector
 
- 
lengthpublic double length()Gets the magnitude of the vector, defined as sqrt(x^2+y^2+z^2). The value of this method is not cached and uses a costly square-root function, so do not repeatedly call this method to get the vector's magnitude. NaN will be returned if the inner result of the sqrt() function overflows, which will be caused if the length is too long.- Returns:
- the magnitude
 
- 
lengthSquaredpublic double lengthSquared()Gets the magnitude of the vector squared.- Returns:
- the magnitude
 
- 
distanceGet the distance between this vector and another. The value of this method is not cached and uses a costly square-root function, so do not repeatedly call this method to get the vector's magnitude. NaN will be returned if the inner result of the sqrt() function overflows, which will be caused if the distance is too long.- Parameters:
- o- The other vector
- Returns:
- the distance
 
- 
distanceSquaredGet the squared distance between this vector and another.- Parameters:
- o- The other vector
- Returns:
- the distance
 
- 
angleGets the angle between this vector and another in radians.- Parameters:
- other- The other vector
- Returns:
- angle in radians
 
- 
midpointSets this vector to the midpoint between this vector and another.- Parameters:
- other- The other vector
- Returns:
- this same vector (now a midpoint)
 
- 
getMidpointGets a new midpoint vector between this vector and another.- Parameters:
- other- The other vector
- Returns:
- a new midpoint vector
 
- 
multiplyPerforms scalar multiplication, multiplying all components with a scalar.- Parameters:
- m- The factor
- Returns:
- the same vector
 
- 
multiplyPerforms scalar multiplication, multiplying all components with a scalar.- Parameters:
- m- The factor
- Returns:
- the same vector
 
- 
multiplyPerforms scalar multiplication, multiplying all components with a scalar.- Parameters:
- m- The factor
- Returns:
- the same vector
 
- 
dotCalculates the dot product of this vector with another. The dot product is defined as x1*x2+y1*y2+z1*z2. The returned value is a scalar.- Parameters:
- other- The other vector
- Returns:
- dot product
 
- 
crossProductCalculates the cross product of this vector with another. The cross product is defined as:- x = y1 * z2 - y2 * z1
- y = z1 * x2 - z2 * x1
- z = x1 * y2 - x2 * y1
 - Parameters:
- o- The other vector
- Returns:
- the same vector
 
- 
getCrossProductCalculates the cross product of this vector with another without mutating the original. The cross product is defined as:- x = y1 * z2 - y2 * z1
- y = z1 * x2 - z2 * x1
- z = x1 * y2 - x2 * y1
 - Parameters:
- o- The other vector
- Returns:
- a new vector
 
- 
normalizeConverts this vector to a unit vector (a vector with length of 1).- Returns:
- the same vector
 
- 
zeroZero this vector's components.- Returns:
- the same vector
 
- 
isZeropublic boolean isZero()Check whether or not each component of this vector is equal to 0.- Returns:
- true if equal to zero, false if at least one component is non-zero
 
- 
isInAABBReturns whether this vector is in an axis-aligned bounding box.The minimum and maximum vectors given must be truly the minimum and maximum X, Y and Z components. - Parameters:
- min- Minimum vector
- max- Maximum vector
- Returns:
- whether this vector is in the AABB
 
- 
isInSphereReturns whether this vector is within a sphere.- Parameters:
- origin- Sphere origin.
- radius- Sphere radius
- Returns:
- whether this vector is in the sphere
 
- 
isNormalizedpublic boolean isNormalized()Returns if a vector is normalized- Returns:
- whether the vector is normalised
 
- 
rotateAroundXRotates the vector around the x axis.This piece of math is based on the standard rotation matrix for vectors in three dimensional space. This matrix can be found here: Rotation Matrix. - Parameters:
- angle- the angle to rotate the vector about. This angle is passed in radians
- Returns:
- the same vector
 
- 
rotateAroundYRotates the vector around the y axis.This piece of math is based on the standard rotation matrix for vectors in three dimensional space. This matrix can be found here: Rotation Matrix. - Parameters:
- angle- the angle to rotate the vector about. This angle is passed in radians
- Returns:
- the same vector
 
- 
rotateAroundZRotates the vector around the z axisThis piece of math is based on the standard rotation matrix for vectors in three dimensional space. This matrix can be found here: Rotation Matrix. - Parameters:
- angle- the angle to rotate the vector about. This angle is passed in radians
- Returns:
- the same vector
 
- 
rotateAroundAxis@NotNull public @NotNull Vector rotateAroundAxis(@NotNull @NotNull Vector axis, double angle) throws IllegalArgumentException Rotates the vector around a given arbitrary axis in 3 dimensional space.Rotation will follow the general Right-Hand-Rule, which means rotation will be counterclockwise when the axis is pointing towards the observer. This method will always make sure the provided axis is a unit vector, to not modify the length of the vector when rotating. If you are experienced with the scaling of a non-unit axis vector, you can use rotateAroundNonUnitAxis(Vector, double).- Parameters:
- axis- the axis to rotate the vector around. If the passed vector is not of length 1, it gets copied and normalized before using it for the rotation. Please use- normalize()on the instance before passing it to this method
- angle- the angle to rotate the vector around the axis
- Returns:
- the same vector
- Throws:
- IllegalArgumentException- if the provided axis vector instance is null
 
- 
rotateAroundNonUnitAxis@NotNull public @NotNull Vector rotateAroundNonUnitAxis(@NotNull @NotNull Vector axis, double angle) throws IllegalArgumentException Rotates the vector around a given arbitrary axis in 3 dimensional space.Rotation will follow the general Right-Hand-Rule, which means rotation will be counterclockwise when the axis is pointing towards the observer. Note that the vector length will change accordingly to the axis vector length. If the provided axis is not a unit vector, the rotated vector will not have its previous length. The scaled length of the resulting vector will be related to the axis vector. If you are not perfectly sure about the scaling of the vector, use rotateAroundAxis(Vector, double)- Parameters:
- axis- the axis to rotate the vector around.
- angle- the angle to rotate the vector around the axis
- Returns:
- the same vector
- Throws:
- IllegalArgumentException- if the provided axis vector instance is null
 
- 
getXpublic double getX()Gets the X component.- Returns:
- The X component.
 
- 
getBlockXpublic int getBlockX()Gets the floored value of the X component, indicating the block that this vector is contained with.- Returns:
- block X
 
- 
getYpublic double getY()Gets the Y component.- Returns:
- The Y component.
 
- 
getBlockYpublic int getBlockY()Gets the floored value of the Y component, indicating the block that this vector is contained with.- Returns:
- block y
 
- 
getZpublic double getZ()Gets the Z component.- Returns:
- The Z component.
 
- 
getBlockZpublic int getBlockZ()Gets the floored value of the Z component, indicating the block that this vector is contained with.- Returns:
- block z
 
- 
setXSet the X component.- Parameters:
- x- The new X component.
- Returns:
- This vector.
 
- 
setXSet the X component.- Parameters:
- x- The new X component.
- Returns:
- This vector.
 
- 
setXSet the X component.- Parameters:
- x- The new X component.
- Returns:
- This vector.
 
- 
setYSet the Y component.- Parameters:
- y- The new Y component.
- Returns:
- This vector.
 
- 
setYSet the Y component.- Parameters:
- y- The new Y component.
- Returns:
- This vector.
 
- 
setYSet the Y component.- Parameters:
- y- The new Y component.
- Returns:
- This vector.
 
- 
setZSet the Z component.- Parameters:
- z- The new Z component.
- Returns:
- This vector.
 
- 
setZSet the Z component.- Parameters:
- z- The new Z component.
- Returns:
- This vector.
 
- 
setZSet the Z component.- Parameters:
- z- The new Z component.
- Returns:
- This vector.
 
- 
equalsChecks to see if two objects are equal.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. 
- 
hashCodepublic int hashCode()Returns a hash code for this vector
- 
cloneGet a new vector.
- 
toStringReturns this vector's components as x,y,z.
- 
toLocationGets a Location version of this vector with yaw and pitch being 0.- Parameters:
- world- The world to link the location to.
- Returns:
- the location
 
- 
toLocationGets a Location version of this vector.- Parameters:
- world- The world to link the location to.
- yaw- The desired yaw.
- pitch- The desired pitch.
- Returns:
- the location
 
- 
toBlockVectorGet the block vector of this vector.- Returns:
- A block vector.
 
- 
toVector3fGet this vector as a JOMLVector3f.- Returns:
- the JOML vector
 
- 
toVector3dGet this vector as a JOMLVector3d.- Returns:
- the JOML vector
 
- 
toVector3iGet this vector as a JOMLVector3i.- Parameters:
- roundingMode- the- RoundingModeto use for this vector's components
- Returns:
- the JOML vector
 
- 
toVector3iGet this vector as a JOMLVector3iwith its components floored.- Returns:
- the JOML vector
- See Also:
 
- 
checkFiniteCheck if each component of this Vector is finite.- Throws:
- IllegalArgumentException- if any component is not finite
 
- 
getEpsilonpublic static double getEpsilon()Get the threshold used for equals().- Returns:
- The epsilon.
 
- 
getMinimum@NotNull public static @NotNull Vector getMinimum(@NotNull @NotNull Vector v1, @NotNull @NotNull Vector v2) Gets the minimum components of two vectors.- Parameters:
- v1- The first vector.
- v2- The second vector.
- Returns:
- minimum
 
- 
getMaximum@NotNull public static @NotNull Vector getMaximum(@NotNull @NotNull Vector v1, @NotNull @NotNull Vector v2) Gets the maximum components of two vectors.- Parameters:
- v1- The first vector.
- v2- The second vector.
- Returns:
- maximum
 
- 
getRandomGets a random vector with components having a random value between 0 and 1.- Returns:
- A random vector.
 
- 
fromJOMLGets a vector with components that match the provided JOMLVector3f.- Parameters:
- vector- the vector to match
- Returns:
- the new vector
 
- 
fromJOMLGets a vector with components that match the provided JOMLVector3d.- Parameters:
- vector- the vector to match
- Returns:
- the new vector
 
- 
fromJOMLGets a vector with components that match the provided JOMLVector3i.- Parameters:
- vector- the vector to match
- Returns:
- the new vector
 
- 
serializeDescription copied from interface:ConfigurationSerializableCreates a Map representation of this class.This class must provide a method to restore this class, as defined in the ConfigurationSerializableinterface javadocs.- Specified by:
- serializein interface- ConfigurationSerializable
- Returns:
- Map containing the current state of this class
 
- 
deserialize
 
-