public class Vector2D
extends java.lang.Object
implements java.lang.Cloneable
| Modifier and Type | Field and Description |
|---|---|
static double |
ASSUME_ANGLE_ZERO
0.017: Constant used for angles equality.
|
static double |
ASSUME_ZERO
1.0E-4: Constant used for coordinates equality.
|
double |
x
The x coordinate of the Vector.
|
double |
y
The y coordinate of the Vector.
|
| Constructor and Description |
|---|
Vector2D()
Create a (0, 0) 2D Vector.
|
Vector2D(double x,
double y)
Create a 2D Vector, knowing its x and y coordinates.
|
Vector2D(java.awt.geom.Point2D p0,
java.awt.geom.Point2D p1)
Create a 2D Vector, knowing its two associated points.
|
Vector2D(Vector2D v)
Create a 2D Vector, identical to another Vector2D.
|
| Modifier and Type | Method and Description |
|---|---|
Vector2D |
add(Vector2D v)
Adds another Vector to this one.
|
java.lang.Object |
clone() |
double |
getAngle()
Return the angle of this vector with the X axis.
|
java.awt.geom.Point2D |
getIntersection(java.awt.geom.Point2D p0,
Vector2D v1,
java.awt.geom.Point2D p1)
Find the intersection between two lines.
|
Vector2D |
getInverse()
Return the inverse of this Vector, which is this vector rotated by PI.
|
double |
getNorm()
Return the euclidian norm of this Vector.
|
Vector2D |
getNormal()
Return the normal of this vector.
|
java.awt.geom.Point2D |
getNormalProjection(java.awt.geom.Point2D o,
java.awt.geom.Point2D p)
Return the orthogonal projection of this point on the line defined by the Vector2D.
|
double |
getScalarProduct(Vector2D v)
Return the scalar product of this vector with another vector.
|
double |
getX()
Return the X coordinate of this Vector.
|
double |
getY()
Return the Y coordinate of this Vector.
|
boolean |
isColinear(java.awt.geom.Point2D p0,
Vector2D v1,
java.awt.geom.Point2D p1)
Determines if two lines are colinear.
|
boolean |
isColinear(java.awt.geom.Point2D p0,
Vector2D v1,
java.awt.geom.Point2D p1,
double delta,
double deltaAngle)
Determines if two lines are colinear.
|
Vector2D |
minus(Vector2D v)
Substracts another vector from this one.
|
Vector2D |
normalize()
Normalize this vector.
|
Vector2D |
rotate(double alpha)
Rotates the Vector.
|
Vector2D |
scaleTo(double d)
Multiply the coordinates of this Vector by a scalar value.
|
void |
setX(double x)
Set the X coordinate of this Vector.
|
void |
setY(double y)
Set the Y coordinate of this Vector.
|
Vector2D |
transform(java.awt.geom.AffineTransform tr)
Return the Vector2D after an AffineTransform.
|
static java.awt.geom.Point2D |
transform(java.awt.geom.Point2D p,
java.awt.geom.AffineTransform tr)
Return a Point2D transformed after an affine transformation.
|
java.awt.geom.Point2D |
translate(java.awt.geom.Point2D p)
Translate a Point by this vector.
|
public double x
public double y
public static final double ASSUME_ZERO
public static final double ASSUME_ANGLE_ZERO
public Vector2D()
public Vector2D(double x,
double y)
x - the x coordinatey - the y coordinatepublic Vector2D(java.awt.geom.Point2D p0,
java.awt.geom.Point2D p1)
p0 - the first pointp1 - the second pointpublic Vector2D(Vector2D v)
v - the vector to clonepublic double getX()
public double getY()
public void setX(double x)
x - the X coordinatepublic void setY(double y)
y - the Y coordinatepublic double getScalarProduct(Vector2D v)
v - the other Vectorpublic Vector2D minus(Vector2D v)
v - the other Vectorpublic Vector2D rotate(double alpha)
alpha - the angle in Radianspublic Vector2D add(Vector2D v)
v - the other Vectorpublic double getNorm()
public double getAngle()
public Vector2D normalize()
public Vector2D scaleTo(double d)
d - the factorpublic java.awt.geom.Point2D translate(java.awt.geom.Point2D p)
p - the Pointpublic Vector2D getNormal()
public Vector2D getInverse()
public java.awt.geom.Point2D getNormalProjection(java.awt.geom.Point2D o,
java.awt.geom.Point2D p)
o - the origin of the linep - the point to projectpublic boolean isColinear(java.awt.geom.Point2D p0,
Vector2D v1,
java.awt.geom.Point2D p1,
double delta,
double deltaAngle)
The two lines are considered colinear if :
p0 - origin of the first line (defined by this vector)v1 - vector defining the second linep1 - origin of the second linedelta - the delta concerning the distance of p1 to the first linedeltaAngle - the delta concerning the difference between the two anglespublic boolean isColinear(java.awt.geom.Point2D p0,
Vector2D v1,
java.awt.geom.Point2D p1)
Same as {link #isColinear(Point2D, Vector2D, Point2D, double, double)} where :
ASSUME_ZEROASSUME_ANGLE_ZEROp0 - origin of the first line (defined by this vector)v1 - vector defining the second linep1 - origin of the second linepublic java.awt.geom.Point2D getIntersection(java.awt.geom.Point2D p0,
Vector2D v1,
java.awt.geom.Point2D p1)
It is considered that there is no intersection if either :
ASSUME_ZERO
valueASSUME_ZERO
value, but they differ from less than this valueRemark: The intersection is computed by resolving the following equations:
where :
p0 - origin of the first line (defined by this vector)v1 - vector defining the second linep1 - origin of the second linepublic java.lang.Object clone()
clone in class java.lang.Objectpublic Vector2D transform(java.awt.geom.AffineTransform tr)
tr - the AffineTransformpublic static java.awt.geom.Point2D transform(java.awt.geom.Point2D p,
java.awt.geom.AffineTransform tr)
p - the pointtr - the AffineTransformCopyright © 2021, 2022, 2025, 2026 Herve Girod. All Rights Reserved. Documentation and source under the BSD 3-Clause licence