Record Class Vec
- All Implemented Interfaces:
Point
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacestatic interface -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabs()add(double value) add(double x, double y, double z) doubleGets the angle between this vector and another in radians.apply(Vec.Operator operator) Creates a new point with coordinated depending onthis.Deprecated.Calculates the cross product of this vector with another.div(double value) div(double x, double y, double z) doubleCalculates the dot product of this vector with another.final booleanIndicates whether some other object is "equal to" this one.static VecDeprecated.usePoint.asVec()insteadfinal inthashCode()Returns a hash code value for this object.interpolate(Vec target, double alpha, 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.Calculates a linear interpolation between this vector with another vector.max(double value) max(double x, double y, double z) min(double value) min(double x, double y, double z) mul(double value) mul(double x, double y, double z) neg()Converts this vector to a unit vector (a vector with length of 1).rotate(double angleX, double angleY, double angleZ) 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) rotateFromView(Pos pos) sub(double value) sub(double x, double y, double z) 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.
-
Field Details
-
ZERO
-
ONE
-
SECTION
-
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
Deprecated.usePoint.asVec()instead- 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
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
-
add
-
add
-
sub
-
sub
-
sub
-
mul
-
mul
-
mul
-
div
-
div
-
div
-
relative
-
neg
-
abs
-
min
-
min
-
min
-
max
-
max
-
max
-
asPosition
Deprecated.usePoint.asPos()instead. -
lengthSquared
-
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
-
isNormalized
public boolean isNormalized()Returns if a vector is normalized- Returns:
- whether the vector is normalised
-
angle
-
dot
-
cross
-
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
-
rotateFromView
-
rotateFromView
-
rotateAroundAxis
@Contract(pure=true) 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) 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
-
interpolate
@Contract(pure=true) public Vec interpolate(Vec target, double alpha, Vec.Interpolation interpolation) -
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
-
Point.asPos()instead.