Class Vector1D
- java.lang.Object
-
- org.hipparchus.geometry.euclidean.oned.Vector1D
-
- All Implemented Interfaces:
Serializable
,Point<Euclidean1D>
,Vector<Euclidean1D,Vector1D>
,Blendable<Vector<Euclidean1D,Vector1D>>
public class Vector1D extends Object implements Vector<Euclidean1D,Vector1D>
This class represents a 1D vector.Instances of this class are guaranteed to be immutable.
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description 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
ONE
Unit (coordinates: 1).static Vector1D
POSITIVE_INFINITY
A vector with all coordinates set to positive infinity.static Vector1D
ZERO
Origin (coordinates: 0).
-
Constructor Summary
Constructors Constructor Description Vector1D(double x)
Simple constructor.Vector1D(double a, Vector1D u)
Multiplicative constructor Build a vector from another one and a scale factor.Vector1D(double a1, Vector1D u1, double a2, Vector1D u2)
Linear constructor Build a vector from two other ones and corresponding scale factors.Vector1D(double a1, Vector1D u1, double a2, Vector1D u2, double a3, Vector1D u3)
Linear constructor Build a vector from three other ones and corresponding scale factors.Vector1D(double a1, Vector1D u1, double a2, Vector1D u2, double a3, Vector1D u3, double a4, Vector1D 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 Vector1D
add(double factor, Vector<Euclidean1D,Vector1D> v)
Add a scaled vector to the instance.Vector1D
add(Vector<Euclidean1D,Vector1D> v)
Add a vector to the instance.static double
distance(Vector1D p1, Vector1D p2)
Compute the distance between two vectors according to the L2 norm.double
distance(Point<Euclidean1D> p)
Compute the distance between the instance and another point.double
distance1(Vector<Euclidean1D,Vector1D> p)
Compute the distance between the instance and another vector according to the L1 norm.static double
distanceInf(Vector1D p1, Vector1D p2)
Compute the distance between two vectors according to the L∞ norm.double
distanceInf(Vector<Euclidean1D,Vector1D> p)
Compute the distance between the instance and another vector according to the L∞ norm.static double
distanceSq(Vector1D p1, Vector1D p2)
Compute the square of the distance between two vectors.double
distanceSq(Vector<Euclidean1D,Vector1D> p)
Compute the square of the distance between the instance and another vector.double
dotProduct(Vector<Euclidean1D,Vector1D> v)
Compute the dot-product of the instance and another vector.boolean
equals(Object other)
Test for the equality of two 1D vectors.boolean
equalsIeee754(Object other)
Test for the equality of two 1D vectors.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.Vector1D
getZero()
Get the null vector of the vectorial space or origin point of the affine space.int
hashCode()
Get a hashCode for the 1D 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 otherwiseVector1D
negate()
Get the opposite of the instance.Vector1D
scalarMultiply(double a)
Multiply the instance by a scalar.Vector1D
subtract(double factor, Vector<Euclidean1D,Vector1D> v)
Subtract a scaled vector from the instance.Vector1D
subtract(Vector<Euclidean1D,Vector1D> p)
Subtract a vector from the instance.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 Vector1D ZERO
Origin (coordinates: 0).
-
ONE
public static final Vector1D ONE
Unit (coordinates: 1).
-
NaN
public static final Vector1D NaN
A vector with all coordinates set to NaN.
-
POSITIVE_INFINITY
public static final Vector1D POSITIVE_INFINITY
A vector with all coordinates set to positive infinity.
-
NEGATIVE_INFINITY
public static final Vector1D NEGATIVE_INFINITY
A vector with all coordinates set to negative infinity.
-
-
Constructor Detail
-
Vector1D
public Vector1D(double x)
Simple constructor. Build a vector from its coordinates- Parameters:
x
- abscissa- See Also:
getX()
-
Vector1D
public Vector1D(double a, Vector1D 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
-
Vector1D
public Vector1D(double a1, Vector1D u1, double a2, Vector1D 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
-
Vector1D
public Vector1D(double a1, Vector1D u1, double a2, Vector1D u2, double a3, Vector1D 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
-
Vector1D
public Vector1D(double a1, Vector1D u1, double a2, Vector1D u2, double a3, Vector1D u3, double a4, Vector1D 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:
Vector1D(double)
-
getSpace
public Space getSpace()
Get the space to which the point belongs.- Specified by:
getSpace
in interfacePoint<Euclidean1D>
- Returns:
- containing space
-
getZero
public Vector1D getZero()
Get the null vector of the vectorial space or origin point of the affine space.- Specified by:
getZero
in interfaceVector<Euclidean1D,Vector1D>
- 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<Euclidean1D,Vector1D>
- Returns:
- L1 norm for the vector
-
getNorm
public double getNorm()
Get the L2 norm for the vector.- Specified by:
getNorm
in interfaceVector<Euclidean1D,Vector1D>
- Returns:
- Euclidean norm for the vector
-
getNormSq
public double getNormSq()
Get the square of the norm for the vector.- Specified by:
getNormSq
in interfaceVector<Euclidean1D,Vector1D>
- 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<Euclidean1D,Vector1D>
- Returns:
- L∞ norm for the vector
-
add
public Vector1D add(Vector<Euclidean1D,Vector1D> v)
Add a vector to the instance.- Specified by:
add
in interfaceVector<Euclidean1D,Vector1D>
- Parameters:
v
- vector to add- Returns:
- a new vector
-
add
public Vector1D add(double factor, Vector<Euclidean1D,Vector1D> v)
Add a scaled vector to the instance.- Specified by:
add
in interfaceVector<Euclidean1D,Vector1D>
- Parameters:
factor
- scale factor to apply to v before adding itv
- vector to add- Returns:
- a new vector
-
subtract
public Vector1D subtract(Vector<Euclidean1D,Vector1D> p)
Subtract a vector from the instance.- Specified by:
subtract
in interfaceVector<Euclidean1D,Vector1D>
- Parameters:
p
- vector to subtract- Returns:
- a new vector
-
subtract
public Vector1D subtract(double factor, Vector<Euclidean1D,Vector1D> v)
Subtract a scaled vector from the instance.- Specified by:
subtract
in interfaceVector<Euclidean1D,Vector1D>
- Parameters:
factor
- scale factor to apply to v before subtracting itv
- vector to subtract- Returns:
- a new vector
-
negate
public Vector1D negate()
Get the opposite of the instance.- Specified by:
negate
in interfaceVector<Euclidean1D,Vector1D>
- Returns:
- a new vector which is opposite to the instance
-
scalarMultiply
public Vector1D scalarMultiply(double a)
Multiply the instance by a scalar.- Specified by:
scalarMultiply
in interfaceVector<Euclidean1D,Vector1D>
- 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<Euclidean1D>
- 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<Euclidean1D,Vector1D>
- Returns:
- true if any coordinate of this vector is infinite and none are NaN; false otherwise
-
distance1
public double distance1(Vector<Euclidean1D,Vector1D> p)
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<Euclidean1D,Vector1D>
- Parameters:
p
- second vector- Returns:
- the distance between the instance and p according to the L1 norm
-
distance
public double distance(Point<Euclidean1D> p)
Compute the distance between the instance and another point.- Specified by:
distance
in interfacePoint<Euclidean1D>
- Parameters:
p
- second point- Returns:
- the distance between the instance and p
-
distanceInf
public double distanceInf(Vector<Euclidean1D,Vector1D> p)
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<Euclidean1D,Vector1D>
- Parameters:
p
- second vector- Returns:
- the distance between the instance and p according to the L∞ norm
-
distanceSq
public double distanceSq(Vector<Euclidean1D,Vector1D> p)
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<Euclidean1D,Vector1D>
- Parameters:
p
- second vector- Returns:
- the square of the distance between the instance and p
-
dotProduct
public double dotProduct(Vector<Euclidean1D,Vector1D> v)
Compute the dot-product of the instance and another vector.- Specified by:
dotProduct
in interfaceVector<Euclidean1D,Vector1D>
- Parameters:
v
- second vector- Returns:
- the dot product this.v
-
distance
public static double distance(Vector1D p1, Vector1D p2)
Compute the distance between two vectors according to the L2 norm.Calling this method is equivalent to calling:
p1.subtract(p2).getNorm()
except that no intermediate vector is built- Parameters:
p1
- first vectorp2
- second vector- Returns:
- the distance between p1 and p2 according to the L2 norm
-
distanceInf
public static double distanceInf(Vector1D p1, Vector1D p2)
Compute the distance between two vectors according to the L∞ norm.Calling this method is equivalent to calling:
p1.subtract(p2).getNormInf()
except that no intermediate vector is built- Parameters:
p1
- first vectorp2
- second vector- Returns:
- the distance between p1 and p2 according to the L∞ norm
-
distanceSq
public static double distanceSq(Vector1D p1, Vector1D p2)
Compute the square of the distance between two vectors.Calling this method is equivalent to calling:
p1.subtract(p2).getNormSq()
except that no intermediate vector is built- Parameters:
p1
- first vectorp2
- second vector- Returns:
- the square of the distance between p1 and p2
-
equals
public boolean equals(Object other)
Test for the equality of two 1D vectors.If all coordinates of two 1D vectors are exactly the same, and none are
Double.NaN
, the two 1D 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 1D vector are equal toDouble.NaN
, the 1D vector is equal toNaN
.
-
equalsIeee754
public boolean equalsIeee754(Object other)
Test for the equality of two 1D vectors.If all coordinates of two 1D vectors are exactly the same, and none are
NaN
, the two 1D 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 thatVector1D.NaN
.equals(Vector1D.NaN
) returnsfalse
despite the instance is checked against itself.- Parameters:
other
- Object to test for equality to this- Returns:
- true if two 1D vector objects are equal, false if object is null, not an instance of Vector1D, or not equal to this Vector1D instance
- Since:
- 2.1
-
hashCode
public int hashCode()
Get a hashCode for the 1D vector.All NaN values have the same hash code.
-
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<Euclidean1D,Vector1D>
- Parameters:
format
- the custom format for components- Returns:
- a string representation of this vector
-
-