Index (Frames) | Index (No Frames) | Package | Package Tree | Tree
java.awt.geom

Class Line2D

java.lang.Object
|
+--java.awt.geom.Line2D

All Implemented Interfaces:

Shape, Cloneable


public abstract class Line2D

extends Object

implements Shape, Cloneable

Represents a directed line bewteen two points in (x,y) Cartesian space. Remember, on-screen graphics have increasing x from left-to-right, and increasing y from top-to-bottom. The storage is left to subclasses.

Since:Authors:

Constructor Summary

Line2D()

The default constructor.

Method Summary

java.lang.Objectclone()

Create a new line of the same run-time type with the same contents as this one.
booleancontains(double x, double y)

Test if a point is contained inside the line.
booleancontains(java.awt.geom.Point2D p)

Test if a point is contained inside the line.
booleancontains(double x, double y, double w, double h)

Tests if the line contains a rectangle.
booleancontains(java.awt.geom.Rectangle2D r)

Tests if the line contains a rectangle.
java.awt.RectanglegetBounds()

Gets a bounding box (not necessarily minimal) for this line.
java.awt.geom.Point2DgetP1()

Return the first point.
java.awt.geom.Point2DgetP2()

Return the second point.
java.awt.geom.PathIteratorgetPathIterator(final AffineTransform at)

Return a path iterator, possibly applying a transform on the result.
java.awt.geom.PathIteratorgetPathIterator(java.awt.geom.AffineTransform at, double flatness)

Return a flat path iterator, possibly applying a transform on the result.
doublegetX1()

Return the x coordinate of the first point.
doublegetX2()

Return the x coordinate of the second point.
doublegetY1()

Return the y coordinate of the first point.
doublegetY2()

Return the y coordinate of the second point.
booleanintersects(double x, double y, double w, double h)

Tests if this line intersects the interior of the specified rectangle.
booleanintersects(java.awt.geom.Rectangle2D r)

Tests if this line intersects the interior of the specified rectangle.
booleanintersectsLine(double x1, double y1, double x2, double y2)

Test if this line intersects the line given by (x1,y1)->(x2,y2).
booleanintersectsLine(java.awt.geom.Line2D l)

Test if this line intersects the given line.
static booleanlinesIntersect(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)

Test if the line segment (x1,y1)->(x2,y2) intersects the line segment (x3,y3)->(x4,y4).
static doubleptLineDist(double x1, double y1, double x2, double y2, double px, double py)

Measures the shortest distance from the reference point to a point on the infinite line extended from the segment.
doubleptLineDist(double px, double py)

Measures the shortest distance from the reference point to a point on the infinite line extended from this segment.
doubleptLineDist(java.awt.geom.Point2D p)

Measures the shortest distance from the reference point to a point on the infinite line extended from this segment.
static doubleptLineDistSq(double x1, double y1, double x2, double y2, double px, double py)

Measures the square of the shortest distance from the reference point to a point on the infinite line extended from the segment.
doubleptLineDistSq(double px, double py)

Measures the square of the shortest distance from the reference point to a point on the infinite line extended from this segment.
doubleptLineDistSq(java.awt.geom.Point2D p)

Measures the square of the shortest distance from the reference point to a point on the infinite line extended from this segment.
static doubleptSegDist(double x1, double y1, double x2, double y2, double px, double py)

Measures the shortest distance from the reference point to a point on the line segment.
doubleptSegDist(double px, double py)

Measures the shortest distance from the reference point to a point on this line segment.
doubleptSegDist(java.awt.geom.Point2D p)

Measures the shortest distance from the reference point to a point on this line segment.
static doubleptSegDistSq(double x1, double y1, double x2, double y2, double px, double py)

Measures the square of the shortest distance from the reference point to a point on the line segment.
doubleptSegDistSq(double px, double py)

Measures the square of the shortest distance from the reference point to a point on this line segment.
doubleptSegDistSq(java.awt.geom.Point2D p)

Measures the square of the shortest distance from the reference point to a point on this line segment.
static intrelativeCCW(double x1, double y1, double x2, double y2, double px, double py)

Computes the relative rotation direction needed to pivot the line about the first point in order to have the second point colinear with point p.
intrelativeCCW(double px, double py)

Computes the relative rotation direction needed to pivot this line about the first point in order to have the second point colinear with point p.
intrelativeCCW(java.awt.geom.Point2D p)

