Record Class Vec
- Record Components:
x- the X coordinatey- the Y coordinatez- the Z coordinate
- All Implemented Interfaces:
Point
This is the fundamental coordinate type for precise spatial calculations. Supports standard vector operations including dot product, cross product, normalization, and rotation.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceDeprecated, for removal: This API element is subject to removal in a future version.static interfaceA functional interface representing an operation on the components of aVec. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Vecstatic final Vecstatic final Vecstatic final Vecstatic final VecFields inherited from interface Point
EPSILON, REGION_SIZE, SECTION_SIZE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabs()Represents this point with all coordinates as their absolute values.add(double value) Creates a new point by adding the provided value to this point coordinates for all XYZ.add(double x, double y, double z) Creates a new point by adding the provided values to this point coordinates.Creates a new point by adding another point coordinates to this point coordinates.apply(Vec.Operator operator) Applies the given operator to this vector's coordinates (x/y/z).Deprecated, for removal: This API element is subject to removal in a future version.usePoint.asPos()instead.asVec()Deprecated.Calculates the cross product of this point with another.div(double value) Creates a new point by dividing the provided value to this point coordinates for all XYZ.div(double x, double y, double z) Creates a new point by dividing the provided values to this point coordinates.Creates a new point by dividing another point coordinates to this point coordinates.final booleanIndicates whether some other object is "equal to" this one.static VecDeprecated, for removal: This API element is subject to removal in a future version.usePoint.asVec()insteadfinal inthashCode()Returns a hash code value for this object.interpolate(Vec target, double alpha, Vec.Interpolation interpolation) Deprecated, for removal: This API element is subject to removal in a future version.usePoint.lerp(Point, double)with aEaseFunctioninsteadCalculates a linear interpolation between this point with another point (x/y/z).max(double value) Gets a point representing the maximum values between this point and the provided value for all coordinates.max(double x, double y, double z) Gets a point representing the maximum values between this point and the provided coordinates (x/y/z).Gets a point representing the maximum values between this point and the provided one (x/y/z).min(double value) Gets a point representing the minimum values between this point and the provided value for all coordinates.min(double x, double y, double z) Gets a point representing the minimum values between this point and the provided coordinates (x/y/z).Gets a point representing the minimum values between this point and the provided one (x/y/z).mul(double value) Creates a new point by multiplying the provided value to this point coordinates for all XYZ.mul(double x, double y, double z) Creates a new point by multiplying the provided values to this point coordinates.Creates a new point by multiplying another point coordinates to this point coordinates.neg()Represents this point with all coordinates negated.Converts this point to a unit point (a point with length of 1).Creates a new point relative to this point based on the provided block face.rotate(double angleX, double angleY, double angleZ) Rotates the vector around the x, y, and z axes.rotateAroundAxis(Vec axis, double angle) Rotates the vector around a given arbitrary axis in 3 dimensional space.rotateAroundNonUnitAxis(Vec 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 axisrotateFromView(float yawDegrees, float pitchDegrees) Rotates the vector from a given yaw and pitch.rotateFromView(Pos pos) Rotates the vector from a position's view (yaw/pitch).sub(double value) Creates a new point by subtracting the provided value to this point coordinates for all XYZ.sub(double x, double y, double z) Creates a new point by subtracting the provided values to this point coordinates.Creates a new point by subtracting another point coordinates to this point coordinates.final StringtoString()Returns a string representation of this record class.withX(double x) Creates a point with the specified X coordinate.withX(DoubleUnaryOperator operator) Creates a point with a modified X coordinate based on its value.withY(double y) Creates a point with the specified Y coordinate.withY(DoubleUnaryOperator operator) Creates a point with a modified Y coordinate based on its value.withZ(double z) Creates a point with the specified Z coordinate.withZ(DoubleUnaryOperator operator) Creates a point with a modified Z coordinate based on its value.doublex()Returns the value of thexrecord component.doubley()Returns the value of theyrecord component.doublez()Returns the value of thezrecord component.Methods inherited from interface Point
angle, asBlockVec, asPos, blockX, blockY, blockZ, chunkX, chunkZ, distance, distance, distanceSquared, distanceSquared, dot, isNormalized, isZero, length, lengthSquared, regionX, regionZ, sameBlock, sameBlock, sameChunk, samePoint, samePoint, samePoint, samePoint, section, sectionX, sectionY, sectionZ, similarPoint, similarPoint
-
Field Details
-
ZERO
-
ONE
-
SECTION
-
CHUNK
-
REGION
-
-
Constructor Details
-
Vec
public Vec(double x, double z) Creates a new vec with the [x;z] coordinates set. Y is set to 0.- Parameters:
x- the X coordinatez- the Z coordinate
-
Vec
public Vec(double value) Creates a vec with all 3 coordinates sharing the same value.- Parameters:
value- the coordinates
-
Vec
-
-
Method Details
-
fromPoint
Deprecated, for removal: This API element is subject to removal in a future version.usePoint.asVec()instead- Parameters:
point- the point to convert- Returns:
- the converted vector
-
apply
Applies the given operator to this vector's coordinates (x/y/z).- Parameters:
operator- the operator to apply- Returns:
- the resulting vector
-
withX
Description copied from interface:PointCreates a point with a modified X coordinate based on its value. -
withX
-
withY
Description copied from interface:PointCreates a point with a modified Y coordinate based on its value. -
withY
-
withZ
Description copied from interface:PointCreates a point with a modified Z coordinate based on its value. -
withZ
-
add
Description copied from interface:PointCreates a new point by adding the provided values to this point coordinates. -
add
Description copied from interface:PointCreates a new point by adding another point coordinates to this point coordinates. -
add
-
sub
Description copied from interface:PointCreates a new point by subtracting the provided values to this point coordinates. -
sub
Description copied from interface:PointCreates a new point by subtracting another point coordinates to this point coordinates. -
sub
Description copied from interface:PointCreates a new point by subtracting the provided value to this point coordinates for all XYZ. -
mul
Description copied from interface:PointCreates a new point by multiplying the provided values to this point coordinates. -
mul
Description copied from interface:PointCreates a new point by multiplying another point coordinates to this point coordinates. -
mul
Description copied from interface:PointCreates a new point by multiplying the provided value to this point coordinates for all XYZ. -
div
Description copied from interface:PointCreates a new point by dividing the provided values to this point coordinates.Warning: division by zero will not error.
-
div
Description copied from interface:PointCreates a new point by dividing another point coordinates to this point coordinates.Warning: division by zero will not error.
-
div
Description copied from interface:PointCreates a new point by dividing the provided value to this point coordinates for all XYZ.Warning: division by zero will not error.
-
relative
-
neg
-
abs
-
min
Description copied from interface:PointGets a point representing the minimum values between this point and the provided one (x/y/z). -
min
Description copied from interface:PointGets a point representing the minimum values between this point and the provided coordinates (x/y/z). -
min
Description copied from interface:PointGets a point representing the minimum values between this point and the provided value for all coordinates. -
max
Description copied from interface:PointGets a point representing the maximum values between this point and the provided one (x/y/z). -
max
Description copied from interface:PointGets a point representing the maximum values between this point and the provided coordinates (x/y/z). -
max
Description copied from interface:PointGets a point representing the maximum values between this point and the provided value for all coordinates. -
asPosition
Deprecated, for removal: This API element is subject to removal in a future version.usePoint.asPos()instead. -
normalize
-
cross
Description copied from interface:PointCalculates the cross product of this point with another. The cross product is defined as:- x = y1 * z2 - y2 * z1
- y = z1 * x2 - z2 * x1
- z = x1 * y2 - x2 * y1
-
rotateAroundX
Rotates 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:
- a new, rotated vector
-
rotateAroundY
Rotates 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:
- a new, rotated vector
-
rotateAroundZ
Rotates 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:
- a new, rotated vector
-
rotate
@Contract(pure=true, value="_, _, _ -> new") public Vec rotate(double angleX, double angleY, double angleZ) Rotates the vector around the x, y, and z axes.- Parameters:
angleX- the angle to rotate around the x-axis in radiansangleY- the angle to rotate around the y-axis in radiansangleZ- the angle to rotate around the z-axis in radians- Returns:
- a new, rotated vector
-
rotateFromView
-
rotateFromView
-
rotateAroundAxis
@Contract(pure=true, value="_, _ -> new") public Vec rotateAroundAxis(Vec 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(Vec, 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 usenormalize()on the instance before passing it to this methodangle- the angle to rotate the vector around the axis- Returns:
- a new vector
- Throws:
IllegalArgumentException
-
rotateAroundNonUnitAxis
@Contract(pure=true, value="_, _ -> new") public Vec rotateAroundNonUnitAxis(Vec 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(Vec, double)- Parameters:
axis- the axis to rotate the vector around.angle- the angle to rotate the vector around the axis- Returns:
- a new vector
- Throws:
IllegalArgumentException
-
lerp
Description copied from interface:PointCalculates a linear interpolation between this point with another point (x/y/z). -
interpolate
@Deprecated(forRemoval=true) @Contract(pure=true) public Vec interpolate(Vec target, double alpha, Vec.Interpolation interpolation) Deprecated, for removal: This API element is subject to removal in a future version.usePoint.lerp(Point, double)with aEaseFunctioninsteadCalculates an interpolation between this vector and a target vector.- Parameters:
target- the target vectoralpha- the alpha value, must be between 0.0 and 1.0interpolation- the interpolation function to use- Returns:
- the interpolated vector
-
asVec
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with thecomparemethod from their corresponding wrapper classes. -
x
-
y
-
z
-
EaseFunctioninstead withlerp(Point, double)