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
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract VdirectionTo(V v) Return the unit vector representing the direction of displacement from this vector to the given vector.abstract booleanReturn true if the current instance and given vector are considered equal as evaluated by the given precision context.protected doubleReturn the vector norm value, throwing anIllegalArgumentExceptionif the value is not real (ie, NaN or infinite) or zero.booleanisZero(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 VGet a vector constructed by linearly interpolating between this vector and the given vector.abstract VReturn the vector representing the displacement from this vector to the given vector.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Spatial
getDimension, isFinite, isInfinite, isNaN
-
Constructor Details
-
EuclideanVector
public EuclideanVector()
-
-
Method Details
-
vectorTo
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
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:
IllegalArgumentException- if the norm of the vector pointing from this instance tovis zero, NaN, or infinite
-
lerp
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, whereAis the current vector andBis 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. Thetparameter 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), wherenis the number of components in the vector andepsis 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:
-
getCheckedNorm
protected double getCheckedNorm()Return the vector norm value, throwing anIllegalArgumentExceptionif the value is not real (ie, NaN or infinite) or zero.- Returns:
- the vector norm value, guaranteed to be real and non-zero
- Throws:
IllegalArgumentException- if the vector norm is zero, NaN, or infinite
-