public class Vector1D extends EuclideanVector<Vector1D>
Modifier and Type | Class and Description |
---|---|
static class |
Vector1D.Sum
Class used to create high-accuracy sums of vectors.
|
static class |
Vector1D.Unit
Represent unit vectors.
|
Modifier and Type | Field and Description |
---|---|
static Comparator<Vector1D> |
COORDINATE_ASCENDING_ORDER
Comparator that sorts vectors in component-wise ascending order.
|
static Vector1D |
NaN
A vector with all coordinates set to NaN.
|
static Vector1D |
NEGATIVE_INFINITY
A vector with all coordinates set to negative infinity.
|
static Vector1D |
POSITIVE_INFINITY
A vector with all coordinates set to positive infinity.
|
static Vector1D |
ZERO
Zero vector (coordinates: 0).
|
Modifier and Type | Method and Description |
---|---|
Vector1D |
add(double factor,
Vector1D v) |
Vector1D |
add(Vector1D v) |
double |
angle(Vector1D v) |
Vector1D.Unit |
directionTo(Vector1D v)
Return the unit vector representing the direction of displacement from this
vector to the given vector.
|
double |
distance(Vector1D v) |
double |
distanceSq(Vector1D v) |
double |
dot(Vector1D v) |
boolean |
eq(Vector1D vec,
Precision.DoubleEquivalence precision)
Return true if the current instance and given vector are considered equal as evaluated by the
given precision context.
|
boolean |
equals(Object other)
Test for the equality of two vectors.
|
int |
getDimension() |
double |
getX()
Returns the abscissa (coordinate value) of the instance.
|
Vector1D |
getZero() |
int |
hashCode()
Get a hashCode for the vector.
|
boolean |
isFinite() |
boolean |
isInfinite() |
boolean |
isNaN() |
Vector1D |
lerp(Vector1D p,
double t)
Get a vector constructed by linearly interpolating between this vector and the given vector.
|
Vector1D |
multiply(double a) |
Vector1D |
negate() |
double |
norm() |
Vector1D.Unit |
normalize() |
Vector1D.Unit |
normalizeOrNull() |
double |
normSq() |
static Vector1D |
of(double x)
Returns a vector with the given coordinate value.
|
static Vector1D |
parse(String str)
Parses the given string and returns a new vector instance.
|
Vector1D |
subtract(double factor,
Vector1D v) |
Vector1D |
subtract(Vector1D v) |
String |
toString() |
Vector1D |
transform(UnaryOperator<Vector1D> fn)
Convenience method to apply a function to this vector.
|
Vector1D |
vectorTo(Vector1D v)
Return the vector representing the displacement from this vector
to the given vector.
|
Vector1D |
withNorm(double magnitude) |
getCheckedNorm, isZero
public static final Vector1D POSITIVE_INFINITY
public static final Vector1D NEGATIVE_INFINITY
public static final Comparator<Vector1D> COORDINATE_ASCENDING_ORDER
public double getX()
public int getDimension()
public boolean isNaN()
public boolean isInfinite()
public boolean isFinite()
public Vector1D vectorTo(Vector1D v)
v.subtract(thisVector)
but with a method name that is much easier to visualize.vectorTo
in class EuclideanVector<Vector1D>
v
- the vector that the returned vector will be directed towardpublic Vector1D.Unit directionTo(Vector1D v)
v.subtract(thisVector).normalize()
but without the intermediate vector instance.directionTo
in class EuclideanVector<Vector1D>
v
- the vector that the returned vector will be directed towardpublic Vector1D lerp(Vector1D p, double t)
V = (1 - t)*A + t*B
, where A
is the current vector and B
is the given vector. This means that if t = 0
, a
vector equal to the current vector will be returned. If t = 1
, a vector equal to the
argument will be returned. The t
parameter is not constrained to the range [0, 1]
,
meaning that linear extrapolation can also be performed with this method.lerp
in class EuclideanVector<Vector1D>
p
- other vectort
- interpolation parameterpublic double norm()
public double normSq()
public Vector1D.Unit normalize()
public Vector1D.Unit normalizeOrNull()
public double distanceSq(Vector1D v)
public double angle(Vector1D v)
For the one-dimensional case, this method returns 0 if the vector x values have
the same sign and pi
if they are opposite.
public Vector1D transform(UnaryOperator<Vector1D> fn)
fn
- the function to applypublic boolean eq(Vector1D vec, Precision.DoubleEquivalence precision)
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)
,
where n
is the number of components in the vector and eps
is the maximum epsilon
value allowed by the precision context.
eq
in class EuclideanVector<Vector1D>
vec
- vector to check for equalityprecision
- precision context used to determine floating point equalitypublic int hashCode()
All NaN values have the same hash code.
public boolean equals(Object other)
If all coordinates of two vectors are exactly the same, and none are
Double.NaN
, the two vectors are considered to be equal.
NaN
coordinates are considered to globally affect the vector
and be equal to each other - i.e, if either (or all) coordinates of the
vector are equal to Double.NaN
, the vector is equal to
NaN
.
public static Vector1D of(double x)
x
- vector coordinatepublic static Vector1D parse(String str)
toString()
.str
- the string to parseIllegalArgumentException
- if the given string has an invalid formatCopyright © 2016–2021 The Apache Software Foundation. All rights reserved.