java.awt.geom
Class Line2D

java.lang.Object
  extended by java.awt.geom.Line2D
All Implemented Interfaces:
Shape, Cloneable
Direct Known Subclasses:
Line2D.Double, Line2D.Float

public abstract class Line2D
extends Object
implements Shape, Cloneable

An abstract class representing a line in two dimensional space

Author:
Lawrie Griffiths

Nested Class Summary
static class Line2D.Double
          A line in 2D space using float coordinates
static class Line2D.Float
          A line in 2D space using float coordinates
 
Constructor Summary
protected Line2D()
          This is an abstract class that cannot be instantiated: use Line2D.Float or Line2D.Double.
 
Method Summary
 Object clone()
          Create a copy of this object, using a shallow copy.
 boolean contains(double x, double y)
          Test if the shape contains the point (x,y)
 boolean contains(double x, double y, double w, double h)
          Test if the shape contains the rectangle with top left at (x,y), width w and height h.
 boolean contains(Point2D p)
          Test if the shape contains the Point2D
 boolean contains(Rectangle2D r)
          Test if the shape contains the Rectangle2D
 Rectangle getBounds()
          Get the bounding Rectangle for the shape
abstract  Point2D getP1()
          Get the start point of the line as a Point2D
abstract  Point2D getP2()
          Get the end point of the line as a Point2D
abstract  double getX1()
          Get the x coordinate of the start of the line
abstract  double getX2()
          Get the x coordinate of the end of the line
abstract  double getY1()
          Get the y coordinate of the start of the line
abstract  double getY2()
          Get the y coordinate of the end of the line
 boolean intersects(double x, double y, double w, double h)
          Test if the shape intersects the rectangle with top left at (x,y), width w and height h.
 boolean intersects(Rectangle2D r)
          Test if the shape intersects the Rectangle2D r
 boolean intersectsLine(double x1, double y1, double x2, double y2)
          Test if this line intersects a given line
 boolean intersectsLine(Line2D l)
          Tests if this line intersects a given line
