Package civitas.celestis.math.vector
Class Vector4
java.lang.Object
civitas.celestis.util.tuple.Double4
civitas.celestis.math.vector.Vector4
- All Implemented Interfaces:
Vector<Vector4>,BaseTuple<Double>,DoubleTuple,Serializable
An immutable four-dimensional vector which uses the type
double.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Vector4The negative W unit vector.static final Vector4The negative X unit vector.static final Vector4The negative Y unit vector.static final Vector4The negative Z unit vector.static final Vector4The positive W unit vector.static final Vector4The positive X unit vector.static final Vector4The positive Y unit vector.static final Vector4The positive Z unit vector.static final Vector4A vector of no direction of magnitude. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionadd(double s) Adds a scalar to this vector component-wise, then returns the resulting vector.Adds another vector to this vector, then returns the resulting vector.Between this vector and the provided boundary vectorsminandmax, this returns a new vector whose components are clamped to respect the range of[min, max].doubleReturns the Euclidean distance between this vector and the provided vectorv.doubleReturns the squared Euclidean distance between this vector and the provided vectorv.doubleReturns the Manhattan distance between this vector and the provided vectorv.divide(double s) Divides this vector by a scalar component-wise, then returns the resulting vector.doubleReturns the dot product between this vector and the provided vectorv.booleanChecks for equality between this vector and the provided vectorv.Applies the provided mapper functionfto each component of this tuple, then returns a new tuple containing the return values of the functionf.Between this vector and the provided boundary vectorv, this takes the maximum of each corresponding pair of components, then returns a new vector whose components are populated from that of the maximum values between each pair of components.merge(Vector4 v, BinaryOperator<Double> f) Between this vector and the provided vectorv, this applies the merger functionfto each corresponding pair of components, then returns a new vector whose components are populated from the return values of the functionf.Between this vector and the provided boundary vectorv, this takes the minimum of each corresponding pair of components, then returns a new vector whose components are populated from that of the minimum values between each pair of components.multiply(double s) Multiplies this vector by a scalar component-wise, then returns the resulting vector.Returns the quaternion left-product between this vector and the provided vectorv.negate()Negates all components of this vector, then returns the resulting vector.doublenorm()Returns the Euclidean norm (the magnitude) of this vector.doublenorm2()Returns the squared Euclidean norm (the squared magnitude) of this vector.Normalizes this vector to have a Euclidean norm (magnitude) of1.Normalizes this vector to have a Euclidean norm (magnitude) of1.Normalizes this vector ot have a Euclidean norm (magnitude) of1.doubleReturns the Manhattan norm of this vector.subtract(double s) Subtracts this vector by a scalar component-wise, then returns the resulting vector.Subtracts another vector from this vector, then returns the resulting vector.Methods inherited from class civitas.celestis.util.tuple.Double4
array, boxed, contains, containsAll, equals, get, hashCode, isFinite, isInfinite, isNaN, isZero, list, mapToObj, size, stream, toString, w, x, y, zMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface civitas.celestis.util.tuple.DoubleTuple
array, boxed, contains, containsAll, doubleArray, equals, get, isFinite, isInfinite, isNaN, isZero, list, mapToObj, size, stream, toString
-
Field Details
-
ZERO
A vector of no direction of magnitude. Represents origin. -
POSITIVE_W
The positive W unit vector. -
POSITIVE_X
The positive X unit vector. -
POSITIVE_Y
The positive Y unit vector. -
POSITIVE_Z
The positive Z unit vector. -
NEGATIVE_W
The negative W unit vector. -
NEGATIVE_X
The negative X unit vector. -
NEGATIVE_Y
The negative Y unit vector. -
NEGATIVE_Z
The negative Z unit vector.
-
-
Constructor Details
-
Vector4
public Vector4(double w, double x, double y, double z) Creates a new vector.- Parameters:
w- The W component of this vectorx- The X component of this vectory- The Y component of this vectorz- The Z component of this vector
-
Vector4
public Vector4(@Nonnull double[] components) Creates a new vector.- Parameters:
components- An array containing the components of this vector in WXYZ order- Throws:
IllegalArgumentException- When the provided array's length is not4
-
Vector4
Creates a new vector.- Parameters:
t- The tuple of which to copy component values from- Throws:
IllegalArgumentException- When the provided tuplet's size is not4
-
-
Method Details
-
norm
public double norm()Returns the Euclidean norm (the magnitude) of this vector. -
norm2
public double norm2()Returns the squared Euclidean norm (the squared magnitude) of this vector. -
normManhattan
public double normManhattan()Returns the Manhattan norm of this vector.- Specified by:
normManhattanin interfaceVector<Vector4>- Returns:
- The Manhattan norm of this vector
-
add
Adds a scalar to this vector component-wise, then returns the resulting vector. -
subtract
Subtracts this vector by a scalar component-wise, then returns the resulting vector. -
multiply
Multiplies this vector by a scalar component-wise, then returns the resulting vector. -
divide
Divides this vector by a scalar component-wise, then returns the resulting vector.- Specified by:
dividein interfaceVector<Vector4>- Parameters:
s- The scalar of which to divide each component of this vector by- Returns:
- The resulting vector
- Throws:
ArithmeticException- When the denominatorsis zero
-
add
Adds another vector to this vector, then returns the resulting vector. -
subtract
Subtracts another vector from this vector, then returns the resulting vector. -
multiply
Returns the quaternion left-product between this vector and the provided vectorv.- Parameters:
v- The vector of which to get the quaternion left-product between- Returns:
- The quaternion left-product between the two vectors
-
dot
Returns the dot product between this vector and the provided vectorv. -
normalize
Normalizes this vector to have a Euclidean norm (magnitude) of1.- Specified by:
normalizein interfaceVector<Vector4>- Returns:
- The normalized vector of this vector
- Throws:
ArithmeticException- When the Euclidean norm of this vector is zero
-
normalizeOrZero
Normalizes this vector ot have a Euclidean norm (magnitude) of1. If this vector's Euclidean norm is zero, this will return itself. (which is guaranteed to be a vector where all components are zero, as only zero vectors have a Euclidean norm of zero)- Specified by:
normalizeOrZeroin interfaceVector<Vector4>- Returns:
- The normalized vector of this vector if successful, zero otherwise
-
normalizeOrDefault
Normalizes this vector to have a Euclidean norm (magnitude) of1. If this vector's Euclidean norm is zero, this will return the provided fallback valuev.- Specified by:
normalizeOrDefaultin interfaceVector<Vector4>- Parameters:
v- The value of which to return in case of division by zero- Returns:
- The normalized vector of this vector if successful, the fallback value
votherwise
-
negate
Negates all components of this vector, then returns the resulting vector. -
min
Between this vector and the provided boundary vectorv, this takes the minimum of each corresponding pair of components, then returns a new vector whose components are populated from that of the minimum values between each pair of components. -
max
Between this vector and the provided boundary vectorv, this takes the maximum of each corresponding pair of components, then returns a new vector whose components are populated from that of the maximum values between each pair of components. -
clamp
Between this vector and the provided boundary vectorsminandmax, this returns a new vector whose components are clamped to respect the range of[min, max]. This is the equivalent of clamping each component to the corresponding pair of minimum and maximum values. -
distance
Returns the Euclidean distance between this vector and the provided vectorv. -
distance2
Returns the squared Euclidean distance between this vector and the provided vectorv. -
distanceManhattan
Returns the Manhattan distance between this vector and the provided vectorv.- Specified by:
distanceManhattanin interfaceVector<Vector4>- Parameters:
v- The vector of which to get the Manhattan distance between- Returns:
- The Manhattan distance between the two vectors
-
map
Applies the provided mapper functionfto each component of this tuple, then returns a new tuple containing the return values of the functionf. -
merge
Between this vector and the provided vectorv, this applies the merger functionfto each corresponding pair of components, then returns a new vector whose components are populated from the return values of the functionf. -
equals
Checks for equality between this vector and the provided vectorv.
-