Package inra.ijpb.geometry
Class Vector2D
java.lang.Object
inra.ijpb.geometry.Vector2D
public class Vector2D
extends java.lang.Object
Represents a couple of coordinates in linear space, and provides some
computing methods.
The class is immutable.
- Author:
- dlegland
-
Constructor Summary
-
Method Summary
Modifier and Type Method 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 vectorVector2D
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.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
Vector2D
public Vector2D()Empty constructor, with all coordinates initialized to zero. -
Vector2D
public Vector2D(double x, double y)Initialization constructor.- Parameters:
x
- the x coordinatey
- the y coordinate
-
-
Method Details
-
crossProduct
Computes the cross product of the two vectors. Cross product is zero for colinear vectors.- Parameters:
v1
- the first vectorv2
- the second vector- Returns:
- the cross product of the two vectors
-
dotProduct
Computes the dot product of two vectors, defined by: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.
- Parameters:
v1
- the first vectorv2
- the second vector- Returns:
- the dot product of the two vectors
-
angle
Computes the angle between two vectors. Result is given in radians.- Parameters:
v1
- the first vectorv2
- the second vector- Returns:
- the angle between the two vectors, in radians
-
getX
public double getX()Returns the x coordinate of the vector.- Returns:
- the x coordinate of the vector
-
getY
public double getY()Returns the y coordinate of the vector.- Returns:
- the y coordinate of the vector
-
plus
Returns the result of the addition of this vector with another vector.- Parameters:
v
- the vector to add- Returns:
- the results of the vector addition
-
minus
Returns the result of the subtraction of this vector with another vector.- Parameters:
v
- the vector to subtract- Returns:
- the results of the vector subtraction
-
times
Returns the result of the multiplication of this vector with a scalar value.- Parameters:
k
- the scalar coefficient- Returns:
- the results of scalar multiplication
-
normalize
Returns a normalized vector with same direction as this vector- Returns:
- the normalized vector with same direction as this.
-
getNorm
public double getNorm()Computes the norm of the vector, given as the square root of the sum of squared coordinates.- Returns:
- the norm of the vector
-
almostEquals
Checks if this vector is close to the given vector, by checking each coordinate using the given threshold.- Parameters:
v
- the vector to compare toeps
- the absolute tolerance for comparing coordinates- Returns:
- true if vector have same coordinates with respect to tolerance
-