fi.utu.cs.physics
Class Vector2

java.lang.Object
  |
  +--fi.utu.cs.physics.Tuple2
        |
        +--fi.utu.cs.physics.Vector2
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable

public class Vector2
extends Tuple2
implements java.lang.Comparable

A two-component vector of double-precision floating point values.


Field Summary
static Vector2 ZERO
          A vector with the length 0.0.
 
Constructor Summary
Vector2(double dx, double dy)
          Creates a new two-component vector with the given values.
Vector2(Point2 source, Point2 target)
          Creates a new two-component vector from the given points.
 
Method Summary
 void add(double dx, double dy)
          Adds values to the components.
 void add(Vector2 other)
          Adds the components of other to the components.
 int compareTo(java.lang.Object o)
          Returns a negative integer, zero, or a positive integer as the length of this vector is less than, equal to, or greater than the length of vector o.
 double getDeltaX()
          Returns the horizontal component.
 double getDeltaY()
          Returns the vertical component.
 double length()
          Returns the length of this vector.
 double lengthSquared()
          Returns the squared length of this vector.
 void rotate(double r)
          Rotates the vector counterclockwise.
 void rotate180()
          Rotates the vector 180 degrees counterclockwise.
 void rotate270()
          Rotates the vector 270 degrees counterclockwise.
 void rotate90()
          Rotates the vector 90 degrees counterclockwise.
 void set(double dx, double dy)
          Sets the horizontal and vertical component.
 void set(Point2 source, Point2 target)
          Sets the horizontal and vertical components to correspond the transfer from the point source to the point target.
 void set(Vector2 v)
          Sets the horizontal and vertical components to the same values as in other.
 void setDeltaX(double dx)
          Sets the horizontal component to the value dx.
 void setDeltaY(double dy)
          Sets the vertical component to the value dy.
 Point2 transfer(Point2 source)
          Creates and returns a point that is transfered from the point source according to this vector.
 
Methods inherited from class fi.utu.cs.physics.Tuple2
add, clone, equals, getFirstElement, getSecondElement, hashCode, max, min, negate, negateFirstElement, negateSecondElement, set, setFirstElement, setSecondElement, swap, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ZERO

public static final Vector2 ZERO
A vector with the length 0.0.
Constructor Detail

Vector2

public Vector2(double dx,
               double dy)
Creates a new two-component vector with the given values.

Vector2

public Vector2(Point2 source,
               Point2 target)
Creates a new two-component vector from the given points. In the new vector, this.getDeltaX() = target.getX() - source.getX() and this.getDeltaY() = target.getY() - source.getY().
Method Detail

getDeltaX

public double getDeltaX()
Returns the horizontal component.

getDeltaY

public double getDeltaY()
Returns the vertical component.

setDeltaX

public void setDeltaX(double dx)
Sets the horizontal component to the value dx.

setDeltaY

public void setDeltaY(double dy)
Sets the vertical component to the value dy.

set

public void set(double dx,
                double dy)
Sets the horizontal and vertical component.
Overrides:
set in class Tuple2
Parameters:
dx - The value of the horizontal component.
dy - The value of the vertical component.
See Also:
set(Point2,Point2), set(Vector2)

set

public void set(Point2 source,
                Point2 target)
Sets the horizontal and vertical components to correspond the transfer from the point source to the point target. After the operation, this.getDeltaX() = target.getX() - this.getX() and this.getDeltaY() = target.getY() - this.getY().
See Also:
set(Vector2)

set

public void set(Vector2 v)
Sets the horizontal and vertical components to the same values as in other.

length

public double length()
Returns the length of this vector.

lengthSquared

public double lengthSquared()
Returns the squared length of this vector.

add

public void add(double dx,
                double dy)
Adds values to the components.
Overrides:
add in class Tuple2
Parameters:
dx - The value added to the horizontal component.
dy - The value added to the vertical component.
See Also:
add(Vector2)

add

public void add(Vector2 other)
Adds the components of other to the components.

transfer

public Point2 transfer(Point2 source)
Creates and returns a point that is transfered from the point source according to this vector. In the new point, getX() = source.getX() + this.getDeltaX() and getY() = source.getY() + this.getDeltaY().

rotate90

public void rotate90()
Rotates the vector 90 degrees counterclockwise.
See Also:
rotate(double), rotate180(), rotate270()

rotate180

public void rotate180()
Rotates the vector 180 degrees counterclockwise.
See Also:
rotate(double), rotate90(), rotate270()

rotate270

public void rotate270()
Rotates the vector 270 degrees counterclockwise.
See Also:
rotate(double), rotate90(), rotate180()

rotate

public void rotate(double r)
Rotates the vector counterclockwise.
Parameters:
r - The amount of rotation in radians.
See Also:
rotate90(), rotate180(), rotate270()

compareTo

public int compareTo(java.lang.Object o)
Returns a negative integer, zero, or a positive integer as the length of this vector is less than, equal to, or greater than the length of vector o.
Specified by:
compareTo in interface java.lang.Comparable
Throws:
ClassCastException - If the argument is not of the type Vector2.