Computes the relative rotation direction needed to pivot this line about the first point in order to have the second point colinear with point p.
voidsetLine(double x1, double y1, double x2, double y2)

Set the coordinates of the line to the given coordinates.
voidsetLine(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2)

Set the coordinates to the given points.
voidsetLine(java.awt.geom.Line2D l)

Set the coordinates to those of the given line.

Constructor Details

Line2D

protected Line2D()

The default constructor.


Method Details

clone

public Object clone()

Create a new line of the same run-time type with the same contents as this one.

Since:Returns:

Throws:


contains

public boolean contains(double x, double y)

Test if a point is contained inside the line. Since a line has no area, this returns false.

Parameters:

Returns:


contains

public boolean contains(double x, double y, double w, double h)

Tests if the line contains a rectangle. Since lines have no area, this always returns false.

Parameters:

Returns:


contains

public boolean contains(java.awt.geom.Point2D p)

Test if a point is contained inside the line. Since a line has no area, this returns false.

Parameters:

Returns:


contains

public boolean contains(java.awt.geom.Rectangle2D r)

Tests if the line contains a rectangle. Since lines have no area, this always returns false.

Parameters:

Returns:


getBounds

public Rectangle getBounds()

Gets a bounding box (not necessarily minimal) for this line.

Returns:

See Also:


getP1

public Point2D getP1()

Return the first point.

Returns:


getP2

public Point2D getP2()

Return the second point.

Returns:


getPathIterator

public PathIterator getPathIterator(final AffineTransform at)

Return a path iterator, possibly applying a transform on the result. This iterator is not threadsafe.

Parameters:

Returns:


getPathIterator

public PathIterator getPathIterator(java.awt.geom.AffineTransform at, double flatness)

Return a flat path iterator, possibly applying a transform on the result. This iterator is not threadsafe.

Parameters:

Returns:

See Also:


getX1

public double getX1()

Return the x coordinate of the first point.

Returns:


getX2

public double getX2()

Return the x coordinate of the second point.

Returns:


getY1

public double getY1()

Return the y coordinate of the first point.

Returns:


getY2

public double getY2()

Return the y coordinate of the second point.

Returns:


intersects

public boolean intersects(double x, double y, double w, double h)

Tests if this line intersects the interior of the specified rectangle.

Parameters:

Returns:


intersects

public boolean intersects(java.awt.geom.Rectangle2D r)

Tests if this line intersects the interior of the specified rectangle.

Parameters:

Returns:

Throws:


intersectsLine

public boolean intersectsLine(double x1, double y1, double x2, double y2)

Test if this line intersects the line given by (x1,y1)->(x2,y2).

Parameters:

Returns:

See Also:


intersectsLine

public boolean intersectsLine(java.awt.geom.Line2D l)

Test if this line intersects the given line.

Parameters:

Returns:

Throws:

See Also:


linesIntersect

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

Test if the line segment (x1,y1)->(x2,y2) intersects the line segment (x3,y3)->(x4,y4).

Parameters:

Returns:


ptLineDist

public double ptLineDist(double px, double py)

Measures the shortest distance from the reference point to a point on the infinite line extended from this segment. If the point is on the segment, the result will be 0. If the segment is length 0, the distance is to the common endpoint.

Parameters:

Returns:

See Also:


ptLineDist

public static double ptLineDist(double x1, double y1, double x2, double y2, double px, double py)

Measures the shortest distance from the reference point to a point on the infinite line extended from the segment. If the point is on the segment, the result will be 0. If the segment is length 0, the distance is to the common endpoint.

Parameters:

Returns:

See Also:


ptLineDist

public double ptLineDist(java.awt.geom.Point2D p)

Measures the shortest distance from the reference point to a point on the infinite line extended from this segment. If the point is on the segment, the result will be 0. If the segment is length 0, the distance is to the common endpoint.

Parameters:

Returns:

Throws:

See Also:


ptLineDistSq

public double ptLineDistSq(double px, double py)

Measures the square of the shortest distance from the reference point to a point on the infinite line extended from this segment. If the point is on the segment, the result will be 0. If the segment is length 0, the distance is to the common endpoint.

Parameters:

Returns:

See Also:


ptLineDistSq

public static double ptLineDistSq(double x1, double y1, double x2, double y2, double px, double py)

