nl.tudelft.simulation.language.d2
Class DirectionalLine

java.lang.Object
  extended by java.awt.geom.Line2D
      extended by java.awt.geom.Line2D.Double
          extended by nl.tudelft.simulation.language.d2.DirectionalLine
All Implemented Interfaces:
Shape, Serializable, Cloneable

public class DirectionalLine
extends Line2D.Double

A directional line with normal vector. Based on the BSPLine-example from the book Developing games in Java from David Brackeen. DirectionalLine.java

(c) copyright 2002-2005 Delft University of Technology , the Netherlands.

See for project information www.simulation.tudelft.nl/language
License of use: Lesser General Public License (LGPL) , no warranty

Version:
$Revision: 1.1 $ $Date: 2007/01/06 13:25:55 $
Author:
Roy Chin
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.geom.Line2D
Line2D.Double, Line2D.Float
 
Field Summary
static int BACKSIDE
          point at the back of the line
static int COLLINEAR
          point collinear with the line
static int FRONTSIDE
          point in front of the line
static int SPANNING
          other line is spanning this line
 
Fields inherited from class java.awt.geom.Line2D.Double
x1, x2, y1, y2
 
Constructor Summary
DirectionalLine(double x1, double y1, double x2, double y2)
          Creates a new DirectionalLine based on the specified coordinates.
 
