public class Vector2D extends Object implements Vector<Euclidean2D>
Instances of this class are guaranteed to be immutable.
Modifier and Type  Field and Description 

static Vector2D 
MINUS_I
Opposite of the first canonical vector (coordinates: 1, 0).

static Vector2D 
MINUS_J
Opposite of the second canonical vector (coordinates: 0, 1).

static Vector2D 
NaN
A vector with all coordinates set to NaN.

static Vector2D 
NEGATIVE_INFINITY
A vector with all coordinates set to negative infinity.

static Vector2D 
PLUS_I
First canonical vector (coordinates: 1, 0).

static Vector2D 
PLUS_J
Second canonical vector (coordinates: 0, 1).

static Vector2D 
POSITIVE_INFINITY
A vector with all coordinates set to positive infinity.

static Vector2D 
ZERO
Origin (coordinates: 0, 0).

Constructor and Description 

Vector2D(double[] v)
Simple constructor.

Vector2D(double x,
double y)
Simple constructor.

Vector2D(double a,
Vector2D u)
Multiplicative constructor
Build a vector from another one and a scale factor.

Vector2D(double a1,
Vector2D u1,
double a2,
Vector2D u2)
Linear constructor
Build a vector from two other ones and corresponding scale factors.

Vector2D(double a1,
Vector2D u1,
double a2,
Vector2D u2,
double a3,
Vector2D u3)
Linear constructor
Build a vector from three other ones and corresponding scale factors.

Vector2D(double a1,
Vector2D u1,
double a2,
Vector2D u2,
double a3,
Vector2D u3,
double a4,
Vector2D u4)
Linear constructor
Build a vector from four other ones and corresponding scale factors.

Modifier and Type  Method and Description 

Vector2D 
add(double factor,
Vector<Euclidean2D> v)
Add a scaled vector to the instance.

Vector2D 
add(Vector<Euclidean2D> v)
Add a vector to the instance.

static double 
angle(Vector2D v1,
Vector2D v2)
Compute the angular separation between two vectors.

double 
crossProduct(Vector2D p1,
Vector2D p2)
Compute the crossproduct of the instance and the given points.

double 
distance(Point<Euclidean2D> p)
Compute the distance between the instance and another point.

static double 
distance(Vector2D p1,
Vector2D p2)
Compute the distance between two vectors according to the L_{2} norm.

double 
distance1(Vector<Euclidean2D> p)
Compute the distance between the instance and another vector according to the L_{1} norm.

static double 
distance1(Vector2D p1,
Vector2D p2)
Compute the distance between two vectors according to the L_{1} norm.

double 
distanceInf(Vector<Euclidean2D> p)
Compute the distance between the instance and another vector according to the L_{∞} norm.

static double 
distanceInf(Vector2D p1,
Vector2D p2)
Compute the distance between two vectors according to the L_{∞} norm.

double 
distanceSq(Vector<Euclidean2D> p)
Compute the square of the distance between the instance and another vector.

static double 
distanceSq(Vector2D p1,
Vector2D p2)
Compute the square of the distance between two vectors.

double 
dotProduct(Vector<Euclidean2D> v)
Compute the dotproduct of the instance and another vector.

boolean 
equals(Object other)
Test for the equality of two 2D vectors.

boolean 
equalsIeee754(Object other)
Test for the equality of two 2D vectors.

double 
getNorm()
Get the L_{2} norm for the vector.

double 
getNorm1()
Get the L_{1} 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.

Vector2D 
getZero()
Get the null vector of the vectorial space or origin point of the affine space.

int 
hashCode()
Get a hashCode for the 2D vector.

boolean 
isInfinite()
Returns true if any coordinate of this vector is infinite and none are NaN;
false otherwise

boolean 
isNaN()
Returns true if any coordinate of this point is NaN; false otherwise

Vector2D 
negate()
Get the opposite of the instance.

Vector2D 
normalize()
Get a normalized vector aligned with the instance.

static double 
orientation(Vector2D p,
Vector2D q,
Vector2D r)
Compute the orientation of a triplet of points.

Vector2D 
scalarMultiply(double a)
Multiply the instance by a scalar.

Vector2D 
subtract(double factor,
Vector<Euclidean2D> v)
Subtract a scaled vector from the instance.

Vector2D 
subtract(Vector<Euclidean2D> p)
Subtract a vector from the instance.

double[] 
toArray()
Get the vector coordinates as a dimension 2 array.

String 
toString()
Get a string representation of this vector.

String 
toString(NumberFormat format)
Get a string representation of this vector.

public static final Vector2D ZERO
public static final Vector2D PLUS_I
public static final Vector2D MINUS_I
public static final Vector2D PLUS_J
public static final Vector2D MINUS_J
public static final Vector2D NaN
public static final Vector2D POSITIVE_INFINITY
public static final Vector2D NEGATIVE_INFINITY
public Vector2D(double x, double y)
public Vector2D(double[] v) throws MathIllegalArgumentException
v
 coordinates arrayMathIllegalArgumentException
 if array does not have 2 elementstoArray()
public Vector2D(double a, Vector2D u)
a
 scale factoru
 base (unscaled) vectorpublic Vector2D(double a1, Vector2D u1, double a2, Vector2D u2)
a1
 first scale factoru1
 first base (unscaled) vectora2
 second scale factoru2
 second base (unscaled) vectorpublic Vector2D(double a1, Vector2D u1, double a2, Vector2D u2, double a3, Vector2D u3)
