Record Class Vec
- All Implemented Interfaces:
Point
To become a value then primitive type.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacestatic interface -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription@NotNull Vecabs()@NotNull Vecadd(double value) @NotNull Vecadd(double x, double y, double z) @NotNull VecdoubleGets the angle between this vector and another in radians.@NotNull Vecapply(@NotNull Vec.Operator operator) Creates a new point with coordinated depending onthis.@NotNull Pos@NotNull VecCalculates the cross product of this vector with another.@NotNull Vecdiv(double value) @NotNull Vecdiv(double x, double y, double z) @NotNull VecdoubleCalculates the dot product of this vector with another.final booleanIndicates whether some other object is "equal to" this one.static @NotNull Vecfinal inthashCode()Returns a hash code value for this object.@NotNull Vecinterpolate(@NotNull Vec target, double alpha, @NotNull Vec.Interpolation interpolation) booleanReturns if a vector is normalizeddoublelength()Gets the magnitude of the vector, defined as sqrt(x^2+y^2+z^2).doubleGets the magnitude of the vector squared.@NotNull VecCalculates a linear interpolation between this vector with another vector.@NotNull Vecmax(double value) @NotNull Vec@NotNull Vecmin(double value) @NotNull Vec@NotNull Vecmul(double value) @NotNull Vecmul(double x, double y, double z) @NotNull Vec@NotNull Vecneg()@NotNull VecConverts this vector to a unit vector (a vector with length of 1).@NotNull Vec@NotNull Vecrotate(double angleX, double angleY, double angleZ) @NotNull VecrotateAroundAxis(@NotNull Vec axis, double angle) Rotates the vector around a given arbitrary axis in 3 dimensional space.@NotNull VecrotateAroundNonUnitAxis(@NotNull Vec axis, double angle) Rotates the vector around a given arbitrary axis in 3 dimensional space.@NotNull VecrotateAroundX(double angle) Rotates the vector around the x-axis.@NotNull VecrotateAroundY(double angle) Rotates the vector around the y-axis.@NotNull VecrotateAroundZ(double angle) Rotates the vector around the z axis@NotNull VecrotateFromView(float yawDegrees, float pitchDegrees) @NotNull VecrotateFromView(@NotNull Pos pos) @NotNull Vecsub(double value) @NotNull Vecsub(double x, double y, double z) @NotNull Vecfinal StringtoString()Returns a string representation of this record class.@NotNull VecwithX(double x) Creates a point with the specified X coordinate.@NotNull VecwithX(@NotNull DoubleUnaryOperator operator) Creates a point with a modified X coordinate based on its value.@NotNull VecwithY(double y) Creates a point with the specified Y coordinate.@NotNull VecwithY(@NotNull DoubleUnaryOperator operator) Creates a point with a modified Y coordinate based on its value.@NotNull VecwithZ(double z) Creates a point with the specified Z coordinate.@NotNull VecwithZ(@NotNull 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.
-
Field Details
-
ZERO
-
ONE
-
EPSILON
public static final double EPSILON- See Also:
-
-
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
public Vec(double x, double y, double z) Creates an instance of aVecrecord class.- Parameters:
x- the value for thexrecord componenty- the value for theyrecord componentz- the value for thezrecord component
-
-
Method Details
-
fromPoint
- Parameters:
point- the point to convert- Returns:
- the converted vector
-
apply
Creates a new point with coordinated depending onthis.- Parameters:
operator- the operator- Returns:
- the created point
-
withX
@Contract(pure=true) @NotNull public @NotNull Vec withX(@NotNull @NotNull DoubleUnaryOperator operator) Description copied from interface:PointCreates a point with a modified X coordinate based on its value. -
withX
Description copied from interface:PointCreates a point with the specified X coordinate. -
withY
@Contract(pure=true) @NotNull public @NotNull Vec withY(@NotNull @NotNull DoubleUnaryOperator operator) Description copied from interface:PointCreates a point with a modified Y coordinate based on its value. -
withY
Description copied from interface:PointCreates a point with the specified Y coordinate. -
withZ
@Contract(pure=true) @NotNull public @NotNull Vec withZ(@NotNull @NotNull DoubleUnaryOperator operator) Description copied from interface:PointCreates a point with a modified Z coordinate based on its value. -
withZ
Description copied from interface:PointCreates a point with the specified Z coordinate. -
add
-
add
-
add
-
sub
-
sub
-
sub
-
mul
-
mul
-
mul
-
div
-
div
-
div
-
relative
-
neg
-
abs
-
min
-
min
-
max
-
max
-
asPosition
-
lengthSquared
@Contract(pure=true) public double lengthSquared()Gets the magnitude of the vector squared.- Returns:
- the magnitude
-
length
@Contract(pure=true) public double length()Gets the magnitude of the vector, defined as sqrt(x^2+y^2+z^2). The value of this method is not cached and uses a costly square-root function, so do not repeatedly call this method to get the vector's magnitude. NaN will be returned if the inner result of the sqrt() function overflows, which will be caused if the length is too long.- Returns:
- the magnitude
-
normalize
Converts this vector to a unit vector (a vector with length of 1).- Returns:
- the same vector
-
isNormalized
public boolean isNormalized()Returns if a vector is normalized- Returns:
- whether the vector is normalised
-
angle
Gets the angle between this vector and another in radians.- Parameters:
vec- the other vector- Returns:
- angle in radians
-
dot
Calculates the dot product of this vector with another. The dot product is defined as x1*x2+y1*y2+z1*z2. The returned value is a scalar.- Parameters:
vec- the other vector- Returns:
- dot product
-
cross
Calculates the cross product of this vector with another. The cross product is defined as:- x = y1 * z2 - y2 * z1
- y = z1 * x2 - z2 * x1
- z = x1 * y2 - x2 * y1
- Parameters:
o- the other vector- Returns:
- the same vector
-
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) @NotNull public @NotNull Vec rotate(double angleX, double angleY, double angleZ) -
rotateFromView
@Contract(pure=true) @NotNull public @NotNull Vec rotateFromView(float yawDegrees, float pitchDegrees) -
rotateFromView
-
rotateAroundAxis
@Contract(pure=true) @NotNull public @NotNull Vec rotateAroundAxis(@NotNull @NotNull 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) @NotNull public @NotNull Vec rotateAroundNonUnitAxis(@NotNull @NotNull 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
Calculates a linear interpolation between this vector with another vector.- Parameters:
vec- the other vectoralpha- The alpha value, must be between 0.0 and 1.0- Returns:
- Linear interpolated vector
-
interpolate
@Contract(pure=true) @NotNull public @NotNull Vec interpolate(@NotNull @NotNull Vec target, double alpha, @NotNull @NotNull Vec.Interpolation interpolation) -
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
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 '=='. -
x
public double x()Returns the value of thexrecord component. -
y
public double y()Returns the value of theyrecord component. -
z
public double z()Returns the value of thezrecord component.
-