public class Vector3D extends MultiDimensionalEuclideanVector<Vector3D>
Modifier and Type | Class and Description |
---|---|
static class |
Vector3D.Sum
Class used to create high-accuracy sums of vectors.
|
static class |
Vector3D.Unit
Represents unit vectors.
|
Modifier and Type | Field and Description |
---|---|
static Comparator<Vector3D> |
COORDINATE_ASCENDING_ORDER
Comparator that sorts vectors in component-wise ascending order.
|
static Vector3D |
NaN
A vector with all coordinates set to NaN.
|
static Vector3D |
NEGATIVE_INFINITY
A vector with all coordinates set to negative infinity.
|
static Vector3D |
POSITIVE_INFINITY
A vector with all coordinates set to positive infinity.
|
static Vector3D |
ZERO
Zero (null) vector (coordinates: 0, 0, 0).
|
Modifier and Type | Method and Description |
---|---|
Vector3D |
add(double factor,
Vector3D v) |
Vector3D |
add(Vector3D v) |
double |
angle(Vector3D v) |
static Vector3D |
centroid(Iterable<Vector3D> pts)
Compute the centroid of the given points.
|
static Vector3D |
centroid(Vector3D first,
Vector3D... more)
Compute the centroid of the given points.
|
Vector3D |
cross(Vector3D v)
Compute the cross-product of the instance with another vector.
|
Vector3D.Unit |
directionTo(Vector3D v)
Return the unit vector representing the direction of displacement from this
vector to the given vector.
|
double |
distance(Vector3D v) |
double |
distanceSq(Vector3D v) |
double |
dot(Vector3D v) |
boolean |
eq(Vector3D 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)
d
Test for the equality of two vector instances.
|
int |
getDimension() |
double |
getX()
Return the x coordinate value (abscissa) of the instance.
|
double |
getY()
Return the y coordinate value (ordinate) of the instance.
|
double |
getZ()
Returns the z coordinate value (height) of the instance.
|
Vector3D |
getZero() |
int |
hashCode()
Get a hashCode for the vector.
|
boolean |
isFinite() |
boolean |
isInfinite() |
boolean |
isNaN() |
Vector3D |
lerp(Vector3D p,
double t)
Get a vector constructed by linearly interpolating between this vector and the given vector.
|
static Vector3D |
max(Iterable<Vector3D> vecs)
Return a vector containing the maximum component values from all input vectors.
|
static Vector3D |
max(Vector3D first,
Vector3D... more)
Return a vector containing the maximum component values from all input vectors.
|
static Vector3D |
min(Iterable<Vector3D> vecs)
Return a vector containing the minimum component values from all input vectors.
|
static Vector3D |
min(Vector3D first,
Vector3D... more)
Return a vector containing the minimum component values from all input vectors.
|
Vector3D |
multiply(double a) |
Vector3D |
negate() |
double |
norm() |
Vector3D.Unit |
normalize() |
Vector3D.Unit |
normalizeOrNull() |
double |
normSq() |
static Vector3D |
of(double[] v)
Creates a vector from the coordinates in the given 3-element array.
|
static Vector3D |
of(double x,
double y,
double z)
Returns a vector with the given coordinate values.
|
Vector3D.Unit |
orthogonal()
Get a unit vector orthogonal to the instance.
|
Vector3D.Unit |
orthogonal(Vector3D dir)
Get a unit vector orthogonal to the current vector and pointing in the direction
of
dir . |
static Vector3D |
parse(String str)
Parses the given string and returns a new vector instance.
|
Vector3D |
project(Vector3D base)
Get the projection of the instance onto the given base vector.
|
Vector3D |
reject(Vector3D base)
Get the rejection of the instance from the given base vector.
|
Vector3D |
subtract(double factor,
Vector3D v) |
Vector3D |
subtract(Vector3D v) |
double[] |
toArray()
Get the coordinates for this instance as a dimension 3 array.
|
String |
toString() |
Vector3D |
transform(UnaryOperator<Vector3D> fn)
Convenience method to apply a function to this vector.
|
Vector3D |
vectorTo(Vector3D v)
Return the vector representing the displacement from this vector
to the given vector.
|
Vector3D |
withNorm(double magnitude) |
getCheckedNorm, isZero
public static final Vector3D POSITIVE_INFINITY
public static final Vector3D NEGATIVE_INFINITY
public static final Comparator<Vector3D> COORDINATE_ASCENDING_ORDER
public double getX()
public double getY()
public double getZ()
public double[] toArray()
public int getDimension()
public boolean isNaN()
public boolean isInfinite()
public boolean isFinite()
public Vector3D vectorTo(Vector3D v)
v.subtract(thisVector)
but with a method name that is much easier to visualize.vectorTo
in class EuclideanVector<Vector3D>
v
- the vector that the returned vector will be directed towardpublic Vector3D.Unit directionTo(Vector3D v)
v.subtract(thisVector).normalize()
but without the intermediate vector instance.directionTo
in class EuclideanVector<Vector3D>
v
- the vector that the returned vector will be directed towardpublic Vector3D lerp(Vector3D 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<Vector3D>
p
- other vectort
- interpolation parameterpublic double norm()
public double normSq()
public Vector3D.Unit normalize()
public Vector3D.Unit normalizeOrNull()
public double distanceSq(Vector3D v)
public double dot(Vector3D v)
The implementation uses specific multiplication and addition algorithms to preserve accuracy and reduce cancellation effects. It should be very accurate even for nearly orthogonal vectors.
Sum
public double angle(Vector3D v)
This method computes the angular separation between two vectors using the dot product for well separated vectors and the cross product for almost aligned vectors. This allows to have a good accuracy in all cases, even for vectors very close to each other.
public Vector3D project(Vector3D base)
base
. Vector projection and rejection onto
a given base are related by the equation
v = vprojection + vrejection
project
in class MultiDimensionalEuclideanVector<Vector3D>
base
- base vectorbase
MultiDimensionalEuclideanVector.reject(MultiDimensionalEuclideanVector)
public Vector3D reject(Vector3D base)
base
. This operation can be interpreted as
returning the orthogonal projection of the instance onto the hyperplane
orthogonal to base
. Vector projection and rejection onto
a given base are related by the equation
v = vprojection + vrejection
reject
in class MultiDimensionalEuclideanVector<Vector3D>
base
- base vectorbase
MultiDimensionalEuclideanVector.project(MultiDimensionalEuclideanVector)
public Vector3D.Unit orthogonal()
There are an infinite number of normalized vectors orthogonal to the instance. This method picks up one of them almost arbitrarily. It is useful when one needs to compute a reference frame with one of the axes in a predefined direction. The following example shows how to build a frame having the k axis aligned with the known vector u :
Vector3D k = u.normalize();
Vector3D i = k.orthogonal();
Vector3D j = k.cross(i);
orthogonal
in class MultiDimensionalEuclideanVector<Vector3D>
IllegalArgumentException
- if the norm of the instance
is zero, NaN, or infinitepublic Vector3D.Unit orthogonal(Vector3D dir)
dir
. This method is equivalent to calling dir.reject(vec).normalize()
except that no intermediate vector object is produced.orthogonal
in class MultiDimensionalEuclideanVector<Vector3D>
dir
- the direction to use for generating the orthogonal vectordir
that does not lie along the current vectorpublic Vector3D cross(Vector3D v)
v
- other vectorpublic Vector3D transform(UnaryOperator<Vector3D> fn)
fn
- the function to applypublic boolean eq(Vector3D 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<Vector3D>
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 instances 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 Vector3D of(double x, double y, double z)
x
- x coordinate valuey
- y coordinate valuez
- z coordinate valuepublic static Vector3D of(double[] v)
v
- coordinates arrayIllegalArgumentException
- if the array does not have 3 elementspublic static Vector3D parse(String str)
toString()
.str
- the string to parseIllegalArgumentException
- if the given string has an invalid formatpublic static Vector3D max(Vector3D first, Vector3D... more)
first
- first vectormore
- additional vectorspublic static Vector3D max(Iterable<Vector3D> vecs)
vecs
- input vectorsIllegalArgumentException
- if the argument does not contain any vectorspublic static Vector3D min(Vector3D first, Vector3D... more)
first
- first vectormore
- additional vectorspublic static Vector3D min(Iterable<Vector3D> vecs)
vecs
- input vectorsIllegalArgumentException
- if the argument does not contain any vectorspublic static Vector3D centroid(Vector3D first, Vector3D... more)
first
- first pointmore
- additional pointspublic static Vector3D centroid(Iterable<Vector3D> pts)
pts
- the points to compute the centroid ofIllegalArgumentException
- if the argument contains no pointsCopyright © 2016–2021 The Apache Software Foundation. All rights reserved.