a1
 first scale factoru1
 first base (unscaled) vectora2
 second scale factoru2
 second base (unscaled) vectora3
 third scale factoru3
 third base (unscaled) vectorpublic Vector2D(double a1, Vector2D u1, double a2, Vector2D u2, double a3, Vector2D u3, double a4, Vector2D u4)
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) vectorpublic double getX()
Vector2D(double, double)
public double getY()
Vector2D(double, double)
public double[] toArray()
Vector2D(double[])
public Space getSpace()
getSpace
in interface Point<Euclidean2D>
public Vector2D getZero()
getZero
in interface Vector<Euclidean2D>
public double getNorm1()
getNorm1
in interface Vector<Euclidean2D>
public double getNorm()
getNorm
in interface Vector<Euclidean2D>
public double getNormSq()
getNormSq
in interface Vector<Euclidean2D>
public double getNormInf()
getNormInf
in interface Vector<Euclidean2D>
public Vector2D add(Vector<Euclidean2D> v)
add
in interface Vector<Euclidean2D>
v
 vector to addpublic Vector2D add(double factor, Vector<Euclidean2D> v)
add
in interface Vector<Euclidean2D>
factor
 scale factor to apply to v before adding itv
 vector to addpublic Vector2D subtract(Vector<Euclidean2D> p)
subtract
in interface Vector<Euclidean2D>
p
 vector to subtractpublic Vector2D subtract(double factor, Vector<Euclidean2D> v)
subtract
in interface Vector<Euclidean2D>
factor
 scale factor to apply to v before subtracting itv
 vector to subtractpublic Vector2D normalize() throws MathRuntimeException
normalize
in interface Vector<Euclidean2D>
MathRuntimeException
 if the norm is zeropublic static double angle(Vector2D v1, Vector2D v2) throws MathRuntimeException
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.
v1
 first vectorv2
 second vectorMathRuntimeException
 if either vector has a null normpublic Vector2D negate()
negate
in interface Vector<Euclidean2D>
public Vector2D scalarMultiply(double a)
scalarMultiply
in interface Vector<Euclidean2D>
a
 scalarpublic boolean isNaN()
isNaN
in interface Point<Euclidean2D>
public boolean isInfinite()
isInfinite
in interface Vector<Euclidean2D>
public double distance1(Vector<Euclidean2D> p)
Calling this method is equivalent to calling:
q.subtract(p).getNorm1()
except that no intermediate
vector is built
distance1
in interface Vector<Euclidean2D>
p
 second vectorpublic double distance(Point<Euclidean2D> p)
distance
in interface Point<Euclidean2D>
p
 second pointpublic double distanceInf(Vector<Euclidean2D> p)
Calling this method is equivalent to calling:
q.subtract(p).getNormInf()
except that no intermediate
vector is built
distanceInf
in interface Vector<Euclidean2D>
p
 second vectorpublic double distanceSq(Vector<Euclidean2D> p)
Calling this method is equivalent to calling:
q.subtract(p).getNormSq()
except that no intermediate
vector is built
distanceSq
in interface Vector<Euclidean2D>
p
 second vectorpublic double dotProduct(Vector<Euclidean2D> v)
dotProduct
in interface Vector<Euclidean2D>
v
 second vectorpublic double crossProduct(Vector2D p1, Vector2D p2)
The cross product can be used to determine the location of a point with regard to the line formed by (p1, p2) and is calculated as: \[ P = (x_2  x_1)(y_3  y_1)  (y_2  y_1)(x_3  x_1) \] with \(p3 = (x_3, y_3)\) being this instance.
If the result is 0, the points are collinear, i.e. lie on a single straight line L; if it is positive, this point lies to the left, otherwise to the right of the line formed by (p1, p2).
p1
 first point of the linep2
 second point of the linepublic static double distance1(Vector2D p1, Vector2D p2)
Calling this method is equivalent to calling:
p1.subtract(p2).getNorm1()
except that no intermediate
vector is built
p1
 first vectorp2
 second vectorpublic static double distance(Vector2D p1, Vector2D p2)
Calling this method is equivalent to calling:
p1.subtract(p2).getNorm()
except that no intermediate
vector is built
p1
 first vectorp2
 second vectorpublic static double distanceInf(Vector2D p1, Vector2D p2)
Calling this method is equivalent to calling:
p1.subtract(p2).getNormInf()
except that no intermediate
vector is built
p1
 first vectorp2
 second vectorpublic static double distanceSq(Vector2D p1, Vector2D p2)
Calling this method is equivalent to calling:
p1.subtract(p2).getNormSq()
except that no intermediate
vector is built
p1
 first vectorp2
 second vectorpublic static double orientation(Vector2D p, Vector2D q, Vector2D r)
p
 first vector of the tripletq
 second vector of the tripletr
 third vector of the tripletpublic boolean equals(Object other)
If all coordinates of two 2D vectors are exactly the same, and none are
Double.NaN
, the two 2D 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
2D vector are equal to Double.NaN
, the 2D vector is equal to
NaN
.
public boolean equalsIeee754(Object other)
If all coordinates of two 2D vectors are exactly the same, and none are
NaN
, the two 2D 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 that Vector2D.NaN
.equals(Vector2D.NaN
)
returns false
despite the instance is checked against itself.
other
 Object to test for equality to thispublic int hashCode()
All NaN values have the same hash code.
public String toString()
public String toString(NumberFormat format)
toString
in interface Vector<Euclidean2D>
format
 the custom format for componentsCopyright © 20162022 CS GROUP. All rights reserved.