Package com.sk89q.worldedit.math
Class Vector3
java.lang.Object
com.sk89q.worldedit.math.Vector3
- Direct Known Subclasses:
MutableVector3
,Vector3Impl
An immutable 3-dimensional vector.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionabs()
Returns a vector with the absolute values of the components of this vector.add
(double x, double y, double z) Add another vector to this vector and return the result as a new vector.Add another vector to this vector and return the result as a new vector.Add a list of vectors to this vector and return the result as a new vector.static Vector3
at
(double x, double y, double z) int
blockX()
Get the X coordinate, aligned to the block grid.int
blockY()
Get the Y coordinate, aligned to the block grid.int
blockZ()
Get the Z coordinate, aligned to the block grid.ceil()
Rounds all components up.clampY
(int min, int max) Clamp the Y component.boolean
containedWithin
(Vector3 min, Vector3 max) Checks to see if a vector is contained with another.Gets the cross product of this and another vector.double
Get the distance between this vector and another vector.double
distanceSq
(Vector3 other) Get the distance between this vector and another vector, squared.divide
(double n) Perform scalar division and return a new vector.divide
(double x, double y, double z) Divide this vector by another vector on each component.Divide this vector by another vector on each component.double
Gets the dot product of this and another vector.boolean
boolean
equalsFuzzy
(Vector3 other) Tests if vectors are equal, accounting for floating point errorsfloor()
Floors the values of all components.int
Gets the x coordinate rounded, accounting for negative coordinatesint
Gets the y coordinate rounded, accounting for negative coordinatesint
Gets the z coordinate rounded, accounting for negative coordinatesgetMaximum
(Vector3 v2) Gets the maximum components of two vectors.getMinimum
(Vector3 v2) Gets the minimum components of two vectors.double
getX()
Deprecated, for removal: This API element is subject to removal in a future version.double
getY()
Deprecated, for removal: This API element is subject to removal in a future version.usey()
insteaddouble
getZ()
Deprecated, for removal: This API element is subject to removal in a future version.usez()
insteadint
hashCode()
double
length()
Get the length of the vector.double
lengthSq()
Get the length, squared, of the vector.multiply
(double n) Perform scalar multiplication and return a new vector.multiply
(double x, double y, double z) Multiply this vector by another vector on each component.Multiply this vector by another vector on each component.Multiply this vector by zero or more vectors on each component.mutX
(double x) mutX
(int x) mutY
(double y) mutY
(int y) mutZ
(double z) mutZ
(int z) Get the normalized vector, which is the vector divided by its length, as a new vector.round()
Rounds all components to the closest integer.Rounds all components usingMathUtils.roundHalfUp(double)
setComponents
(double x, double y, double z) setComponents
(int x, int y, int z) setComponents
(Vector3 other) static Comparator
<Vector3> Returns a comparator that sorts vectors first by Y, then Z, then X.subtract
(double x, double y, double z) Subtract another vector from this vector and return the result as a new vector.Subtract another vector from this vector and return the result as a new vector.Subtract a list of vectors from this vector and return the result as a new vector.Create a newBlockVector
from this vector.static BlockVector3
toBlockPoint
(double x, double y, double z) Create a newBlockVector
using the given components.Returns a string representation that is supported by the parser.double
toPitch()
Get this vector's pitch as used within the game.toString()
Creates a 2D vector by dropping the Y component from this vector.double
toYaw()
Get this vector's yaw as used within the game.transform2D
(double angle, double aboutX, double aboutZ, double translateX, double translateZ) Perform a 2D transformation on this vector and return a new one.withX
(double x) Set the X coordinate.withY
(double y) Set the Y coordinate.withZ
(double z) Set the Z coordinate.abstract double
x()
Get the X coordinate.abstract double
y()
Get the Y coordinate.abstract double
z()
Get the Z coordinate.
-
Field Details
-
ZERO
-
UNIT_X
-
UNIT_Y
-
UNIT_Z
-
ONE
-
-
Constructor Details
-
Vector3
public Vector3()
-
-
Method Details
-
at
-
sortByCoordsYzx
Returns a comparator that sorts vectors first by Y, then Z, then X.Useful for sorting by chunk block storage order.
-
getBlockX
public int getBlockX()Gets the x coordinate rounded, accounting for negative coordinates- Returns:
- the x coordinate
-
getBlockY
public int getBlockY()Gets the y coordinate rounded, accounting for negative coordinates- Returns:
- the y coordinate
-
getBlockZ
public int getBlockZ()Gets the z coordinate rounded, accounting for negative coordinates- Returns:
- the z coordinate
-
setComponents
-
setComponents
-
setComponents
-
mutX
-
mutX
-
mutY
-
mutY
-
mutZ
-
mutZ
-
x
public abstract double x()Get the X coordinate.- Returns:
- the x coordinate
- Since:
- 2.11.0
-
blockX
public int blockX()Get the X coordinate, aligned to the block grid.- Returns:
- the block-aligned x coordinate
-
getX
Deprecated, for removal: This API element is subject to removal in a future version.usex()
insteadGet the X coordinate.- Returns:
- the x coordinate
-
withX
Set the X coordinate.- Parameters:
x
- the new X- Returns:
- a new vector
-
y
public abstract double y()Get the Y coordinate.- Returns:
- the y coordinate
- Since:
- 2.11.0
-
blockY
public int blockY()Get the Y coordinate, aligned to the block grid.- Returns:
- the block-aligned y coordinate
-
getY
Deprecated, for removal: This API element is subject to removal in a future version.usey()
insteadGet the Y coordinate.- Returns:
- the y coordinate
-
withY
Set the Y coordinate.- Parameters:
y
- the new Y- Returns:
- a new vector
-
z
public abstract double z()Get the Z coordinate.- Returns:
- the z coordinate
- Since:
- 2.11.0
-
blockZ
public int blockZ()Get the Z coordinate, aligned to the block grid.- Returns:
- the block-aligned z coordinate
-
getZ
Deprecated, for removal: This API element is subject to removal in a future version.usez()
insteadGet the Z coordinate.- Returns:
- the z coordinate
-
withZ
Set the Z coordinate.- Parameters:
z
- the new Z- Returns:
- a new vector
-
add
Add another vector to this vector and return the result as a new vector.- Parameters:
other
- the other vector- Returns:
- a new vector
-
add
Add another vector to this vector and return the result as a new vector.- Parameters:
x
- the value to addy
- the value to addz
- the value to add- Returns:
- a new vector
-
add
Add a list of vectors to this vector and return the result as a new vector.- Parameters:
others
- an array of vectors- Returns:
- a new vector
-
subtract
Subtract another vector from this vector and return the result as a new vector.- Parameters:
other
- the other vector- Returns:
- a new vector
-
subtract
Subtract another vector from this vector and return the result as a new vector.- Parameters:
x
- the value to subtracty
- the value to subtractz
- the value to subtract- Returns:
- a new vector
-
subtract
Subtract a list of vectors from this vector and return the result as a new vector.- Parameters:
others
- an array of vectors- Returns:
- a new vector
-
multiply
Multiply this vector by another vector on each component.- Parameters:
other
- the other vector- Returns:
- a new vector
-
multiply
Multiply this vector by another vector on each component.- Parameters:
x
- the value to multiplyy
- the value to multiplyz
- the value to multiply- Returns:
- a new vector
-
multiply
Multiply this vector by zero or more vectors on each component.- Parameters:
others
- an array of vectors- Returns:
- a new vector
-
multiply
Perform scalar multiplication and return a new vector.- Parameters:
n
- the value to multiply- Returns:
- a new vector
-
divide
Divide this vector by another vector on each component.- Parameters:
other
- the other vector- Returns:
- a new vector
-
divide
Divide this vector by another vector on each component.- Parameters:
x
- the value to divide byy
- the value to divide byz
- the value to divide by- Returns:
- a new vector
-
divide
Perform scalar division and return a new vector.- Parameters:
n
- the value to divide by- Returns:
- a new vector
-
length
public double length()Get the length of the vector.- Returns:
- length
-
lengthSq
public double lengthSq()Get the length, squared, of the vector.- Returns:
- length, squared
-
distance
Get the distance between this vector and another vector.- Parameters:
other
- the other vector- Returns:
- distance
-
distanceSq
Get the distance between this vector and another vector, squared.- Parameters:
other
- the other vector- Returns:
- distance
-
normalize
Get the normalized vector, which is the vector divided by its length, as a new vector.- Returns:
- a new vector
-
dot
Gets the dot product of this and another vector.- Parameters:
other
- the other vector- Returns:
- the dot product of this and the other vector
-
cross
Gets the cross product of this and another vector.- Parameters:
other
- the other vector- Returns:
- the cross product of this and the other vector
-
containedWithin
Checks to see if a vector is contained with another.- Parameters:
min
- the minimum point (X, Y, and Z are the lowest)max
- the maximum point (X, Y, and Z are the lowest)- Returns:
- true if the vector is contained
-
clampY
Clamp the Y component.- Parameters:
min
- the minimum valuemax
- the maximum value- Returns:
- a new vector
-
floor
Floors the values of all components.- Returns:
- a new vector
-
ceil
Rounds all components up.- Returns:
- a new vector
-
round
Rounds all components to the closest integer.Components < 0.5 are rounded down, otherwise up.
- Returns:
- a new vector
-
roundHalfUp
Rounds all components usingMathUtils.roundHalfUp(double)
- Returns:
- a new vector
-
abs
Returns a vector with the absolute values of the components of this vector.- Returns:
- a new vector
-
transform2D
public Vector3 transform2D(double angle, double aboutX, double aboutZ, double translateX, double translateZ) Perform a 2D transformation on this vector and return a new one.- Parameters:
angle
- in degreesaboutX
- about which x coordinate to rotateaboutZ
- about which z coordinate to rotatetranslateX
- what to add after rotationtranslateZ
- what to add after rotation- Returns:
- a new vector
- See Also:
-
toPitch
public double toPitch()Get this vector's pitch as used within the game.- Returns:
- pitch in radians
-
toYaw
public double toYaw()Get this vector's yaw as used within the game.- Returns:
- yaw in radians
-
getMinimum
Gets the minimum components of two vectors.- Parameters:
v2
- the second vector- Returns:
- minimum
-
getMaximum
Gets the maximum components of two vectors.- Parameters:
v2
- the second vector- Returns:
- maximum
-
toBlockPoint
Create a newBlockVector
using the given components.- Parameters:
x
- the X coordinatey
- the Y coordinatez
- the Z coordinate- Returns:
- a new
BlockVector
-
toBlockPoint
Create a newBlockVector
from this vector.- Returns:
- a new
BlockVector
-
toVector2
Creates a 2D vector by dropping the Y component from this vector.- Returns:
- a new
Vector2
-
equals
-
equalsFuzzy
Tests if vectors are equal, accounting for floating point errors- Parameters:
other
- Another Vector3- Returns:
- if the vectors are effectively equal
-
hashCode
public int hashCode() -
toString
-
toParserString
Returns a string representation that is supported by the parser.- Returns:
- string
-
x()
instead