Class Vector3D
- java.lang.Object
-
- org.hipparchus.geometry.euclidean.threed.Vector3D
-
- All Implemented Interfaces:
Serializable
,Point<Euclidean3D>
,Vector<Euclidean3D,Vector3D>
,Blendable<Vector<Euclidean3D,Vector3D>>
public class Vector3D extends Object implements Serializable, Vector<Euclidean3D,Vector3D>
This class implements vectors in a three-dimensional space.Instance of this class are guaranteed to be immutable.
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static Vector3D
MINUS_I
Opposite of the first canonical vector (coordinates: -1, 0, 0).static Vector3D
MINUS_J
Opposite of the second canonical vector (coordinates: 0, -1, 0).static Vector3D
MINUS_K
Opposite of the third canonical vector (coordinates: 0, 0, -1).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
PLUS_I
First canonical vector (coordinates: 1, 0, 0).static Vector3D
PLUS_J
Second canonical vector (coordinates: 0, 1, 0).static Vector3D
PLUS_K
Third canonical vector (coordinates: 0, 0, 1).static Vector3D
POSITIVE_INFINITY
A vector with all coordinates set to positive infinity.static Vector3D
ZERO
Null vector (coordinates: 0, 0, 0).
-
Constructor Summary
Constructors Constructor Description Vector3D(double[] v)
Simple constructor.Vector3D(double alpha, double delta)
Simple constructor.Vector3D(double x, double y, double z)
Simple constructor.Vector3D(double a, Vector3D u)
Multiplicative constructor Build a vector from another one and a scale factor.Vector3D(double a1, Vector3D u1, double a2, Vector3D u2)
Linear constructor Build a vector from two other ones and corresponding scale factors.Vector3D(double a1, Vector3D u1, double a2, Vector3D u2, double a3, Vector3D u3)
Linear constructor Build a vector from three other ones and corresponding scale factors.Vector3D(double a1, Vector3D u1, double a2, Vector3D u2, double a3, Vector3D u3, double a4, Vector3D u4)
Linear constructor Build a vector from four other ones and corresponding scale factors.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Vector3D
add(double factor, Vector<Euclidean3D,Vector3D> v)
Add a scaled vector to the instance.Vector3D
add(Vector<Euclidean3D,Vector3D> v)
Add a vector to the instance.static double
angle(Vector3D v1, Vector3D v2)
Compute the angular separation between two vectors.static Vector3D
crossProduct(Vector3D v1, Vector3D v2)
Compute the cross-product of two vectors.Vector3D
crossProduct(Vector<Euclidean3D,Vector3D> v)
Compute the cross-product of the instance with another vector.static double
distance(Vector3D v1, Vector3D v2)
Compute the distance between two vectors according to the L2 norm.double
distance(Point<Euclidean3D> v)
Compute the distance between the instance and another point.static double
distance1(Vector3D v1, Vector3D v2)
Compute the distance between two vectors according to the L1 norm.double
distance1(Vector<Euclidean3D,Vector3D> v)
Compute the distance between the instance and another vector according to the L1 norm.static double
distanceInf(Vector3D v1, Vector3D v2)
Compute the distance between two vectors according to the L∞ norm.double
distanceInf(Vector<Euclidean3D,Vector3D> v)
Compute the distance between the instance and another vector according to the L∞ norm.static double
distanceSq(Vector3D v1, Vector3D v2)
Compute the square of the distance between two vectors.double
distanceSq(Vector<Euclidean3D,Vector3D> v)
Compute the square of the distance between the instance and another vector.static double
dotProduct(Vector3D v1, Vector3D v2)
Compute the dot-product of two vectors.double
dotProduct(Vector<Euclidean3D,Vector3D> v)
Compute the dot-product of the instance and another vector.boolean
equals(Object other)
Test for the equality of two 3D vectors.boolean
equalsIeee754(Object other)
Test for the equality of two 3D vectors.double
getAlpha()
Get the azimuth of the vector.double
getDelta()
Get the elevation of the vector.double
getNorm()
Get the L2 norm for the vector.double
getNorm1()
Get the L1 norm for the vector.double
getNormInf()
Get the L∞ norm for the vector.double
getNormSq()
Get the square of the norm for the vector.Space
getSpace()
Get the space to which the point belongs.double
getX()
Get the abscissa of the vector.double
getY()
Get the ordinate of the vector.double
getZ()
Get the height of the vector.Vector3D
getZero()
Get the null vector of the vectorial space or origin point of the affine space.int
hashCode()
Get a hashCode for the 3D vector.boolean
isInfinite()
Returns true if any coordinate of this vector is infinite and none are NaN; false otherwiseboolean
isNaN()
Returns true if any coordinate of this point is NaN; false otherwiseVector3D
negate()
Get the opposite of the instance.Vector3D
orthogonal()
Get a vector orthogonal to the instance.Vector3D
scalarMultiply(double a)
Multiply the instance by a scalar.Vector3D
subtract(double factor, Vector<Euclidean3D,Vector3D> v)
Subtract a scaled vector from the instance.Vector3D
subtract(Vector<Euclidean3D,Vector3D> v)
Subtract a vector from the instance.double[]
toArray()
Get the vector coordinates as a dimension 3 array.String
toString()
Get a string representation of this vector.String
toString(NumberFormat format)
Get a string representation of this vector.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.hipparchus.geometry.Vector
blendArithmeticallyWith, normalize
-
-
-
-
Field Detail
-
ZERO
public static final Vector3D ZERO
Null vector (coordinates: 0, 0, 0).
-
PLUS_I
public static final Vector3D PLUS_I
First canonical vector (coordinates: 1, 0, 0).
-
MINUS_I
public static final Vector3D MINUS_I
Opposite of the first canonical vector (coordinates: -1, 0, 0).
-
PLUS_J
public static final Vector3D PLUS_J
Second canonical vector (coordinates: 0, 1, 0).
-
MINUS_J
public static final Vector3D MINUS_J
Opposite of the second canonical vector (coordinates: 0, -1, 0).
-
PLUS_K
public static final Vector3D PLUS_K
Third canonical vector (coordinates: 0, 0, 1).
-
MINUS_K
public static final Vector3D MINUS_K
Opposite of the third canonical vector (coordinates: 0, 0, -1).
-
NaN
public static final Vector3D NaN
A vector with all coordinates set to NaN.
-
POSITIVE_INFINITY
public static final Vector3D POSITIVE_INFINITY
A vector with all coordinates set to positive infinity.
-
NEGATIVE_INFINITY
public static final Vector3D NEGATIVE_INFINITY
A vector with all coordinates set to negative infinity.
-
-
Constructor Detail
-
Vector3D
public Vector3D(double x, double y, double z)
Simple constructor. Build a vector from its coordinates
-
Vector3D
public Vector3D(double[] v) throws MathIllegalArgumentException
Simple constructor. Build a vector from its coordinates- Parameters:
v
- coordinates array- Throws:
MathIllegalArgumentException
- if array does not have 3 elements- See Also:
toArray()
-
Vector3D
public Vector3D(double alpha, double delta)
Simple constructor. Build a vector from its azimuthal coordinates- Parameters:
alpha
- azimuth (α) around Z (0 is +X, π/2 is +Y, π is -X and 3π/2 is -Y)delta
- elevation (δ) above (XY) plane, from -π/2 to +π/2- See Also:
getAlpha()
,getDelta()
-
Vector3D
public Vector3D(double a, Vector3D u)
Multiplicative constructor Build a vector from another one and a scale factor. The vector built will be a * u- Parameters:
a
- scale factoru
- base (unscaled) vector
-
Vector3D
public Vector3D(double a1, Vector3D u1, double a2, Vector3D u2)
Linear constructor Build a vector from two other ones and corresponding scale factors. The vector built will be a1 * u1 + a2 * u2- Parameters:
a1
- first scale factoru1
- first base (unscaled) vectora2
- second scale factoru2
- second base (unscaled) vector
-
Vector3D
public Vector3D(double a1, Vector3D u1, double a2, Vector3D u2, double a3, Vector3D u3)
Linear constructor Build a vector from three other ones and corresponding scale factors. The vector built will be a1 * u1 + a2 * u2 + a3 * u3- Parameters:
a1
- first scale factoru1
- first base (unscaled) vectora2
- second scale factoru2
- second base (unscaled) vectora3
- third scale factoru3
- third base (unscaled) vector
-
Vector3D
public Vector3D(double a1, Vector3D u1, double a2, Vector3D u2, double a3, Vector3D u3, double a4, Vector3D u4)
Linear constructor Build a vector from four other ones and corresponding scale factors. The vector built will be a1 * u1 + a2 * u2 + a3 * u3 + a4 * u4- Parameters:
a1
- first scale factoru1
- first base (unscaled) vectora2
- second scale factoru2
- second base (unscaled) vectora3
- third scale factoru3
- third base (unscaled) vectora4
- fourth scale factoru4
- fourth base (unscaled) vector
-
-
Method Detail
-
getX
public double getX()
Get the abscissa of the vector.- Returns:
- abscissa of the vector
- See Also:
Vector3D(double, double, double)
-
getY
public double getY()
Get the ordinate of the vector.- Returns:
- ordinate of the vector
- See Also:
Vector3D(double, double, double)
-
getZ
public double getZ()
Get the height of the vector.- Returns:
- height of the vector
- See Also:
Vector3D(double, double, double)
-
toArray
public double[] toArray()
Get the vector coordinates as a dimension 3 array.- Returns:
- vector coordinates
- See Also:
Vector3D(double[])
-
getSpace
public Space getSpace()
Get the space to which the point belongs.- Specified by:
getSpace
in interfacePoint<Euclidean3D>
- Returns:
- containing space
-
getZero
public Vector3D getZero()
Get the null vector of the vectorial space or origin point of the affine space.- Specified by:
getZero
in interfaceVector<Euclidean3D,Vector3D>
- Returns:
- null vector of the vectorial space or origin point of the affine space
-
getNorm1
public double getNorm1()
Get the L1 norm for the vector.- Specified by:
getNorm1
in interfaceVector<Euclidean3D,Vector3D>
- Returns:
- L1 norm for the vector
-
getNorm
public double getNorm()
Get the L2 norm for the vector.- Specified by:
getNorm
in interfaceVector<Euclidean3D,Vector3D>
- Returns:
- Euclidean norm for the vector
-
getNormSq
public double getNormSq()
Get the square of the norm for the vector.- Specified by:
getNormSq
in interfaceVector<Euclidean3D,Vector3D>
- Returns:
- square of the Euclidean norm for the vector
-
getNormInf
public double getNormInf()
Get the L∞ norm for the vector.- Specified by:
getNormInf
in interfaceVector<Euclidean3D,Vector3D>
- Returns:
- L∞ norm for the vector
-
getAlpha
public double getAlpha()
Get the azimuth of the vector.- Returns:
- azimuth (α) of the vector, between -π and +π
- See Also:
Vector3D(double, double)
-
getDelta
public double getDelta()
Get the elevation of the vector.- Returns:
- elevation (δ) of the vector, between -π/2 and +π/2
- See Also:
Vector3D(double, double)
-
add
public Vector3D add(Vector<Euclidean3D,Vector3D> v)
Add a vector to the instance.- Specified by:
add
in interfaceVector<Euclidean3D,Vector3D>
- Parameters:
v
- vector to add- Returns:
- a new vector
-
add
public Vector3D add(double factor, Vector<Euclidean3D,Vector3D> v)
Add a scaled vector to the instance.- Specified by:
add
in interfaceVector<Euclidean3D,Vector3D>
- Parameters:
factor
- scale factor to apply to v before adding itv
- vector to add- Returns:
- a new vector
-
subtract
public Vector3D subtract(Vector<Euclidean3D,Vector3D> v)
Subtract a vector from the instance.- Specified by:
subtract
in interfaceVector<Euclidean3D,Vector3D>
- Parameters:
v
- vector to subtract- Returns:
- a new vector
-
subtract
public Vector3D subtract(double factor, Vector<Euclidean3D,Vector3D> v)
Subtract a scaled vector from the instance.- Specified by:
subtract
in interfaceVector<Euclidean3D,Vector3D>
- Parameters:
factor
- scale factor to apply to v before subtracting itv
- vector to subtract- Returns:
- a new vector
-
orthogonal
public Vector3D orthogonal() throws MathRuntimeException
Get a vector orthogonal to the instance.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 = Vector3D.crossProduct(k, i);
- Returns:
- a new normalized vector orthogonal to the instance
- Throws:
MathRuntimeException
- if the norm of the instance is null
-
angle
public static double angle(Vector3D v1, Vector3D v2) throws MathRuntimeException
Compute the angular separation between two vectors.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.
- Parameters:
v1
- first vectorv2
- second vector- Returns:
- angular separation between v1 and v2
- Throws:
MathRuntimeException
- if either vector has a null norm
-
negate
public Vector3D negate()
Get the opposite of the instance.- Specified by:
negate
in interfaceVector<Euclidean3D,Vector3D>
- Returns:
- a new vector which is opposite to the instance
-
scalarMultiply
public Vector3D scalarMultiply(double a)
Multiply the instance by a scalar.- Specified by:
scalarMultiply
in interfaceVector<Euclidean3D,Vector3D>
- Parameters:
a
- scalar- Returns:
- a new vector
-
isNaN
public boolean isNaN()
Returns true if any coordinate of this point is NaN; false otherwise- Specified by:
isNaN
in interfacePoint<Euclidean3D>
- Returns:
- true if any coordinate of this point is NaN; false otherwise
-
isInfinite
public boolean isInfinite()
Returns true if any coordinate of this vector is infinite and none are NaN; false otherwise- Specified by:
isInfinite
in interfaceVector<Euclidean3D,Vector3D>
- Returns:
- true if any coordinate of this vector is infinite and none are NaN; false otherwise
-
equals
public boolean equals(Object other)
Test for the equality of two 3D vectors.If all coordinates of two 3D vectors are exactly the same, and none are
Double.NaN
, the two 3D vectors are considered to be equal.NaN
coordinates are considered to affect globally the vector and be equals to each other - i.e, if either (or all) coordinates of the 3D vector are equal toDouble.NaN
, the 3D vector is equal toNaN
.
-
equalsIeee754
public boolean equalsIeee754(Object other)
Test for the equality of two 3D vectors.If all coordinates of two 3D vectors are exactly the same, and none are
NaN
, the two 3D vectors are considered to be equal.In compliance with IEEE754 handling, if any coordinates of any of the two vectors are
NaN
, then the vectors are considered different. This implies thatVector3D.NaN
.equals(Vector3D.NaN
) returnsfalse
despite the instance is checked against itself.- Parameters:
other
- Object to test for equality to this- Returns:
- true if two 3D vector objects are equal, false if object is null, not an instance of Vector3D, or not equal to this Vector3D instance
- Since:
- 2.1
-
hashCode
public int hashCode()
Get a hashCode for the 3D vector.All NaN values have the same hash code.
-
dotProduct
public double dotProduct(Vector<Euclidean3D,Vector3D> v)
Compute the dot-product of the instance and another vector.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.
- Specified by:
dotProduct
in interfaceVector<Euclidean3D,Vector3D>
- Parameters:
v
- second vector- Returns:
- the dot product this.v
- See Also:
MathArrays.linearCombination(double, double, double, double, double, double)
-
crossProduct
public Vector3D crossProduct(Vector<Euclidean3D,Vector3D> v)
Compute the cross-product of the instance with another vector.- Parameters:
v
- other vector- Returns:
- the cross product this ^ v as a new Vector3D
-
distance1
public double distance1(Vector<Euclidean3D,Vector3D> v)
Compute the distance between the instance and another vector according to the L1 norm.Calling this method is equivalent to calling:
q.subtract(p).getNorm1()
except that no intermediate vector is built- Specified by:
distance1
in interfaceVector<Euclidean3D,Vector3D>
- Parameters:
v
- second vector- Returns:
- the distance between the instance and p according to the L1 norm
-
distance
public double distance(Point<Euclidean3D> v)
Compute the distance between the instance and another point.- Specified by:
distance
in interfacePoint<Euclidean3D>
- Parameters:
v
- second point- Returns:
- the distance between the instance and p
-
distanceInf
public double distanceInf(Vector<Euclidean3D,Vector3D> v)
Compute the distance between the instance and another vector according to the L∞ norm.Calling this method is equivalent to calling:
q.subtract(p).getNormInf()
except that no intermediate vector is built- Specified by:
distanceInf
in interfaceVector<Euclidean3D,Vector3D>
- Parameters:
v
- second vector- Returns:
- the distance between the instance and p according to the L∞ norm
-
distanceSq
public double distanceSq(Vector<Euclidean3D,Vector3D> v)
Compute the square of the distance between the instance and another vector.Calling this method is equivalent to calling:
q.subtract(p).getNormSq()
except that no intermediate vector is built- Specified by:
distanceSq
in interfaceVector<Euclidean3D,Vector3D>
- Parameters:
v
- second vector- Returns:
- the square of the distance between the instance and p
-
dotProduct
public static double dotProduct(Vector3D v1, Vector3D v2)
Compute the dot-product of two vectors.- Parameters:
v1
- first vectorv2
- second vector- Returns:
- the dot product v1.v2
-
crossProduct
public static Vector3D crossProduct(Vector3D v1, Vector3D v2)
Compute the cross-product of two vectors.- Parameters:
v1
- first vectorv2
- second vector- Returns:
- the cross product v1 ^ v2 as a new Vector
-
distance1
public static double distance1(Vector3D v1, Vector3D v2)
Compute the distance between two vectors according to the L1 norm.Calling this method is equivalent to calling:
v1.subtract(v2).getNorm1()
except that no intermediate vector is built- Parameters:
v1
- first vectorv2
- second vector- Returns:
- the distance between v1 and v2 according to the L1 norm
-
distance
public static double distance(Vector3D v1, Vector3D v2)
Compute the distance between two vectors according to the L2 norm.Calling this method is equivalent to calling:
v1.subtract(v2).getNorm()
except that no intermediate vector is built- Parameters:
v1
- first vectorv2
- second vector- Returns:
- the distance between v1 and v2 according to the L2 norm
-
distanceInf
public static double distanceInf(Vector3D v1, Vector3D v2)
Compute the distance between two vectors according to the L∞ norm.Calling this method is equivalent to calling:
v1.subtract(v2).getNormInf()
except that no intermediate vector is built- Parameters:
v1
- first vectorv2
- second vector- Returns:
- the distance between v1 and v2 according to the L∞ norm
-
distanceSq
public static double distanceSq(Vector3D v1, Vector3D v2)
Compute the square of the distance between two vectors.Calling this method is equivalent to calling:
v1.subtract(v2).getNormSq()
except that no intermediate vector is built- Parameters:
v1
- first vectorv2
- second vector- Returns:
- the square of the distance between v1 and v2
-
toString
public String toString()
Get a string representation of this vector.
-
toString
public String toString(NumberFormat format)
Get a string representation of this vector.- Specified by:
toString
in interfaceVector<Euclidean3D,Vector3D>
- Parameters:
format
- the custom format for components- Returns:
- a string representation of this vector
-
-