Class Vector2D
- java.lang.Object
-
- math.geom2d.Vector2D
-
- All Implemented Interfaces:
- java.lang.Cloneable, GeometricObject2D
public class Vector2D extends java.lang.Object implements GeometricObject2D, java.lang.Cloneable
A vector in the 2D plane. Provides methods to compute cross product and dot product, addition and subtraction of vectors.
-
-
Constructor Summary
Constructors Constructor and Description Vector2D()Constructs a new Vectors initialized with x=1 and y=0.Vector2D(double x, double y)Constructs a new vector with the given coordinates.Vector2D(Point2D point)Constructs a new vector between the origin and the given point.Vector2D(Point2D point1, Point2D point2)Constructs a new vector between two points
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method and Description booleanalmostEquals(GeometricObject2D obj, double eps)Test whether this object is the same as another vector, with respect to a given threshold.doubleangle()Returns the angle with the horizontal axis, in radians.Vector2Dclone()Deprecated.not necessary to clone immutable objectstatic Vector2Dcreate(double x, double y)Deprecated.since 0.11.1static Vector2Dcreate(Point2D point)Deprecated.since 0.11.1static Vector2DcreatePolar(double rho, double theta)Creates a new vector by specifying the distance to the origin, and the angle with the horizontal.doublecross(Vector2D v)Get the cross product with pointp.static doublecross(Vector2D v1, Vector2D v2)Get the cross product of the two vectors, defined by :doubledot(Vector2D v)Get the dot product with pointp.static doubledot(Vector2D v1, Vector2D v2)Get the dot product of the two vectors, defined by :booleanequals(java.lang.Object obj)Test whether this object is exactly the same as another vector.doublegetX()Returns the x coordinates of this vector.doublegetY()Returns the y coordinates of this vector.booleanisColinear(Vector2D v)test if the two vectors are colinearstatic booleanisColinear(Vector2D v1, Vector2D v2)Tests if the two vectors are colinearbooleanisOrthogonal(Vector2D v)test if the two vectors are orthogonalstatic booleanisOrthogonal(Vector2D v1, Vector2D v2)Tests if the two vectors are orthogonalVector2Dminus(Vector2D v)Returns the subtraction of current vector with vector given as parameter.doublenorm()Computes the norm of the vectorVector2Dnormalize()Returns the vector with same direction as this one, but with norm equal to 1.Vector2Dopposite()Returns the opposite vector v2 of this, such that the sum of this and v2 equals the null vector.Vector2Dplus(Vector2D v)Returns the sum of current vector with vector given as parameter.Vector2Drotate(double theta)Rotates the vector by the given angle.Vector2Dtimes(double k)Multiplies the vector by a scalar amount.java.lang.StringtoString()Display the coordinates of the vector.Vector2Dtransform(AffineTransform2D trans)Transform the vector, by using only the first 4 parameters of the transform.doublex()Returns the x coordinates of this vector.doubley()Returns the y coordinates of this vector.
-
-
-
Constructor Detail
-
Vector2D
public Vector2D()
Constructs a new Vectors initialized with x=1 and y=0.
-
Vector2D
public Vector2D(double x, double y)Constructs a new vector with the given coordinates. Consider creating a new Vector using static factory.
-
Vector2D
public Vector2D(Point2D point)
Constructs a new vector between the origin and the given point.
-
-
Method Detail
-
create
@Deprecated public static Vector2D create(double x, double y)
Deprecated. since 0.11.1Static factory for creating a new vector in Cartesian coordinates.
-
create
@Deprecated public static Vector2D create(Point2D point)
Deprecated. since 0.11.1Static factory for creating a new vector from the coordinate of a point.
-
createPolar
public static Vector2D createPolar(double rho, double theta)
Creates a new vector by specifying the distance to the origin, and the angle with the horizontal.
-
dot
public static double dot(Vector2D v1, Vector2D v2)
Get the dot product of the two vectors, defined by :dx1*dy2 + dx2*dy1Dot product is zero if the vectors defined by the 2 vectors are orthogonal. It is positive if vectors are in the same direction, and negative if they are in opposite direction.
-
cross
public static double cross(Vector2D v1, Vector2D v2)
Get the cross product of the two vectors, defined by :dx1*dy2 - dx2*dy1Cross product is zero for colinear vectors. It is positive if angle between vector 1 and vector 2 is comprised between 0 and PI, and negative otherwise.
-
isColinear
public static boolean isColinear(Vector2D v1, Vector2D v2)
Tests if the two vectors are colinear- Returns:
- true if the vectors are colinear
-
isOrthogonal
public static boolean isOrthogonal(Vector2D v1, Vector2D v2)
Tests if the two vectors are orthogonal- Returns:
- true if the vectors are orthogonal
-
x
public double x()
Returns the x coordinates of this vector.
-
getX
public double getX()
Returns the x coordinates of this vector.
-
y
public double y()
Returns the y coordinates of this vector.
-
getY
public double getY()
Returns the y coordinates of this vector.
-
opposite
public Vector2D opposite()
Returns the opposite vector v2 of this, such that the sum of this and v2 equals the null vector.- Returns:
- the vector opposite to
this.
-
norm
public double norm()
Computes the norm of the vector- Returns:
- the euclidean norm of the vector
-
angle
public double angle()
Returns the angle with the horizontal axis, in radians.- Returns:
- the horizontal angle of the vector
-
normalize
public Vector2D normalize()
Returns the vector with same direction as this one, but with norm equal to 1.
-
isColinear
public boolean isColinear(Vector2D v)
test if the two vectors are colinear- Returns:
- true if the vectors are colinear
-
isOrthogonal
public boolean isOrthogonal(Vector2D v)
test if the two vectors are orthogonal- Returns:
- true if the vectors are orthogonal
-
dot
public double dot(Vector2D v)
Get the dot product with pointp. Dot product id defined by:x1*y2 + x2*y1. Dot product is zero if the vectors defined by the 2 points are orthogonal. It is positive if vectors are in the same direction, and negative if they are in opposite direction.
-
cross
public double cross(Vector2D v)
Get the cross product with pointp. Cross product is defined by :x1*y2 - x2*y1. Cross product is zero for colinear vector. It is positive if angle between vector 1 and vector 2 is comprised between 0 and PI, and negative otherwise.
-
plus
public Vector2D plus(Vector2D v)
Returns the sum of current vector with vector given as parameter. Inner fields are not modified.
-
minus
public Vector2D minus(Vector2D v)
Returns the subtraction of current vector with vector given as parameter. Inner fields are not modified.
-
times
public Vector2D times(double k)
Multiplies the vector by a scalar amount. Inner fields are not- Parameters:
k- the scale factor- Returns:
- the scaled vector
- Since:
- 0.7.0
-
rotate
public Vector2D rotate(double theta)
Rotates the vector by the given angle.- Parameters:
theta- the angle of rotation, in radians counter-clockwise
-
transform
public Vector2D transform(AffineTransform2D trans)
Transform the vector, by using only the first 4 parameters of the transform. Translation of a vector returns the same vector.- Parameters:
trans- an affine transform- Returns:
- the transformed vector.
-
almostEquals
public boolean almostEquals(GeometricObject2D obj, double eps)
Test whether this object is the same as another vector, with respect to a given threshold.- Specified by:
almostEqualsin interfaceGeometricObject2D- Parameters:
obj- the object to compareeps- a threshold value, for example the minimal coordinate difference- Returns:
- true if both object have the same value up to the threshold
-
equals
public boolean equals(java.lang.Object obj)
Test whether this object is exactly the same as another vector.- Overrides:
equalsin classjava.lang.Object- See Also:
almostEquals(math.geom2d.GeometricObject2D, double)
-
toString
public java.lang.String toString()
Display the coordinates of the vector. Typical output is:x=3 y=4.- Overrides:
toStringin classjava.lang.Object
-
clone
@Deprecated public Vector2D clone()
Deprecated. not necessary to clone immutable object- Overrides:
clonein classjava.lang.Object
-
-
DMelt 3.0 © DataMelt by jWork.ORG