Search this API

y.geom
Class YVector

java.lang.Object
  extended by y.geom.YVector

public class YVector
extends java.lang.Object

This class represents a vector in the 2-dimensional real vector space. This vector is an ordered 2 tuple 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 addAngle(double a1, double a2)
          Returns the result of the addition of two angles between 0 and 2*Pi.
static double angle(YVector v1, YVector v2)
          Returns the angle (measured in radians) between two vectors in clockwise order (with regards to screen coordinates) 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 euclidean 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 length.
static boolean rightOf(YVector v1, YVector v2)
          Returns true if vector v1 is on the right side of v2.
 YVector rotate(double angle)
          Returns a new YVector instance that is obtained by rotating this vector by the given angle (measured in radians) in clockwise direction (with regards to screen coordinates).
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.
 java.lang.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.

rotate

public YVector rotate(double angle)
Returns a new YVector instance that is obtained by rotating this vector by the given angle (measured in radians) in clockwise direction (with regards to screen coordinates). Screen coordinates mean positive x-direction is from left to right and positive y-direction is from top to bottom:
 0 --> 1
 |
 v
 1
 

Parameters:
angle - the angle of rotation in radians.
Returns:
the rotated vector.

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 sum.
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 length is multiplied.

length

public double length()
Returns the length of the vector, this is the value of the euclidean 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 length.

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 (measured in radians) between two vectors in clockwise order (with regards to screen coordinates) from v1 to v2. Screen coordinates mean positive x-direction is from left to right and positive y-direction is from top to bottom:
 0 --> 1
 |
 v
 1
 


addAngle

public static double addAngle(double a1,
                              double a2)
Returns the result of the addition of two angles between 0 and 2*Pi. The result is calculated modulo 2*Pi.

Parameters:
a1 - a value in [0,2Pi).
a2 - a value in [0,2Pi).
Returns:
The sum of a1 and a2 modulo 2*Pi.

toString

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

Overrides:
toString in class java.lang.Object

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