y.geom
Class YVector

java.lang.Object
  |
  +--y.geom.YVector

public class YVector
extends Object

This class represents a vector in the 2-dimensional real vector space. This vector is an ordered 2 tupel and is defined by two doubles.


Constructor Summary
YVector(double dx, double dy)
          Creates a new vector with given direction.
YVector(double x1, double y1, double x2, double y2)
          Creates a new vector, whose direction is given by two points.
YVector(YPoint p1)
          Creates a new vector, whose direction is given by a point.
YVector(YPoint p1, YPoint p2)
          Creates a new vector, whose direction is given by two points.
YVector(YVector v)
          Creates a new vector which is a copy of another vector.
 
Method Summary
static YPoint add(YPoint p, YVector v)
          Adds the vector to a point and returns the resulting point.
 void add(YVector v)
          Adds a vector to this vector.
static YVector add(YVector v, YVector w)
          Adds two vectors and returns the result.
static double angle(YVector v1, YVector v2)
          Returns the angle between two vectors in counter clockwise order from v1 to v2.
static YVector getNormal(YVector v)
          Returns this vector with unit length.
 double getX()
          Returns the first coordinate of the vector.
 double getY()
          Returns the second coordinate of the vector.
 double length()
          Returns the length of the vector, this is the value of the eucledian norm.
 void norm()
          Assigns unit length to the vector.
static YVector orthoNormal(YVector v)
          Returns the vector which is orthogonal to the given one and has unit lenght.
static boolean rightOf(YVector v1, YVector v2)
          Returns true if vector v1 is on the right side of v2.
static double scalarProduct(YVector v1, YVector v2)
          Returns the value of the scalar product of two vectors.
 void scale(double factor)
          Scales the vector by an factor.
 String toString()
          Returns a string representation of this vector.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

YVector

public YVector(double dx,
               double dy)
Creates a new vector with given direction.

Parameters:
dx - the first coordinate
dy - the second coordinate

YVector

public YVector(YVector v)
Creates a new vector which is a copy of another vector.

Parameters:
v - the vector, whose values are copied.

YVector

public YVector(YPoint p1,
               YPoint p2)
Creates a new vector, whose direction is given by two points. The vector is defined by p1 - p2.

Parameters:
p1 - the first point.
p2 - the second point.

YVector

public YVector(YPoint p1)
Creates a new vector, whose direction is given by a point. The vector is defined by p1 - (0,0).

Parameters:
p1 - the point.

YVector

public YVector(double x1,
               double y1,
               double x2,
               double y2)
Creates a new vector, whose direction is given by two points. The vector is defined by (x1 - x2, y1 - y2).

Parameters:
x1 - the X-coordinate of the first point.
y1 - the Y-coordinate of the first point.
x2 - the X-coordinate of the second point.
y2 - the Y-coordinate of the second point.
Method Detail

getX

public double getX()
Returns the first coordinate of the vector.

Returns:
the X-coordinate of the vector.

getY

public double getY()
Returns the second coordinate of the vector.

Returns:
the X-coordinate of the vector.

norm

public void norm()
Assigns unit length to the vector.

Postcondition:
length() == 1.

add

public void add(YVector v)
Adds a vector to this vector.

Parameters:
v - the vector to add.

add

public static YVector add(YVector v,
                          YVector w)
Adds two vectors and returns the result.

Parameters:
v - first vector to sum.
w - second vector to summ.
Returns:
v+w

add

public static YPoint add(YPoint p,
                         YVector v)
Adds the vector to a point and returns the resulting point.

Parameters:
p - a point.
v - the vector to add to the point.
Returns:
p+v

scale

public void scale(double factor)
Scales the vector by an factor.

Parameters:
factor - the scale factor, with which the lenght is multiplied.

length

public double length()
Returns the length of the vector, this is the value of the eucledian norm.

Returns:
a value > 0.

rightOf

public static boolean rightOf(YVector v1,
                              YVector v2)
Returns true if vector v1 is on the right side of v2.


getNormal

public static YVector getNormal(YVector v)
Returns this vector with unit length.


orthoNormal

public static YVector orthoNormal(YVector v)
Returns the vector which is orthogonal to the given one and has unit lenght.

Parameters:
v - a vector.
Returns:
a vector which is orthogonal to v with unit length.

scalarProduct

public static double scalarProduct(YVector v1,
                                   YVector v2)
Returns the value of the scalar product of two vectors.

Parameters:
v1 - the first vector.
v2 - the second vector.
Returns:
v1.x * v2.x + v1.y * v2.y

angle

public static double angle(YVector v1,
                           YVector v2)
Returns the angle between two vectors in counter clockwise order from v1 to v2.


toString

public String toString()
Returns a string representation of this vector.

Overrides:
toString in class Object

© Copyright 2000-2003,
yWorks GmbH.
All rights reserved.

2003