jdsl.extension.LEDA.Layout.Geometry
Class Vector2D

java.lang.Object
  |
  +--jdsl.extension.LEDA.Layout.Geometry.Vector2D

public class Vector2D
extends java.lang.Object
implements java.lang.Cloneable, Point

This class represents a two-dimensional vector, or, likewise, its endpoint. It has serveral methods for easy handling, e.g. arithmetical operations. It has a copy constructor and a clone method for easy copy actions.


Constructor Summary
Vector2D()
          Constructs a null vector.
Vector2D(double x, double y)
          Constructs a new vector with given components.
Vector2D(double r, double phi, Vector2D p)
          Constructs a new point by using polar coordinates (from a different origin).
Vector2D(Point p)
          Copy-Constructor.
Vector2D(Vector2D p)
          Copy-Constructor.
 
Method Summary
 Vector2D add(Vector2D q)
          Returns result vector.
 java.lang.Object clone()
          Creates a new Vector2D and initializes it with this.
 Vector2D difference(Vector2D q)
          Returns result vector of difference of two vectors.
 double distance(Vector2D q)
          Returns euklidean distance between this vector and q.
 boolean equals(java.lang.Object q)
          Compares q to this object.
 double length()
          Returns euklidean length.
 void moveRelX(double x)
           
 void moveRelY(double y)
           
 Vector2D reversal()
          Creates a new vector with reversed orientation.
 Vector2D reverse()
          Reverses direction and returns the vector.
 double scalar(Vector2D q)
          Returns scalar product of this vector and q.
 Vector2D scale(double s)
          Returns scaled vector.
 double sqrDistance(Vector2D q)
          Returns euklidean distance in square.
 Vector2D subtract(Vector2D q)
          Returns result vector.
 Vector2D sum(Vector2D q)
          Returns result vector of addition by two vectors.
 java.lang.String toString()
          Returns a String object representing this point.
 Vector2D translate(double dx, double dy)
          Returns translated vector.
 double x()
          Returns current X-coodinate.
 double xDistance(Vector2D q)
          Returns distance between this point and q (parallel to x) Note: If q is null then this method will return the same value as x()
 double y()
          Returns current Y-coodinate.
 double yDistance(Vector2D q)
          Returns distance between this point and q (parallel to y) Note: If q is null then this method will return the same value as y()
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Vector2D

public Vector2D()
Constructs a null vector.

Vector2D

public Vector2D(double x,
                double y)
Constructs a new vector with given components.
Parameters:
x - first component
y - second component

Vector2D

public Vector2D(double r,
                double phi,
                Vector2D p)
Constructs a new point by using polar coordinates (from a different origin).

Note:
null is a valid translation and is treated like (0, 0)
Parameters:
r - radius
phi - angle
p - translation to new origin

Vector2D

public Vector2D(Vector2D p)
Copy-Constructor. Constructs a new point by copying another point.

Note:
If p is null then default position will be used.
Parameters:
p - a Vector2D reference

Vector2D

public Vector2D(Point p)
Copy-Constructor. Constructs a new point by copying another point.

Note:
If p is null then default position will be used.
Parameters:
p - a point
Method Detail

x

public double x()
Returns current X-coodinate.
Specified by:
x in interface Point

y

public double y()
Returns current Y-coodinate.
Specified by:
y in interface Point

moveRelX

public void moveRelX(double x)
Specified by:
moveRelX in interface Point

moveRelY

public void moveRelY(double y)
Specified by:
moveRelY in interface Point

xDistance

public double xDistance(Vector2D q)
Returns distance between this point and q (parallel to x)

Note:
If q is null then this method will return the same value as x()
Parameters:
q - a Vector2D reference

yDistance

public double yDistance(Vector2D q)
Returns distance between this point and q (parallel to y)

Note:
If q is null then this method will return the same value as y()
Parameters:
q - a Vector2D reference

length

public double length()
Returns euklidean length.

distance

public double distance(Vector2D q)
Returns euklidean distance between this vector and q. This is the distance between the points represened by these vectors.

Note:
If q is null zero is returned.
Parameters:
q - a Vector2D reference

sqrDistance

public double sqrDistance(Vector2D q)
Returns euklidean distance in square.

Note:
If q is null zero is returned.
Parameters:
q - a Vector2D reference

scale

public Vector2D scale(double s)
Returns scaled vector. In details: both components are multiplied by s.
Parameters:
s - scale faktor (any double)
Returns:
a reference (to this) not a new instance.

translate

public Vector2D translate(double dx,
                          double dy)
Returns translated vector. In details: both components are relative move by offset d*
Parameters:
x - offset in x direction (positiv means to right)
y - offset in y direction (positiv means up)
Returns:
a reference (to this) not a new instance.

reverse

public Vector2D reverse()
Reverses direction and returns the vector.
Returns:
a reference the reversed instance (this)

reversal

public Vector2D reversal()
Creates a new vector with reversed orientation.
Returns:
reference to newly constructed reversal

add

public Vector2D add(Vector2D q)
Returns result vector. In details: we add q to this vector.

Note:
If q is null (0, 0) is assumed for q.
Parameters:
q - a vector reference
Returns:
a reference (to this) not a new instance.

sum

public Vector2D sum(Vector2D q)
Returns result vector of addition by two vectors. In details: we add q to this vector.

Note:
If q is null (0, 0) is assumed for q.
Parameters:
q - a vector reference
Returns:
a new instance initialized with result vector

subtract

public Vector2D subtract(Vector2D q)
Returns result vector. In details: we add q's reversed vector to this one

Note:
If q is null (0, 0) is assumed for q.
Parameters:
q - a vector reference
Returns:
a reference (to this) not a new instance.

difference

public Vector2D difference(Vector2D q)
Returns result vector of difference of two vectors. In details: we add q's reversed vector to this.

Note:
If q is null (0, 0) is assumed for q.
Parameters:
q - a vector reference
Returns:
a new instance initialized with result vector

scalar

public double scalar(Vector2D q)
Returns scalar product of this vector and q.

Note:
If q is null (0, 0) is assumed for q.
Parameters:
q - a vector reference
Returns:
a new instance initialized with result vector

equals

public boolean equals(java.lang.Object q)
Compares q to this object.
Parameters:
q - the reference object with which to compare.
Returns:
true if this object is the same as the obj argument; false otherwise.
Overrides:
equals in class java.lang.Object

clone

public java.lang.Object clone()
Creates a new Vector2D and initializes it with this.
Returns:
a clone of this instance.
Overrides:
clone in class java.lang.Object

toString

public java.lang.String toString()
Returns a String object representing this point.

Note:
This string looks like "(x , y)"
Overrides:
toString in class java.lang.Object