Class Vector3

java.lang.Object
com.sk89q.worldedit.math.Vector3
Direct Known Subclasses:
MutableVector3, Vector3Impl

public abstract class Vector3 extends Object
An immutable 3-dimensional vector.
  • Field Details

    • ZERO

      public static final Vector3 ZERO
    • UNIT_X

      public static final Vector3 UNIT_X
    • UNIT_Y

      public static final Vector3 UNIT_Y
    • UNIT_Z

      public static final Vector3 UNIT_Z
    • ONE

      public static final Vector3 ONE
  • Constructor Details

    • Vector3

      public Vector3()
  • Method Details

    • at

      public static Vector3 at(double x, double y, double z)
    • sortByCoordsYzx

      public static Comparator<Vector3> 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

      public MutableVector3 setComponents(Vector3 other)
    • setComponents

      public MutableVector3 setComponents(int x, int y, int z)
    • setComponents

      public MutableVector3 setComponents(double x, double y, double z)
    • mutX

      public MutableVector3 mutX(int x)
    • mutX

      public MutableVector3 mutX(double x)
    • mutY

      public MutableVector3 mutY(int y)
    • mutY

      public MutableVector3 mutY(double y)
    • mutZ

      public MutableVector3 mutZ(int z)
    • mutZ

      public MutableVector3 mutZ(double z)
    • 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(forRemoval=true, since="2.11.0") public double getX()
      Deprecated, for removal: This API element is subject to removal in a future version.
      use x() instead
      Get the X coordinate.
      Returns:
      the x coordinate
    • withX

      public Vector3 withX(double x)
      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(forRemoval=true, since="2.11.0") public double getY()
      Deprecated, for removal: This API element is subject to removal in a future version.
      use y() instead
      Get the Y coordinate.
      Returns:
      the y coordinate
    • withY

      public Vector3 withY(double y)
      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(forRemoval=true, since="2.11.0") public double getZ()
      Deprecated, for removal: This API element is subject to removal in a future version.
      use z() instead
      Get the Z coordinate.
      Returns:
      the z coordinate
    • withZ

      public Vector3 withZ(double z)
      Set the Z coordinate.
      Parameters:
      z - the new Z
      Returns:
      a new vector
    • add

      public Vector3 add(Vector3 other)
      Add another vector to this vector and return the result as a new vector.
      Parameters:
      other - the other vector
      Returns:
      a new vector
    • add

      public Vector3 add(double x, double y, double z)
      Add another vector to this vector and return the result as a new vector.
      Parameters:
      x - the value to add
      y - the value to add
      z - the value to add
      Returns:
      a new vector
    • add

      public Vector3 add(Vector3... others)
      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

      public Vector3 subtract(Vector3 other)
      Subtract another vector from this vector and return the result as a new vector.
      Parameters:
      other - the other vector
      Returns:
      a new vector
    • subtract

      public Vector3 subtract(double x, double y, double z)
      Subtract another vector from this vector and return the result as a new vector.
      Parameters:
      x - the value to subtract
      y - the value to subtract
      z - the value to subtract
      Returns:
      a new vector
    • subtract

      public Vector3 subtract(Vector3... others)
      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

      public Vector3 multiply(Vector3 other)
      Multiply this vector by another vector on each component.
      Parameters:
      other - the other vector
      Returns:
      a new vector
    • multiply

      public Vector3 multiply(double x, double y, double z)
      Multiply this vector by another vector on each component.
      Parameters:
      x - the value to multiply
      y - the value to multiply
      z - the value to multiply
      Returns:
      a new vector
    • multiply

      public Vector3 multiply(Vector3... others)
      Multiply this vector by zero or more vectors on each component.
      Parameters:
      others - an array of vectors
      Returns:
      a new vector
    • multiply

      public Vector3 multiply(double n)
      Perform scalar multiplication and return a new vector.
      Parameters:
      n - the value to multiply
      Returns:
      a new vector
    • divide

      public Vector3 divide(Vector3 other)
      Divide this vector by another vector on each component.
      Parameters:
      other - the other vector
      Returns:
      a new vector
    • divide

      public Vector3 divide(double x, double y, double z)
      Divide this vector by another vector on each component.
      Parameters:
      x - the value to divide by
      y - the value to divide by
      z - the value to divide by
      Returns:
      a new vector
    • divide

      public Vector3 divide(double n)
      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

      public double distance(Vector3 other)
      Get the distance between this vector and another vector.
      Parameters:
      other - the other vector
      Returns:
      distance
    • distanceSq

      public double distanceSq(Vector3 other)
      Get the distance between this vector and another vector, squared.
      Parameters:
      other - the other vector
      Returns:
      distance
    • normalize

      public Vector3 normalize()
      Get the normalized vector, which is the vector divided by its length, as a new vector.
      Returns:
      a new vector
    • dot

      public double dot(Vector3 other)
      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

      public Vector3 cross(Vector3 other)
      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

      public boolean containedWithin(Vector3 min, Vector3 max)
      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

      public Vector3 clampY(int min, int max)
      Clamp the Y component.
      Parameters:
      min - the minimum value
      max - the maximum value
      Returns:
      a new vector
    • floor

      public Vector3 floor()
      Floors the values of all components.
      Returns:
      a new vector
    • ceil

      public Vector3 ceil()
      Rounds all components up.
      Returns:
      a new vector
    • round

      public Vector3 round()
      Rounds all components to the closest integer.

      Components < 0.5 are rounded down, otherwise up.

      Returns:
      a new vector
    • roundHalfUp

      public Vector3 roundHalfUp()
      Rounds all components using MathUtils.roundHalfUp(double)
      Returns:
      a new vector
    • abs

      public Vector3 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 degrees
      aboutX - about which x coordinate to rotate
      aboutZ - about which z coordinate to rotate
      translateX - what to add after rotation
      translateZ - 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

      public Vector3 getMinimum(Vector3 v2)
      Gets the minimum components of two vectors.
      Parameters:
      v2 - the second vector
      Returns:
      minimum
    • getMaximum

      public Vector3 getMaximum(Vector3 v2)
      Gets the maximum components of two vectors.
      Parameters:
      v2 - the second vector
      Returns:
      maximum
    • toBlockPoint

      public static BlockVector3 toBlockPoint(double x, double y, double z)
      Create a new BlockVector using the given components.
      Parameters:
      x - the X coordinate
      y - the Y coordinate
      z - the Z coordinate
      Returns:
      a new BlockVector
    • toBlockPoint

      public BlockVector3 toBlockPoint()
      Create a new BlockVector from this vector.
      Returns:
      a new BlockVector
    • toVector2

      public Vector2 toVector2()
      Creates a 2D vector by dropping the Y component from this vector.
      Returns:
      a new Vector2
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • equalsFuzzy

      public boolean equalsFuzzy(Vector3 other)
      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()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toParserString

      public String toParserString()
      Returns a string representation that is supported by the parser.
      Returns:
      string