Package civitas.celestis.math.vector
Class Vector3
java.lang.Object
civitas.celestis.util.tuple.Double3
civitas.celestis.math.vector.Vector3
- All Implemented Interfaces:
Vector<Vector3>,BaseTuple<Double>,DoubleTuple,Serializable
An immutable three-dimensional vector which uses the type
double.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Vector3The negative X unit vector.static final Vector3The negative Y unit vector.static final Vector3The negative Z unit vector.static final Vector3The positive X unit vector.static final Vector3The positive Y unit vector.static final Vector3The positive Z unit vector.static final Vector3A vector of no direction or 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].Returns the cross product between this vector and the provided vectorv.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(Vector3 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.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.Converts this vector into a pure quaternion.rotate(Quaternion q) Rotates this vector by the provided rotation quaternionq.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.Double3
array, boxed, contains, containsAll, equals, get, hashCode, isFinite, isInfinite, isNaN, isZero, list, mapToObj, size, stream, toString, 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 or magnitude. Represents origin. -
POSITIVE_X
The positive X unit vector. -
POSITIVE_Y
The positive Y unit vector. -
POSITIVE_Z
The positive Z 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
-
Vector3
public Vector3(double x, double y, double z) Creates a new vector.- Parameters:
x- The X component of this vectory- The Y component of this vectorz- The Z component of this vector
-
Vector3
public Vector3(@Nonnull double[] components) Creates a new vector.- Parameters:
components- An array containing the components of this vector in XYZ order- Throws:
IllegalArgumentException- When the provided array's length is not3
-
Vector3
Creates a new vector.- Parameters:
t- The tuple of which to copy component values from- Throws:
IllegalArgumentException- When the provided tuplet's size is not3
-
-
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<Vector3>- 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<Vector3>- 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. -
cross
Returns the cross product between this vector and the provided vectorv.- Parameters:
v- The vector of which to get the cross product between- Returns:
- The cross 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<Vector3>- 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<Vector3>- 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<Vector3>- 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<Vector3>- 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. -
quaternion
Converts this vector into a pure quaternion. (a quaternion whose scalar part is0, and the vector part is populated from this vector's components)- Returns:
- A pure quaternion constructed from this vector
-
rotate
Rotates this vector by the provided rotation quaternionq.- Parameters:
q- The rotation quaternion of which to apply to this vector- Returns:
- The rotated vector
-
equals
Checks for equality between this vector and the provided vectorv.
-