com.horstmann.violet.framework
Class Direction

java.lang.Object
  extended by com.horstmann.violet.framework.Direction

public class Direction
extends java.lang.Object

This class describes a direction in the 2D plane. A direction is a vector of length 1 with an angle between 0 (inclusive) and 360 degrees (exclusive). There is also a degenerate direction of length 0.


Field Summary
static Direction EAST
           
static Direction NORTH
           
static Direction SOUTH
           
static Direction WEST
           
 
Constructor Summary
Direction(double dx, double dy)
          Constructs a direction (normalized to length 1).
Direction(java.awt.geom.Point2D p, java.awt.geom.Point2D q)
          Constructs a direction between two points
 
Method Summary
 double getX()
          Gets the x-component of this direction
 double getY()
          Gets the y-component of this direction
 Direction turn(double angle)
          Turns this direction by an angle.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NORTH

public static final Direction NORTH

SOUTH

public static final Direction SOUTH

EAST

public static final Direction EAST

WEST

public static final Direction WEST
Constructor Detail

Direction

public Direction(double dx,
                 double dy)
Constructs a direction (normalized to length 1).

Parameters:
dx - the x-value of the direction
dy - the corresponding y-value of the direction

Direction

public Direction(java.awt.geom.Point2D p,
                 java.awt.geom.Point2D q)
Constructs a direction between two points

Parameters:
p - the starting point
q - the ending point
Method Detail

turn

public Direction turn(double angle)
Turns this direction by an angle.

Parameters:
angle - the angle in degrees

getX

public double getX()
Gets the x-component of this direction

Returns:
the x-component (between -1 and 1)

getY

public double getY()
Gets the y-component of this direction

Returns:
the y-component (between -1 and 1)