V
- Vector implementation typepublic interface Vector<V extends Vector<V>> extends Spatial
This interface uses self-referencing generic parameters to ensure that implementations are only used with instances of their own type. This removes the need for casting inside of methods in order to access implementation-specific data, such as coordinate values.
Modifier and Type | Method and Description |
---|---|
V |
add(double factor,
V v)
Add a scaled vector to the instance.
|
V |
add(V v)
Add a vector to the instance.
|
double |
angle(V v)
Compute the angular separation between two vectors in radians.
|
double |
distance(V v)
Compute the distance between the instance and another vector.
|
double |
distanceSq(V v)
Compute the square of the distance between the instance and another vector.
|
double |
dot(V v)
Compute the dot-product of the instance and another vector.
|
V |
getZero()
Get the zero (null) vector of the space.
|
V |
multiply(double a)
Multiply the instance by a scalar.
|
V |
negate()
Get the negation of the instance.
|
double |
norm()
Get the L2 norm (commonly known as the Euclidean norm) for the vector.
|
V |
normalize()
Get a normalized vector aligned with the instance.
|
V |
normalizeOrNull()
Attempt to compute a normalized vector aligned with the instance, returning null if
such a vector cannot be computed.
|
double |
normSq()
Get the square of the L2 norm (also known as the Euclidean norm)
for the vector.
|
V |
subtract(double factor,
V v)
Subtract a scaled vector from the instance.
|
V |
subtract(V v)
Subtract a vector from the instance.
|
V |
withNorm(double norm)
Returns a vector with the same direction but with the given
norm.
|
getDimension, isFinite, isInfinite, isNaN
double norm()
double normSq()
norm()
V withNorm(double norm)
vec.normalize().scalarMultiply(mag)
but without the intermediate vector.norm
- The vector normV add(double factor, V v)
factor
- scale factor to apply to v before adding itv
- vector to addV subtract(V v)
v
- vector to subtractV subtract(double factor, V v)
factor
- scale factor to apply to v before subtracting itv
- vector to subtractV negate()
V normalize()
IllegalArgumentException
- if the norm is zero, NaN, or infinitenormalizeOrNull()
V normalizeOrNull()
normalize()
but returns null instead of throwing an exception on failure.normalize()
V multiply(double a)
a
- scalardouble distance(V v)
v
- second vectordouble distanceSq(V v)
Calling this method is equivalent to calling:
q.subtract(p).getNormSq()
except that no intermediate
vector is built
v
- second vectornormSq()
double dot(V v)
v
- second vectordouble angle(V v)
v
- other vectorIllegalArgumentException
- if either vector has a zero, NaN, or infinite normCopyright © 2016–2021 The Apache Software Foundation. All rights reserved.