Class Line2D

java.lang.Object
armyc2.c5isr.graphics2d.Line2D
Direct Known Subclasses:
Line2D.Double, Line2D.Float

public abstract class Line2D extends Object
This Line2D represents a line segment in (x,y) coordinate space. This class, like all of the Java 2D API, uses a default coordinate system called user space in which the y-axis values increase downward and x-axis values increase to the right. For more information on the user space coordinate system, see the Coordinate Systems section of the Java 2D Programmer's Guide.

This class is only the abstract superclass for all objects that store a 2D line segment. The actual storage representation of the coordinates is left to the subclass.

Since:
1.2
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    A line segment specified with double coordinates.
    static class 
    A line segment specified with float coordinates.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    This is an abstract class that cannot be instantiated directly.
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates a new object of the same class as this object.
    boolean
    contains(double x, double y)
    Tests if a specified coordinate is inside the boundary of this Line2D.
    boolean
    contains(double x, double y, double w, double h)
    Tests if the interior of this Line2D entirely contains the specified set of rectangular coordinates.
    boolean
    Tests if a given Point2D is inside the boundary of this Line2D.
    boolean
    Tests if the interior of this Line2D entirely contains the specified Rectangle2D.
     
    abstract Point2D
    Returns the start Point2D of this Line2D.
    abstract Point2D
    Returns the end Point2D of this Line2D.
    abstract double
    Returns the X coordinate of the start point in double precision.
    abstract double
    Returns the X coordinate of the end point in double precision.
    abstract double
    Returns the Y coordinate of the start point in double precision.
    abstract double
    Returns the Y coordinate of the end point in double precision.
    boolean
     
    static boolean
    linesIntersect(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
     
    double
    ptLineDist(double px, double py)
    Returns the distance from a point to this line.
    static double
    ptLineDist(double x1, double y1, double x2, double y2, double px, double py)
    Returns the distance from a point to a line.
    double
    Returns the distance from a Point2D to this line.
    double
    ptLineDistSq(double px, double py)
    Returns the square of the distance from a point to this line.
    static double
    ptLineDistSq(double x1, double y1, double x2, double y2, double px, double py)
    Returns the square of the distance from a point to a line.
    double
    Returns the square of the distance from a specified Point2D to this line.
    int
    relativeCCW(double px, double py)
    Returns an indicator of where the specified point (px,py) lies with respect to this line segment.
    static int
    relativeCCW(double x1, double y1, double x2, double y2, double px, double py)
    Returns an indicator of where the specified point (px,py) lies with respect to the line segment from (x1,y1) to (x2,y2).
    abstract void
    setLine(double x1, double y1, double x2, double y2)
    Sets the location of the end points of this Line2D to the specified double coordinates.
    void
    Sets the location of the end points of this Line2D to the same as those end points of the specified Line2D.
    void
    Sets the location of the end points of this Line2D to the specified Point2D coordinates.

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Line2D

      protected Line2D()
      This is an abstract class that cannot be instantiated directly. Type-specific implementation subclasses are available for instantiation and provide a number of formats for storing the information necessary to satisfy the various accessory methods below.
      Since:
      1.2
      See Also:
  • Method Details

    • getBounds2D

    • intersectsLine

      public boolean intersectsLine(Line2D edge)
    • linesIntersect

      public static boolean linesIntersect(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
    • getX1

      public abstract double getX1()
      Returns the X coordinate of the start point in double precision.
      Returns:
      the X coordinate of the start point of this Line2D object.
      Since:
      1.2
    • getY1

      public abstract double getY1()
      Returns the Y coordinate of the start point in double precision.
      Returns:
      the Y coordinate of the start point of this Line2D object.
      Since:
      1.2
    • getP1

      public abstract Point2D getP1()
      Returns the start Point2D of this Line2D.
      Returns:
      the start Point2D of this Line2D.
      Since:
      1.2
    • getX2

      public abstract double getX2()
      Returns the X coordinate of the end point in double precision.
      Returns:
      the X coordinate of the end point of this Line2D object.
      Since:
      1.2
    • getY2

      public abstract double getY2()
      Returns the Y coordinate of the end point in double precision.
      Returns:
      the Y coordinate of the end point of this Line2D object.
      Since:
      1.2
    • getP2

      public abstract Point2D getP2()
      Returns the end Point2D of this Line2D.
      Returns:
      the end Point2D of this Line2D.
      Since:
      1.2
    • setLine

      public abstract void setLine(double x1, double y1, double x2, double y2)
      Sets the location of the end points of this Line2D to the specified 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
      Since:
      1.2
    • setLine

      public void setLine(Point2D p1, Point2D p2)
      Sets the location of the end points of this Line2D to the specified Point2D coordinates.
      Parameters:
      p1 - the start Point2D of the line segment
      p2 - the end Point2D of the line segment
      Since:
      1.2
    • setLine

      public void setLine(Line2D l)
      Sets the location of the end points of this Line2D to the same as those end points of the specified Line2D.
      Parameters:
      l - the specified Line2D
      Since:
      1.2
    • 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 (px,py) lies with respect to the line segment from (x1,y1) to (x2,y2). The return value can be either 1, -1, or 0 and indicates in which direction the specified line must pivot around its first end point, (x1,y1), in order to point at the specified point (px,py) .

      A return value of 1 indicates that the line segment must turn in the direction that takes the positive X axis towards the negative Y axis. In the default coordinate system used by Java 2D, this direction is counterclockwise.

      A return value of -1 indicates that the line segment must turn in the direction that takes the positive X axis towards the positive Y axis. In the default coordinate system, this direction is clockwise.

      A return value of 0 indicates that the point lies exactly on the line segment. Note that an indicator value of 0 is rare and not useful for determining colinearity because of floating point rounding issues.

      If the point is colinear with the line segment, but not between the end points, then the value will be -1 if the point lies "beyond (x1,y1)" or 1 if the point lies "beyond (x2,y2)".

      Parameters:
      x1 - the X coordinate of the start point of the specified line segment
      y1 - the Y coordinate of the start point of the specified line segment
      x2 - the X coordinate of the end point of the specified line segment
      y2 - the Y coordinate of the end point of the specified line segment
      px - the X coordinate of the specified point to be compared with the specified line segment
      py - the Y coordinate of the specified point to be compared with the specified line segment
      Returns:
      an integer that indicates the position of the third specified coordinates with respect to the line segment formed by the first two specified coordinates.
      Since:
      1.2
    • relativeCCW

      public int relativeCCW(double px, double py)
      Returns an indicator of where the specified point (px,py) lies with respect to this line segment. See the method comments of relativeCCW(double, double, double, double, double, double) to interpret the return value.
      Parameters:
      px - the X coordinate of the specified point to be compared with this Line2D
      py - the Y coordinate of the specified point to be compared with this Line2D
      Returns:
      an integer that indicates the position of the specified coordinates with respect to this Line2D
      Since:
      1.2
      See Also:
    • ptLineDistSq

      public static double ptLineDistSq(double x1, double y1, double x2, double y2, double px, double py)
      Returns the square of the distance from a point to a line. The distance measured is the distance between the specified point and the closest point on the infinitely-extended line defined by the specified coordinates. If the specified point intersects the line, this method returns 0.0.
      Parameters:
      x1 - the X coordinate of the start point of the specified line
      y1 - the Y coordinate of the start point of the specified line
      x2 - the X coordinate of the end point of the specified line
      y2 - the Y coordinate of the end point of the specified line
      px - the X coordinate of the specified point being measured against the specified line
      py - the Y coordinate of the specified point being measured against the specified line
      Returns:
      a double value that is the square of the distance from the specified point to the specified line.
      Since:
      1.2
    • ptLineDist

      public static double ptLineDist(double x1, double y1, double x2, double y2, double px, double py)
      Returns the distance from a point to a line. The distance measured is the distance between the specified point and the closest point on the infinitely-extended line defined by the specified coordinates. If the specified point intersects the line, this method returns 0.0.
      Parameters:
      x1 - the X coordinate of the start point of the specified line
      y1 - the Y coordinate of the start point of the specified line
      x2 - the X coordinate of the end point of the specified line
      y2 - the Y coordinate of the end point of the specified line
      px - the X coordinate of the specified point being measured against the specified line
      py - the Y coordinate of the specified point being measured against the specified line
      Returns:
      a double value that is the distance from the specified point to the specified line.
      Since:
      1.2
    • ptLineDistSq

      public double ptLineDistSq(double px, double py)
      Returns the square of the distance from a point to this line. The distance measured is the distance between the specified point and the closest point on the infinitely-extended line defined by this Line2D. If the specified point intersects the line, this method returns 0.0.
      Parameters:
      px - the X coordinate of the specified point being measured against this line
      py - the Y coordinate of the specified point being measured against this line
      Returns:
      a double value that is the square of the distance from a specified point to the current line.
      Since:
      1.2
    • ptLineDistSq

      public double ptLineDistSq(Point2D pt)
      Returns the square of the distance from a specified Point2D to this line. The distance measured is the distance between the specified point and the closest point on the infinitely-extended line defined by this Line2D. If the specified point intersects the line, this method returns 0.0.
      Parameters:
      pt - the specified Point2D being measured against this line
      Returns:
      a double value that is the square of the distance from a specified Point2D to the current line.
      Since:
      1.2
    • ptLineDist

      public double ptLineDist(double px, double py)
      Returns the distance from a point to this line. The distance measured is the distance between the specified point and the closest point on the infinitely-extended line defined by this Line2D. If the specified point intersects the line, this method returns 0.0.
      Parameters:
      px - the X coordinate of the specified point being measured against this line
      py - the Y coordinate of the specified point being measured against this line
      Returns:
      a double value that is the distance from a specified point to the current line.
      Since:
      1.2
    • ptLineDist

      public double ptLineDist(Point2D pt)
      Returns the distance from a Point2D to this line. The distance measured is the distance between the specified point and the closest point on the infinitely-extended line defined by this Line2D. If the specified point intersects the line, this method returns 0.0.
      Parameters:
      pt - the specified Point2D being measured
      Returns:
      a double value that is the distance from a specified Point2D to the current line.
      Since:
      1.2
    • contains

      public boolean contains(double x, double y)
      Tests if a specified coordinate is inside the boundary of this Line2D. This method is required to implement the Shape interface, but in the case of Line2D objects it always returns false since a line contains no area.
      Parameters:
      x - the X coordinate of the specified point to be tested
      y - the Y coordinate of the specified point to be tested
      Returns:
      false because a Line2D contains no area.
      Since:
      1.2
    • contains

      public boolean contains(Point2D p)
      Tests if a given Point2D is inside the boundary of this Line2D. This method is required to implement the Shape interface, but in the case of Line2D objects it always returns false since a line contains no area.
      Parameters:
      p - the specified Point2D to be tested
      Returns:
      false because a Line2D contains no area.
      Since:
      1.2
    • contains

      public boolean contains(double x, double y, double w, double h)
      Tests if the interior of this Line2D entirely contains the specified set of rectangular coordinates. This method is required to implement the Shape interface, but in the case of Line2D objects it always returns false since a line contains no area.
      Parameters:
      x - the X coordinate of the upper-left corner of the specified rectangular area
      y - the Y coordinate of the upper-left corner of the specified rectangular area
      w - the width of the specified rectangular area
      h - the height of the specified rectangular area
      Returns:
      false because a Line2D contains no area.
      Since:
      1.2
    • contains

      public boolean contains(Rectangle2D r)
      Tests if the interior of this Line2D entirely contains the specified Rectangle2D. This method is required to implement the Shape interface, but in the case of Line2D objects it always returns false since a line contains no area.
      Parameters:
      r - the specified Rectangle2D to be tested
      Returns:
      false because a Line2D contains no area.
      Since:
      1.2
    • clone

      public Object clone()
      Creates a new object of the same class as this object.
      Overrides:
      clone in class Object
      Returns:
      a clone of this instance.
      Throws:
      OutOfMemoryError - if there is not enough memory.
      Since:
      1.2
      See Also: