auc.geom
Class Vector2D

java.lang.Object
  |
  +--auc.geom.Vector2D

public class Vector2D
extends java.lang.Object

The Vector2D class for the two-dimensional vector algebra. This class provides vectorial operations for the 2-dimensional vectors: addition, subtraction and multiplication by scalar value.


Field Summary
static double precision
          The precision of vector operations.
 double x
          The x-coordinate of the vector.
 double y
          The y-coordinate of the vector.
 
Constructor Summary
Vector2D()
          Constructs a zero value Vector2D(0,0).
Vector2D(double x, double y)
          Constructs the Vector2D with the given value.
Vector2D(Vector2D p)
          Constructs an exact copy of the given Vector2D.
 
Method Summary
 double abs()
          Calculates the Euclidian length of this vector.
 Vector2D add(double x, double y)
          Calculates the sum vector of this and given coordinates: this.x := this.x + x, this.y := this.y + y.
 Vector2D add(Vector2D p)
          Calculates the sum vector of this and given coordinates: this := this + p.
 double angle(Vector2D p)
          Calculates the angle between this and given vector in radians.
 double angle3(Vector2D b, Vector2D c)
          Calculates the angle between two edges, the vertex of the angle is this vector.
 double angleX()
          Calculates the angle between this vector and the x-axis.
 double distance(Vector2D p)
          Calculates the Euclidian distance between this and given vector points.
 boolean equals(java.lang.Object obj)
          Compares this vector with given object.
 Vector2D multiply(double c)
          Multiplies this vector by scalar value.
 Vector2D normalize()
          Calculates the normal of this vector.
 Vector2D rotate(double angle)
          Rotates this vector around 0,0 point by given angle.
 Vector2D set(double x, double y)
          Coordinates set operation.
 Vector2D set(Vector2D p)
          Coordinates set operation.
 Vector2D subtract(double x, double y)
          Calculates the difference vector of this and given coordinates: this.x := this.x - x, this.y := this.y - y.
 Vector2D subtract(Vector2D p)
          Calculates the difference vector of this and given vector: this := this - p.
 java.lang.String toString()
          The standart method for String concatination operation overriding.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

x

public double x
The x-coordinate of the vector.

y

public double y
The y-coordinate of the vector.

precision

public static double precision
The precision of vector operations. Caution: the change of this parameter in any Vector2D instance makes change in any other Vector2D object calculations (because it is a static variable).
Constructor Detail

Vector2D

public Vector2D(double x,
                double y)
Constructs the Vector2D with the given value.
Parameters:
x - the x-coordinate for the vector.
y - the y-coordinate for the vector.
See Also:
x, y

Vector2D

public Vector2D(Vector2D p)
Constructs an exact copy of the given Vector2D.
Parameters:
p - the original vector.

Vector2D

public Vector2D()
Constructs a zero value Vector2D(0,0).
See Also:
Vector2D(double, double)
Method Detail

equals

public boolean equals(java.lang.Object obj)
Compares this vector with given object.
Overrides:
equals in class java.lang.Object
Parameters:
obj - the object to compare with.
Returns:
true if and only if the obj is Vector2D and the distance(obj) is less than precision.
See Also:
precision, distance(Vector2D)

distance

public double distance(Vector2D p)
Calculates the Euclidian distance between this and given vector points. This is equivalent to this.subtract(p).abs(), except it does not change the vectors.
Parameters:
p - the vector that points to another point in 2D space.
Returns:
the distance between two points double value.

abs

public double abs()
Calculates the Euclidian length of this vector.
Returns:
the absolute double value of this vector.

set

public Vector2D set(double x,
                    double y)
Coordinates set operation. This method sets the vector coordinates to the given ones.
Parameters:
x - the new x-coordinate for this vector.
y - the new y-coordinate for this vector.
Returns:
this altered vector (no new vector-objects are created!).
See Also:
set(Vector2D)

set

public Vector2D set(Vector2D p)
Coordinates set operation. This method sets the vector coordinates to the given vector coordinates.
Parameters:
p - the new x and y coordinates for this vector encapsulated in a Vector2D object.
Returns:
this altered vector (no new vector-objects are created!).
See Also:
set(double, double)

add

public Vector2D add(double x,
                    double y)
Calculates the sum vector of this and given coordinates: this.x := this.x + x, this.y := this.y + y.
Parameters:
x - the x-coordinate to be added.
y - the y-coordinate to be added.
Returns:
this sum vector (no new vector-objects are created!).
See Also:
add(Vector2D)

add

public Vector2D add(Vector2D p)
Calculates the sum vector of this and given coordinates: this := this + p.
Parameters:
p - the vector to be added.
Returns:
this sum vector (no new vector-objects are created!).
See Also:
add(double, double)

subtract

public Vector2D subtract(double x,
                         double y)
Calculates the difference vector of this and given coordinates: this.x := this.x - x, this.y := this.y - y.
Parameters:
x - the x-coordinate to be subtracted.
y - the y-coordinate to be subtracted.
Returns:
this subtracted vector (no new vector-objects are created!).
See Also:
subtract(Vector2D)

subtract

public Vector2D subtract(Vector2D p)
Calculates the difference vector of this and given vector: this := this - p.
Parameters:
p - the vector to be subtracted.
Returns:
this subtracted vector (no new vector-objects are created!).
See Also:
subtract(double, double)

normalize

public Vector2D normalize()
Calculates the normal of this vector. The length of the vector becomes 1, but the direction is kept the same.
Returns:
this normalized vector (no new vector-objects are created!).

multiply

public Vector2D multiply(double c)
Multiplies this vector by scalar value.
Parameters:
c - the scalar double value.
Returns:
this multiplied vector (no new vector-objects are created!).

rotate

public Vector2D rotate(double angle)
Rotates this vector around 0,0 point by given angle.
Parameters:
angle - the angle double value in radians.
Returns:
This rotated vector (no new vector-objects are created!).

angleX

public double angleX()
Calculates the angle between this vector and the x-axis. This mathod is used by Vector2D#angle(Vector2D) method.
Returns:
the double value of the angle in radians.
See Also:
angle(Vector2D)

angle

public double angle(Vector2D p)
Calculates the angle between this and given vector in radians. The angle is always between -Math.PI and Math.PI.
Parameters:
p - the given vector.
Returns:
The double value of the angle.
See Also:
angleX()

angle3

public double angle3(Vector2D b,
                     Vector2D c)
Calculates the angle between two edges, the vertex of the angle is this vector.
Parameters:
b - is the first edge of the angle.
c - is the second edge of the angle.
Returns:
the double value of the angle in radians, the value is always between -Math.PI and Math.PI.

toString

public java.lang.String toString()
The standart method for String concatination operation overriding.
Overrides:
toString in class java.lang.Object
Returns:
the string representation of the object (class signiture and the main fields values).