static boolean linesIntersect(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
          Test if one line intersects another line
 int relativeCCW(double px, double py)
          Returns an indicator of where the specified point lies with respect to the line.
static int relativeCCW(double x1, double y1, double x2, double y2, double px, double py)
          Returns an indicator of where the specified point lies with respect to the line
 int relativeCCW(Point2D p)
          Returns an indicator of where the specified point lies with respect to the line
abstract  void setLine(double x1, double y1, double x2, double y2)
          Sets the end points of the line using double coordinates.
 void setLine(Line2D line)
          Set the end points of a line to the same as a given line
 void setLine(Point2D p1, Point2D p2)
          Sets the end points of the line from a given start and end point
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.awt.Shape
getBounds2D
 

Constructor Detail

Line2D

protected Line2D()
This is an abstract class that cannot be instantiated: use Line2D.Float or Line2D.Double.

Method Detail

getX1

public abstract double getX1()
Get the x coordinate of the start of the line

Returns:
the x coordinate as a double

getY1

public abstract double getY1()
Get the y coordinate of the start of the line

Returns:
the y coordinate as a double

getP1

public abstract Point2D getP1()
Get the start point of the line as a Point2D

Returns:
the Point2D

getX2

public abstract double getX2()
Get the x coordinate of the end of the line

Returns:
the x coordinate as a double

getY2

public abstract double getY2()
Get the y coordinate of the end of the line

Returns:
the y coordinate as a double

getP2

public abstract Point2D getP2()
Get the end point of the line as a Point2D

Returns:
the Point2D

setLine

public abstract void setLine(double x1,
                             double y1,
                             double x2,
                             double y2)
Sets the end points of the line using double coordinates.

Parameters:
x1 - the x coordinate of the start point
y1 - the y coordinate of the start point
x2 - the x coordinate of the end point
y2 - the y coordinate of the end point

setLine

public void setLine(Point2D p1,
                    Point2D p2)
Sets the end points of the line from a given start and end point

Parameters:
p1 - the start point
p2 - the end point

setLine

public void setLine(Line2D line)
Set the end points of a line to the same as a given line

Parameters:
line - the given line

contains

public boolean contains(double x,
                        double y)
Description copied from interface: Shape
Test if the shape contains the point (x,y)

Specified by:
contains in interface Shape
Parameters:
x - the x co-ordinate of the point
y - the y co-ordinate of the point
Returns:
true iff the shape contains the point

contains

public boolean contains(Point2D p)
Description copied from interface: Shape
Test if the shape contains the Point2D

Specified by:
contains in interface Shape
Parameters:
p - the Point2D
Returns:
true iff the shape contains the point

contains

public boolean contains(double x,
                        double y,
                        double w,
                        double h)
Description copied from interface: Shape
Test if the shape contains the rectangle with top left at (x,y), width w and height h.

Specified by:
contains in interface Shape
Parameters:
x - the x-coordinate of the top left point of the rectangle
y - the y-coordinate of the top left point of the rectangle
w - the width of the rectangle
h - the height of the rectangle
Returns:
true iff the shape contains the rectangle

contains

public boolean contains(Rectangle2D r)
Description copied from interface: Shape
Test if the shape contains the Rectangle2D

Specified by:
contains in interface Shape
Parameters:
r - the Rectangle2D
Returns:
true iff the shape contains the Rectangle2D

intersects

public boolean intersects(double x,
                          double y,
                          double w,
                          double h)
Description copied from interface: Shape
Test if the shape intersects the rectangle with top left at (x,y), width w and height h.

Specified by:
intersects in interface Shape
Parameters:
x - the x-coordinate of the top left point of the rectangle
y - the y-coordinate of the top left point of the rectangle
w - the width of the rectangle
h - the height of the rectangle
Returns:
true iff the shape intersects the rectangle

intersectsLine

public boolean intersectsLine(double x1,
                              double y1,
                              double x2,
                              double y2)
Test if this line intersects a given line

Parameters:
x1 - the x coordinate of the start of the given line
y1 - the y coordinate of the start of the given line
x2 - the x coordinate of the end of the given line
y2 - the y coordinate of the end of the given line
Returns:
true iff the lines intersect

intersectsLine

public boolean intersectsLine(Line2D l)
Tests if this line intersects a given line

Parameters:
l - the given line
Returns:
true iff the lines intersect

linesIntersect

public static boolean linesIntersect(double x1,
                                     double y1,
                                     double x2,
                                     double y2,
                                     double x3,
                                     double y3,
                                     double x4,
                                     double y4)
Test if one line intersects another line

Parameters:
x1 - the x coordinate of the start of the first line
y1 - the y coordinate of the start of the first line
x2 - the x coordinate of the end of the first line
y2 - the y coordinate of the end of the first line
x3 - the x coordinate of the start of the second line
y3 - the y coordinate of the start of the second line
x4 - the x coordinate of the end of the second line
y4 - the y coordinate of the end of the second line
Returns:
true iff the lines intersect

getBounds

public Rectangle getBounds()
Description copied from interface: Shape
Get the bounding Rectangle for the shape

Specified by:
getBounds in interface Shape
Returns:
the bounding Rectangle

clone

public Object clone()
Description copied from class: Object
Create a copy of this object, using a shallow copy.

Overrides:
clone in class Object
Returns:
The new copy of the Object

relativeCCW

public static int relativeCCW(double x1,
                              double y1,
                              double x2,
                              double y2,
                              double px,
                              double py)
Returns an indicator of where the specified point lies with respect to the line

Parameters:
x1 - the x coordinate of the start of the line
y1 - the y coordinate of the start of the line
x2 - the x coordinate of the end of the line
y2 - the y coordinate of the end of the line
px - the x coordinate of the specified point
py - the y coordinate of the specified point
Returns:
0 iff the point is on the line else 1 or -1 depending on whether the point in to the left or ahead of the line, or to the right or behind the line segment

relativeCCW

public int relativeCCW(Point2D p)
Returns an indicator of where the specified point lies with respect to the line

Parameters:
p - the specified point
Returns:
0 iff the point is on the line else 1 or -1 depending on whether the point in to the left or ahead of the line, or to the right or behind the line segment

relativeCCW

public int relativeCCW(double px,
                       double py)
Returns an indicator of where the specified point lies with respect to the line.

Parameters:
px - the x coordinate of the specified point
py - the y coordinate of the specified point
Returns:
0 iff the point is on the line else 1 or -1 depending on whether the point in to the left or ahead of the line, or to the right or behind the line segment

intersects

public boolean intersects(Rectangle2D r)
Description copied from interface: Shape
Test if the shape intersects the Rectangle2D r

Specified by:
intersects in interface Shape
Parameters:
r - the Recangle2D
Returns:
true iff the shape intersects the Rectangle2D