public class Vector2D extends Object
Constructor and Description |
---|
Vector2D()
Empty constructor, with all coordinates initialized to zero.
|
Vector2D(double x,
double y)
Initialization constructor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
almostEquals(Vector2D v,
double eps)
Checks if this vector is close to the given vector, by checking each
coordinate using the given threshold.
|
static double |
angle(Vector2D v1,
Vector2D v2)
Computes the angle between two vectors.
|
static double |
crossProduct(Vector2D v1,
Vector2D v2)
Computes the cross product of the two vectors.
|
static double |
dotProduct(Vector2D v1,
Vector2D v2)
Computes the dot product of two vectors, defined by:
|
double |
getNorm()
Computes the norm of the vector, given as the square root of the sum
of squared coordinates.
|
double |
getX()
Returns the x coordinate of the vector.
|
double |
getY()
Returns the y coordinate of the vector.
|
Vector2D |
minus(Vector2D v)
Returns the result of the subtraction of this vector with another vector.
|
Vector2D |
normalize()
Returns a normalized vector with same direction as this vector
|
Vector2D |
plus(Vector2D v)
Returns the result of the addition of this vector with another vector.
|
Vector2D |
times(double k)
Returns the result of the multiplication of this vector with a scalar value.
|
public Vector2D()
public Vector2D(double x, double y)
x
- the x coordinatey
- the y coordinatepublic static final double crossProduct(Vector2D v1, Vector2D v2)
v1
- the first vectorv2
- the second vectorpublic static final double dotProduct(Vector2D v1, Vector2D v2)
x1 * x2 + y1 * y2
Dot product is zero if the vectors are orthogonal. It is positive if vectors are in the same direction, and negative if they are in opposite direction.
v1
- the first vectorv2
- the second vectorpublic static final double angle(Vector2D v1, Vector2D v2)
v1
- the first vectorv2
- the second vectorpublic double getX()
public double getY()
public Vector2D plus(Vector2D v)
v
- the vector to addpublic Vector2D minus(Vector2D v)
v
- the vector to subtractpublic Vector2D times(double k)
k
- the scalar coefficientpublic Vector2D normalize()
public double getNorm()
public boolean almostEquals(Vector2D v, double eps)
v
- the vector to compare toeps
- the absolute tolerance for comparing coordinatesCopyright © 2014–2023 INRA-IJPB Modeling and Digital Imaging lab. All rights reserved.