Class EuclideanVector<V extends EuclideanVector<V>>
- java.lang.Object
-
- org.apache.commons.geometry.euclidean.EuclideanVector<V>
-
- Type Parameters:
V
- Vector implementation type
- Direct Known Subclasses:
MultiDimensionalEuclideanVector
,Vector1D
public abstract class EuclideanVector<V extends EuclideanVector<V>> extends java.lang.Object implements Vector<V>, Point<V>
Abstract base class for Euclidean vectors and points. Seehere
for a discussion of the combination of point and vector functionality into a single class hierarchy.
-
-
Constructor Summary
Constructors Constructor Description EuclideanVector()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract V
directionTo(V v)
Return the unit vector representing the direction of displacement from this vector to the given vector.abstract boolean
eq(V v, org.apache.commons.numbers.core.Precision.DoubleEquivalence precision)
Return true if the current instance and given vector are considered equal as evaluated by the given precision context.protected double
getCheckedNorm()
Return the vector norm value, throwing anIllegalArgumentException
if the value is not real (ie, NaN or infinite) or zero.boolean
isZero(org.apache.commons.numbers.core.Precision.DoubleEquivalence precision)
Return true if the current instance is considered equal to the zero vector as evaluated by the given precision context.abstract V
lerp(V v, double t)
Get a vector constructed by linearly interpolating between this vector and the given vector.abstract V
vectorTo(V v)
Return the vector representing the displacement from this vector to the given vector.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.commons.geometry.core.Spatial
getDimension, isFinite, isInfinite, isNaN
-
-
-
-
Method Detail
-
vectorTo
public abstract V vectorTo(V v)
Return the vector representing the displacement from this vector to the given vector. This is exactly equivalent tov.subtract(thisVector)
but with a method name that is much easier to visualize.- Parameters:
v
- the vector that the returned vector will be directed toward- Returns:
- vector representing the displacement from this vector to the given vector
-
directionTo
public abstract V directionTo(V v)
Return the unit vector representing the direction of displacement from this vector to the given vector. This is exactly equivalent tov.subtract(thisVector).normalize()
but without the intermediate vector instance.- Parameters:
v
- the vector that the returned vector will be directed toward- Returns:
- unit vector representing the direction of displacement from this vector to the given vector
- Throws:
java.lang.IllegalArgumentException
- if the norm of the vector pointing from this instance tov
is zero, NaN, or infinite
-
lerp
public abstract V lerp(V v, double t)
Get a vector constructed by linearly interpolating between this vector and the given vector. The vector coordinates are generated by the equationV = (1 - t)*A + t*B
, whereA
is the current vector andB
is the given vector. This means that ift = 0
, a vector equal to the current vector will be returned. Ift = 1
, a vector equal to the argument will be returned. Thet
parameter is not constrained to the range[0, 1]
, meaning that linear extrapolation can also be performed with this method.- Parameters:
v
- other vectort
- interpolation parameter- Returns:
- interpolated or extrapolated vector
-
eq
public abstract boolean eq(V v, org.apache.commons.numbers.core.Precision.DoubleEquivalence precision)
Return true if the current instance and given vector are considered equal as evaluated by the given precision context.Equality is determined by comparing each pair of components in turn from the two vectors. If all components evaluate as equal, then the vectors are considered equal. If any are not equal, then the vectors are not considered equal. Note that this approach means that the calculated distance between two "equal" vectors may be as much as
√(n * eps2)
, wheren
is the number of components in the vector andeps
is the maximum epsilon value allowed by the precision context.- Parameters:
v
- vector to check for equalityprecision
- precision context used to determine floating point equality- Returns:
- true if the current instance is considered equal to the given vector when using the given precision context; otherwise false
-
isZero
public boolean isZero(org.apache.commons.numbers.core.Precision.DoubleEquivalence precision)
Return true if the current instance is considered equal to the zero vector as evaluated by the given precision context. This is a convenience method equivalent tovec.equals(vec.getZero(), precision)
.- Parameters:
precision
- precision context used to determine floating point equality- Returns:
- true if the current instance is considered equal to the zero vector when using the given precision context; otherwise false
- See Also:
eq(EuclideanVector, Precision.DoubleEquivalence)
-
getCheckedNorm
protected double getCheckedNorm()
Return the vector norm value, throwing anIllegalArgumentException
if the value is not real (ie, NaN or infinite) or zero.- Returns:
- the vector norm value, guaranteed to be real and non-zero
- Throws:
java.lang.IllegalArgumentException
- if the vector norm is zero, NaN, or infinite
-
-