Measures the square of the shortest distance from the reference point to a point on the infinite line extended from the segment. If the point is on the segment, the result will be 0. If the segment is length 0, the distance is to the common endpoint.

Parameters:

Returns:

See Also:


ptLineDistSq

public double ptLineDistSq(java.awt.geom.Point2D p)

Measures the square of the shortest distance from the reference point to a point on the infinite line extended from this segment. If the point is on the segment, the result will be 0. If the segment is length 0, the distance is to the common endpoint.

Parameters:

Returns:

Throws:

See Also:


ptSegDist

public double ptSegDist(double px, double py)

Measures the shortest distance from the reference point to a point on this line segment. If the point is on the segment, the result will be 0.

Parameters:

Returns:

See Also:


ptSegDist

public static double ptSegDist(double x1, double y1, double x2, double y2, double px, double py)

Measures the shortest distance from the reference point to a point on the line segment. If the point is on the segment, the result will be 0.

Parameters:

Returns:

See Also:


ptSegDist

public double ptSegDist(java.awt.geom.Point2D p)

Measures the shortest distance from the reference point to a point on this line segment. If the point is on the segment, the result will be 0.

Parameters:

Returns:

Throws:

See Also:


ptSegDistSq

public double ptSegDistSq(double px, double py)

Measures the square of the shortest distance from the reference point to a point on this line segment. If the point is on the segment, the result will be 0.

Parameters:

Returns:

See Also:


ptSegDistSq

public static double ptSegDistSq(double x1, double y1, double x2, double y2, double px, double py)

Measures the square of the shortest distance from the reference point to a point on the line segment. If the point is on the segment, the result will be 0.

Parameters:

Returns:

See Also:


ptSegDistSq

public double ptSegDistSq(java.awt.geom.Point2D p)

Measures the square of the shortest distance from the reference point to a point on this line segment. If the point is on the segment, the result will be 0.

Parameters:

Returns:

Throws:

See Also:


relativeCCW

public int relativeCCW(double px, double py)

Computes the relative rotation direction needed to pivot this line about the first point in order to have the second point colinear with point p. Because of floating point rounding, don't expect this to be a perfect measure of colinearity. The answer is 1 if the line has a shorter rotation in the direction of the positive X axis to the negative Y axis (counter-clockwise in the default Java coordinate system), or -1 if the shortest rotation is in the opposite direction (clockwise). If p is already colinear, the return value is -1 if it lies beyond the first point, 0 if it lies in the segment, or 1 if it lies beyond the second point. If the first and second point are coincident, this returns 0.

Parameters:

Returns:

See Also:


relativeCCW

public static int relativeCCW(double x1, double y1, double x2, double y2, double px, double py)

Computes the relative rotation direction needed to pivot the line about the first point in order to have the second point colinear with point p. Because of floating point rounding, don't expect this to be a perfect measure of colinearity. The answer is 1 if the line has a shorter rotation in the direction of the positive X axis to the negative Y axis (counter-clockwise in the default Java coordinate system), or -1 if the shortest rotation is in the opposite direction (clockwise). If p is already colinear, the return value is -1 if it lies beyond the first point, 0 if it lies in the segment, or 1 if it lies beyond the second point. If the first and second point are coincident, this returns 0.

Parameters:

Returns:


relativeCCW

public int relativeCCW(java.awt.geom.Point2D p)

Computes the relative rotation direction needed to pivot this line about the first point in order to have the second point colinear with point p. Because of floating point rounding, don't expect this to be a perfect measure of colinearity. The answer is 1 if the line has a shorter rotation in the direction of the positive X axis to the negative Y axis (counter-clockwise in the default Java coordinate system), or -1 if the shortest rotation is in the opposite direction (clockwise). If p is already colinear, the return value is -1 if it lies beyond the first point, 0 if it lies in the segment, or 1 if it lies beyond the second point. If the first and second point are coincident, this returns 0.

Parameters:

Returns:

Throws:

See Also:


setLine

public void setLine(double x1, double y1, double x2, double y2)

Set the coordinates of the line to the given coordinates. Loss of precision may occur due to rounding issues.

Parameters:


setLine

public void setLine(java.awt.geom.Line2D l)

Set the coordinates to those of the given line.

Parameters:

Throws:


setLine

public void setLine(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2)

Set the coordinates to the given points.

Parameters:

Throws: