Package civitas.celestis.math.vector
Class ArrayVector
java.lang.Object
civitas.celestis.util.tuple.DoubleArrayTuple
civitas.celestis.math.vector.ArrayVector
- All Implemented Interfaces:
Vector<ArrayVector>,BaseTuple<Double>,DoubleTuple,Serializable
An arbitrary dimensional array-based vector.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionArrayVector(double... components) Creates a new vector.Creates a new vector. -
Method Summary
Modifier and TypeMethodDescriptionadd(double s) Adds a scalar to this vector component-wise, then returns the resulting vector.add(ArrayVector v) Adds another vector to this vector, then returns the resulting vector.clamp(ArrayVector min, ArrayVector max) 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.doubledot(ArrayVector v) Returns 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.max(ArrayVector v) 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(ArrayVector 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.min(ArrayVector v) 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.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.DoubleArrayTuple
array, boxed, contains, containsAll, equals, get, hashCode, isFinite, isInfinite, isNaN, isZero, list, mapToObj, size, stream, toStringMethods 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
-
Constructor Details
-
ArrayVector
public ArrayVector(@Nonnull double... components) Creates a new vector.- Parameters:
components- The components of this vector in sequential order
-
ArrayVector
Creates a new vector.- Parameters:
t- The tuple of which to copy component values from
-
-
Method Details
-
norm
public double norm()Returns the Euclidean norm (the magnitude) of this vector.- Specified by:
normin interfaceVector<ArrayVector>- Returns:
- The Euclidean norm of this vector
-
norm2
public double norm2()Returns the squared Euclidean norm (the squared magnitude) of this vector.- Specified by:
norm2in interfaceVector<ArrayVector>- Returns:
- The squared Euclidean norm of this vector
-
normManhattan
public double normManhattan()Returns the Manhattan norm of this vector.- Specified by:
normManhattanin interfaceVector<ArrayVector>- Returns:
- The Manhattan norm of this vector
-
add
Adds a scalar to this vector component-wise, then returns the resulting vector.- Specified by:
addin interfaceVector<ArrayVector>- Parameters:
s- The scalar of which to add to each component of this vector- Returns:
- The resulting vector
-
subtract
Subtracts this vector by a scalar component-wise, then returns the resulting vector.- Specified by:
subtractin interfaceVector<ArrayVector>- Parameters:
s- The scalar of which to subtract from each component of this vector- Returns:
- The resulting vector
-
multiply
Multiplies this vector by a scalar component-wise, then returns the resulting vector.- Specified by:
multiplyin interfaceVector<ArrayVector>- Parameters:
s- The scalar of which to multiply each component of this vector by- Returns:
- The resulting vector
-
divide
Divides this vector by a scalar component-wise, then returns the resulting vector.- Specified by:
dividein interfaceVector<ArrayVector>- 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.- Specified by:
addin interfaceVector<ArrayVector>- Parameters:
v- The vector of which to add to this vector- Returns:
- The resulting vector
-
subtract
Subtracts another vector from this vector, then returns the resulting vector.- Specified by:
subtractin interfaceVector<ArrayVector>- Parameters:
v- The vector of which to subtract from this vector- Returns:
- The resulting vector
-
dot
Returns the dot product between this vector and the provided vectorv.- Specified by:
dotin interfaceVector<ArrayVector>- Parameters:
v- The vector of which to get the dot product between- Returns:
- The dot product between the two vectors
-
normalize
Normalizes this vector to have a Euclidean norm (magnitude) of1.- Specified by:
normalizein interfaceVector<ArrayVector>- 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<ArrayVector>- 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<ArrayVector>- 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.- Specified by:
negatein interfaceVector<ArrayVector>- Returns:
- The negation of this 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.- Specified by:
minin interfaceVector<ArrayVector>- Parameters:
v- The boundary vector of which to compare to- Returns:
- The minimum vector of the two vectors
-
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.- Specified by:
maxin interfaceVector<ArrayVector>- Parameters:
v- The boundary vector of which to compare to- Returns:
- The maximum vector of the two vectors
-
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.- Specified by:
clampin interfaceVector<ArrayVector>- Parameters:
min- The minimum boundary vector to compare tomax- The maximum boundary vector to compare to- Returns:
- The clamped vector which respects the boundaries of
[min, max]
-
distance
Returns the Euclidean distance between this vector and the provided vectorv.- Specified by:
distancein interfaceVector<ArrayVector>- Parameters:
v- The vector of which get the Euclidean distance between- Returns:
- The Euclidean distance between the two vectors
-
distance2
Returns the squared Euclidean distance between this vector and the provided vectorv.- Specified by:
distance2in interfaceVector<ArrayVector>- Parameters:
v- The vector of which to get the squared Euclidean distance between- Returns:
- The squared Euclidean distance between the two vectors
-
distanceManhattan
Returns the Manhattan distance between this vector and the provided vectorv.- Specified by:
distanceManhattanin interfaceVector<ArrayVector>- 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.- Specified by:
mapin interfaceDoubleTuple- Specified by:
mapin interfaceVector<ArrayVector>- Overrides:
mapin classDoubleArrayTuple- Parameters:
f- The function of which to apply to each component of this vector- Returns:
- The resulting tuple
-
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.- Specified by:
mergein interfaceVector<ArrayVector>- Parameters:
v- The vector of which to merge this vector withf- The merger function to handle the merging of the two vectors- Returns:
- The resulting vector
-
equals
Checks for equality between this vector and the provided vectorv.- Specified by:
equalsin interfaceVector<ArrayVector>- Parameters:
v- The vector to compare to- Returns:
trueif the component values are equal
-