Package net.apartium.cocoabeans.space
Class Position
java.lang.Object
net.apartium.cocoabeans.space.Position
- Direct Known Subclasses:
ImmutablePosition
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabs()Sets the x, y, z coordinates to their absolute values.Adds another position to this position.static PositionAdds two positions and returns a new position.ceil()Ceils the x, y, z coordinates.copy()Creates a copy of this position.crossProduct(Position other) Computes the cross product with another position.doubleReturns the distance between this and another position.doubledistanceSquared(Position other) Returns the squared distance between this and another position.divide(double scalar) Divides this position by a scalar.doubleComputes the dot product with another position.booleanfloor()Floors the x, y, z coordinates.static PositionfromDirection(double rotX, double rotY) Returns a position based on yaw and pitch angles.doublegetX()Returns the x coordinate.doublegetY()Returns the y coordinate.doublegetZ()Returns the z coordinate.inthashCode()Returns an immutable version of this position.booleanisZero()Checks if this position is zero (all coordinates are 0).doublelength()Returns the length (magnitude) of this position vector.Returns a rotation based on the direction to a target position.static PositionReturns the maximum of two positions for each coordinate.static Positionmultiply(double scalar) Multiplies this position by a scalar.static PositionMultiplies a position by a long value and returns a new position.negate()Negates this position.Normalizes this position vector.round()Rounds the x, y, z coordinates.round(int places) Rounds the x, y, z coordinates to the specified number of decimal places.setX(double x) Sets the x coordinate.setY(double y) Sets the y coordinate.setZ(double z) Sets the z coordinate.Subtracts another position from this position.toString()
-
Field Details
-
ZERO
Position at (0, 0, 0). -
UP
Position at (0, 1, 0). -
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 coordinatey- the y coordinatez- the z coordinate
-
Position
Create a new position by copying another position.- Parameters:
other- the position to copy
-
-
Method Details
-
min
-
max
Returns the maximum of two positions for each coordinate.- Parameters:
a- first positionb- 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
Sets the x coordinate.- Parameters:
x- new x- Returns:
- this
-
setY
Sets the y coordinate.- Parameters:
y- new y- Returns:
- this
-
setZ
Sets the z coordinate.- Parameters:
z- new z- Returns:
- this
-
add
Adds another position to this position.- Parameters:
other- the position to add- Returns:
- this after addition
-
subtract
Subtracts another position from this position.- Parameters:
other- the position to subtract- Returns:
- this after subtraction
-
multiply
Multiplies this position by a scalar.- Parameters:
scalar- the scalar value- Returns:
- this after multiplication
-
divide
Divides this position by a scalar.- Parameters:
scalar- the scalar value- Returns:
- this after division
-
negate
Negates this position.- Returns:
- this after negation
-
dot
Computes the dot product with another position.- Parameters:
other- the other position- Returns:
- dot product
-
crossProduct
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
Normalizes this position vector.- Returns:
- this after normalization
-
floor
Floors the x, y, z coordinates.- Returns:
- this after flooring
-
ceil
Ceils the x, y, z coordinates.- Returns:
- this after ceiling
-
round
Rounds the x, y, z coordinates.- Returns:
- this after rounding
-
round
Rounds the x, y, z coordinates to the specified number of decimal places.- Parameters:
places- number of decimal places- Returns:
- this after rounding
-
abs
Sets the x, y, z coordinates to their absolute values.- Returns:
- this after applying abs
-
distanceSquared
Returns the squared distance between this and another position.- Parameters:
other- the other position- Returns:
- squared distance
-
distance
Returns the distance between this and another position.- Parameters:
other- the other position- Returns:
- distance
-
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
Returns an immutable version of this position.- Returns:
- immutable position
-
lookAt
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() -
equals
-
toString
-
fromDirection
Returns a position based on yaw and pitch angles.- Parameters:
rotX- yaw angle in degreesrotY- pitch angle in degrees- Returns:
- position based on direction
-
add
Adds two positions and returns a new position.- Parameters:
a- first positionb- second position- Returns:
- sum of positions
-
multiply
Multiplies a position by a long value and returns a new position.- Parameters:
position- the positionvalue- the scalar value- Returns:
- multiplied position
-