math.geom2d
Class Vector2D

Package class diagram package Vector2D
java.lang.Object
  extended by math.geom2d.Vector2D
All Implemented Interfaces:
Serializable, Cloneable

public class Vector2D
extends Object
implements Cloneable, Serializable

A vector in the 2D plane. Provides methods to compute cross product and dot product, addition and subtraction of vectors.

See Also:
Serialized Form

Field Summary
protected  double x
           
protected  double y
           
 
Constructor Summary
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
 Vector2D clone()
           
static Vector2D create(double x, double y)
          Static factory for creating a new point in cartesian coordinates.
static Vector2D create(Point2D point)
          Static factory for creating a new vector from the coordinate of a point.
static Vector2D createPolar(double rho, double theta)
          Creates a new vector by specifying the distance to the origin, and the angle with the horizontal.
 double cross(Vector2D v)
          Get the cross product with point p.
static double cross(Vector2D v1, Vector2D v2)
          Get the cross product of the two vectors, defined by :
 double dot(Vector2D v)
          Get the dot product with point p.
static double dot(Vector2D v1, Vector2D v2)
          Get the dot product of the two vectors, defined by :
 boolean equals(Object obj)
          Test whether this object is the same as another vector.
 double getAngle()
          Returns the angle with the horizontal axis, in radians.
 double getNorm()
          Computes the norm of the vector
 Vector2D getNormalizedVector()
          Returns the vector with same direction as this one, but with norm equal to 1.
 Vector2D getOpposite()
          Returns the opposite vector v2 of this, such that the sum of this and v2 equals the null vector.
 double getX()
           
 double getY()
           
 boolean isColinear(Vector2D v)
          test if the two vectors are colinear
static boolean isColinear(Vector2D v1, Vector2D v2)
          Tests if the two vectors are colinear
 boolean isOrthogonal(Vector2D v)
          test if the two vectors are orthogonal
static boolean isOrthogonal(Vector2D v1, Vector2D v2)
          Tests if the two vectors are orthogonal
 Vector2D minus(Vector2D v)
          Returns the subtraction of current vector with vector given as parameter.
 void normalize()
          Normalizes the vector, such that its norms becomes 1.
 Vector2D plus(Vector2D v)
          Returns the sum of current vector with vector given as parameter.
 void setAsPolar(double rho, double theta)
          Deprecated. vectors will become imutable in a future release
 void setVector(double x, double y)
          Deprecated. vectors will become imutable in a future release
 void setX(double x)
          Deprecated. vectors will become imutable in a future release
 void setY(double y)
          Deprecated. vectors will become imutable in a future release
 Vector2D times(double k)
          Multiplies the vector by a scalar amount.
 String toString()
           
 Vector2D transform(AffineTransform2D trans)
          Transform the vector, by using only the first 4 parameters of the transform.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

x

protected double x

y

protected double y
Constructor Detail

Vector2D

public Vector2D()
Constructs a new Vectors initialized with x=1 and y=0.


Vector2D

public Vector2D(Point2D point)
Constructs a new vector between the origin and the given point.


Vector2D

public Vector2D(Point2D point1,
                Point2D point2)
Constructs a new vector between two points


Vector2D

public Vector2D(double x,
                double y)
Constructs a new vector with the given coordinates. Consider creating a new Vector using static factory.

Method Detail

create

public static Vector2D create(Point2D point)
Static factory for creating a new vector from the coordinate of a point.

Since:
0.8.1

create

public static Vector2D create(double x,
                              double y)
Static factory for creating a new point in cartesian coordinates.

Since:
0.8.1

createPolar

public static final 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 final double dot(Vector2D v1,
                               Vector2D v2)
Get the dot product of the two vectors, defined by :

dx1*dy2 + dx2*dy1

Dot 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 final double cross(Vector2D v1,
                                 Vector2D v2)
Get the cross product of the two vectors, defined by :

dx1*dy2 - dx2*dy1

cross 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 final boolean isColinear(Vector2D v1,
                                       Vector2D v2)
Tests if the two vectors are colinear

Returns:
true if the vectors are colinear

isOrthogonal

public static final boolean isOrthogonal(Vector2D v1,
                                         Vector2D v2)
Tests if the two vectors are orthogonal

Returns:
true if the vectors are orthogonal

getX

public double getX()

getY

public double getY()

setX

@Deprecated
public void setX(double x)
Deprecated. vectors will become imutable in a future release


setY

@Deprecated
public void setY(double y)
Deprecated. vectors will become imutable in a future release


setVector

@Deprecated
public void setVector(double x,
                                 double y)
Deprecated. vectors will become imutable in a future release


setAsPolar

@Deprecated
public void setAsPolar(double rho,
                                  double theta)
Deprecated. vectors will become imutable in a future release

Set location specified as polar coordinate : distance from origin + angle with horizontal.


getOpposite

public Vector2D getOpposite()
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.

getNorm

public double getNorm()
Computes the norm of the vector

Returns:
the euclidean norm of the vector

getAngle

public double getAngle()
Returns the angle with the horizontal axis, in radians.

Returns:
the horizontal angle of the vector

normalize

public void normalize()
Normalizes the vector, such that its norms becomes 1.


getNormalizedVector

public Vector2D getNormalizedVector()
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 point p. 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 point p. 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

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.

equals

public boolean equals(Object obj)
Test whether this object is the same as another vector.

Overrides:
equals in class Object

toString

public String toString()
Overrides:
toString in class Object

clone

public Vector2D clone()
Overrides:
clone in class Object


Copyright © 2013 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.