Method Summary
 void calcNormal()
          Calculates the normal to this line.
 boolean equalsCoordinates(DirectionalLine line)
          Returns true if the endpoints of this line match the endpoints of the specified line.
 boolean equalsCoordinatesIgnoreOrder(DirectionalLine line)
          Returns true if the endpoints of this line match the endpoints of the specified line, ignoring endpoint order (if the first point of this line is equal to the second point of the specified line, and vice versa, returns true).
 void flip()
          Flips this line so that the end points are reversed (in other words, (x1,y1) becomes (x2,y2) and vice versa) and the normal is changed to point the opposite direction.
 double getIntersection(Line2D.Double line)
          Returns the fraction of intersection along this line.
 Point2D.Double getIntersectionPoint(Line2D.Double line)
          Returns the interection point of this line with the specified line.
 double getLineThickness()
          Gets the thickness of the line.
 double getNormalx()
           
 double getNormaly()
           
 int getSide(Line2D.Double line)
          Gets the side of this line that the specified line segment is on.
 int getSideThick(double x, double y)
          Gets the side of this line the specified point is on.
 int getSideThin(double x, double y)
          Gets the side of this line the specified point is on.
 void normalize()
          Normalizes the normal of this line (make the normal's length 1).
 void setLine(double x1, double y1, double x2, double y2)
           
 void setLine(float x1, float y1, float x2, float y2)
          Set the line using floats.
 void setLineThickness(double lineThickness)
          Sets the tickness of the line.
 String toString()
           
 
Methods inherited from class java.awt.geom.Line2D.Double
getBounds2D, getP1, getP2, getX1, getX2, getY1, getY2
 
Methods inherited from class java.awt.geom.Line2D
clone, contains, contains, contains, contains, getBounds, getPathIterator, getPathIterator, intersects, intersects, intersectsLine, intersectsLine, linesIntersect, ptLineDist, ptLineDist, ptLineDist, ptLineDistSq, ptLineDistSq, ptLineDistSq, ptSegDist, ptSegDist, ptSegDist, ptSegDistSq, ptSegDistSq, ptSegDistSq, relativeCCW, relativeCCW, relativeCCW, setLine, setLine
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

BACKSIDE

public static final int BACKSIDE
point at the back of the line

See Also:
Constant Field Values

COLLINEAR

public static final int COLLINEAR
point collinear with the line

See Also:
Constant Field Values

FRONTSIDE

public static final int FRONTSIDE
point in front of the line

See Also:
Constant Field Values

SPANNING

public static final int SPANNING
other line is spanning this line

See Also:
Constant Field Values
Constructor Detail

DirectionalLine

public DirectionalLine(double x1,
                       double y1,
                       double x2,
                       double y2)
Creates a new DirectionalLine based on the specified coordinates.

Parameters:
x1 - Coordinate x1
y1 - Coordinate y1
x2 - Coordinate x2
y2 - Coordinate y2
Method Detail

calcNormal

public void calcNormal()
Calculates the normal to this line.


normalize

public void normalize()
Normalizes the normal of this line (make the normal's length 1).


setLine

public void setLine(float x1,
                    float y1,
                    float x2,
                    float y2)
Set the line using floats.

Parameters:
x1 - x1 coordinate
y1 - y1 coodinate
x2 - x2 coordinate
y2 - y2 coordinate

setLine

public void setLine(double x1,
                    double y1,
                    double x2,
                    double y2)
Overrides:
setLine in class Line2D.Double
See Also:
Line2D.setLine(double, double, double, double)

flip

public void flip()
Flips this line so that the end points are reversed (in other words, (x1,y1) becomes (x2,y2) and vice versa) and the normal is changed to point the opposite direction.


equalsCoordinates

public boolean equalsCoordinates(DirectionalLine line)
Returns true if the endpoints of this line match the endpoints of the specified line. Ignores normal and height values.

Parameters:
line - another line
Returns:
true if this line's coordinates are equal to the other line's coordinates

equalsCoordinatesIgnoreOrder

public boolean equalsCoordinatesIgnoreOrder(DirectionalLine line)
Returns true if the endpoints of this line match the endpoints of the specified line, ignoring endpoint order (if the first point of this line is equal to the second point of the specified line, and vice versa, returns true). Ignores normal and height values.

Parameters:
line - another line
Returns:
true if coordinates match independent of the order

toString

public String toString()
Overrides:
toString in class Object
See Also:
Object.toString()

getSideThick

public int getSideThick(double x,
                        double y)
Gets the side of this line the specified point is on. This method treats the line as 1-unit thick, so points within this 1-unit border are considered collinear. For this to work correctly, the normal of this line must be normalized, either by setting this line to a polygon or by calling normalize(). Returns either FRONTSIDE, BACKSIDE, or COLLINEAR.

Parameters:
x - coordinate x
y - coordinate y
Returns:
the side

getSideThin

public int getSideThin(double x,
                       double y)
Gets the side of this line the specified point is on. Because of doubleing point inaccuracy, a collinear line will be rare. For this to work correctly, the normal of this line must be normalized, either by setting this line to a polygon or by calling normalize(). Returns either FRONTSIDE, BACKSIDE, or COLLINEAR.

Parameters:
x - coordinate x
y - coordinate y
Returns:
the side

getSide

public int getSide(Line2D.Double line)
Gets the side of this line that the specified line segment is on. Returns either FRONT, BACK, COLINEAR, or SPANNING.

Parameters:
line - line segment
Returns:
the side

getIntersection

public double getIntersection(Line2D.Double line)
Returns the fraction of intersection along this line. Returns a value from 0 to 1 if the segments intersect. For example, a return value of 0 means the intersection occurs at point (x1, y1), 1 means the intersection occurs at point (x2, y2), and .5 mean the intersection occurs halfway between the two endpoints of this line. Returns -1 if the lines are parallel.

Parameters:
line - a line
Returns:
the intersection

getIntersectionPoint

public Point2D.Double getIntersectionPoint(Line2D.Double line)
Returns the interection point of this line with the specified line.

Parameters:
line - a line
Returns:
intersection point

getLineThickness

public double getLineThickness()
Gets the thickness of the line.

Returns:
returns the lineThickness

setLineThickness

public void setLineThickness(double lineThickness)
Sets the tickness of the line.

Parameters:
lineThickness - the lineThickness to set

getNormalx

public double getNormalx()
Returns:
returns the normalX

getNormaly

public double getNormaly()
Returns:
returns the normalY


Copyright © 2002-2011 Delft University of Technology, the Netherlands. All Rights Reserved.