Class Position

java.lang.Object
net.apartium.cocoabeans.space.Position
Direct Known Subclasses:
ImmutablePosition

@AvailableSince("0.0.22") public class Position extends Object
Represents a mutable position in 3D space with double precision coordinates (x, y, z).

Provides a variety of vector operations, arithmetic, and utility methods for manipulating positions, including addition, subtraction, multiplication, division, normalization, rounding, flooring, ceiling, and conversion to immutable positions. Also supports distance calculations, dot and cross products, and directional calculations based on yaw and pitch.

Common constants such as ZERO, UP, and DOWN are provided for convenience.

This class is available since version 0.0.22.

  • Field Details

    • ZERO

      public static final Position ZERO
      Position at (0, 0, 0).
    • UP

      public static final Position UP
      Position at (0, 1, 0).
    • DOWN

      public static final Position DOWN
      Position at (0, -1, 0).
  • Constructor Details

    • Position

      @AvailableSince("0.0.30") public Position(double x, double y, double z)
      Create a new position with the given coordinates.
      Parameters:
      x - the x coordinate
      y - the y coordinate
      z - the z coordinate
    • Position

      public Position(Position other)
      Create a new position by copying another position.
      Parameters:
      other - the position to copy
  • Method Details

    • min

      public static Position min(Position a, Position b)
    • max

      public static Position max(Position a, Position b)
      Returns the maximum of two positions for each coordinate.
      Parameters:
      a - first position
      b - second position
      Returns:
      position with maximum x, y, z
    • getX

      public double getX()
      Returns the x coordinate.
      Returns:
      x
    • getY

      public double getY()
      Returns the y coordinate.
      Returns:
      y
    • getZ

      public double getZ()
      Returns the z coordinate.
      Returns:
      z
    • setX

      public Position setX(double x)
      Sets the x coordinate.
      Parameters:
      x - new x
      Returns:
      this
    • setY

      public Position setY(double y)
      Sets the y coordinate.
      Parameters:
      y - new y
      Returns:
      this
    • setZ

      public Position setZ(double z)
      Sets the z coordinate.
      Parameters:
      z - new z
      Returns:
      this
    • add

      public Position add(Position other)
      Adds another position to this position.
      Parameters:
      other - the position to add
      Returns:
      this after addition
    • subtract

      public Position subtract(Position other)
      Subtracts another position from this position.
      Parameters:
      other - the position to subtract
      Returns:
      this after subtraction
    • multiply

      public Position multiply(double scalar)
      Multiplies this position by a scalar.
      Parameters:
      scalar - the scalar value
      Returns:
      this after multiplication
    • divide

      public Position divide(double scalar)
      Divides this position by a scalar.
      Parameters:
      scalar - the scalar value
      Returns:
      this after division
    • negate

      public Position negate()
      Negates this position.
      Returns:
      this after negation
    • dot

      public double dot(Position other)
      Computes the dot product with another position.
      Parameters:
      other - the other position
      Returns:
      dot product
    • crossProduct

      public Position crossProduct(Position other)
      Computes the cross product with another position.
      Parameters:
      other - the other position
      Returns:
      cross product position
    • length

      public double length()
      Returns the length (magnitude) of this position vector.
      Returns:
      length
    • normalize

      public Position normalize()
      Normalizes this position vector.
      Returns:
      this after normalization
    • floor

      public Position floor()
      Floors the x, y, z coordinates.
      Returns:
      this after flooring
    • ceil

      public Position ceil()
      Ceils the x, y, z coordinates.
      Returns:
      this after ceiling
    • round

      public Position round()
      Rounds the x, y, z coordinates.
      Returns:
      this after rounding
    • round

      public Position round(int places)
      Rounds the x, y, z coordinates to the specified number of decimal places.
      Parameters:
      places - number of decimal places
      Returns:
      this after rounding
    • abs

      public Position abs()
      Sets the x, y, z coordinates to their absolute values.
      Returns:
      this after applying abs
    • distanceSquared

      public double distanceSquared(Position other)
      Returns the squared distance between this and another position.
      Parameters:
      other - the other position
      Returns:
      squared distance
    • distance

      public double distance(Position other)
      Returns the distance between this and another position.
      Parameters:
      other - the other position
      Returns:
      distance
    • copy

      public Position copy()
      Creates a copy of this position.
      Returns:
      new instance of position
    • isZero

      public boolean isZero()
      Checks if this position is zero (all coordinates are 0).
      Returns:
      true if position is zero
    • immutable

      public Position immutable()
      Returns an immutable version of this position.
      Returns:
      immutable position
    • lookAt

      @AvailableSince("0.0.30") public Rotation lookAt(Position target)
      Returns a rotation based on the direction to a target position.
      Parameters:
      target - target position
      Returns:
      rotation to look at target
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

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

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

      public static Position fromDirection(double rotX, double rotY)
      Returns a position based on yaw and pitch angles.
      Parameters:
      rotX - yaw angle in degrees
      rotY - pitch angle in degrees
      Returns:
      position based on direction
    • add

      public static Position add(Position a, Position b)
      Adds two positions and returns a new position.
      Parameters:
      a - first position
      b - second position
      Returns:
      sum of positions
    • multiply

      public static Position multiply(Position position, long value)
      Multiplies a position by a long value and returns a new position.
      Parameters:
      position - the position
      value - the scalar value
      Returns:
      multiplied position