Package lejos.robotics.geometry
Class Line2D
- java.lang.Object
-
- lejos.robotics.geometry.Line2D
-
- All Implemented Interfaces:
java.lang.Cloneable,Shape
- Direct Known Subclasses:
Line2D.Double,Line2D.Float
public abstract class Line2D extends java.lang.Object implements Shape, java.lang.Cloneable
An abstract class representing a line in two dimensional space- Author:
- Lawrie Griffiths
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classLine2D.DoubleA line in 2D space using float coordinatesstatic classLine2D.FloatA line in 2D space using float coordinates
-
Constructor Summary
Constructors Modifier Constructor Description protectedLine2D()This is an abstract class that cannot be instantiated: use Line2D.Float or Line2D.Double.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description java.lang.Objectclone()booleancontains(double x, double y)Test if the shape contains the point (x,y)booleancontains(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.booleancontains(Point2D p)Test if the shape contains the Point2Dbooleancontains(Rectangle2D r)Test if the shape contains the Rectangle2DRectangleInt32getBounds()Get the bounding Rectangle for the shapeabstract Point2DgetP1()Get the start point of the line as a Point2Dabstract Point2DgetP2()Get the end point of the line as a Point2Dabstract doublegetX1()Get the x coordinate of the start of the lineabstract doublegetX2()Get the x coordinate of the end of the lineabstract doublegetY1()Get the y coordinate of the start of the lineabstract doublegetY2()Get the y coordinate of the end of the linebooleanintersects(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.booleanintersects(Rectangle2D r)Test if the shape intersects the Rectangle2D rbooleanintersectsLine(double x1, double y1, double x2, double y2)Test if this line intersects a given linebooleanintersectsLine(Line2D l)Tests if this line intersects a given linestatic booleanlinesIntersect(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)Test if one line intersects another linedoubleptSegDist(double px, double py)Measures the shortest distance from the reference point to a point on this line 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(Point2D p)Measures the shortest distance from the reference point to a point on this 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.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(Point2D p)Measures the square of the shortest distance from the reference point to a point on this line segment.intrelativeCCW(double px, double py)Returns an indicator of where the specified point lies with respect to the line.static intrelativeCCW(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 lineintrelativeCCW(Point2D p)Returns an indicator of where the specified point lies with respect to the lineabstract voidsetLine(double x1, double y1, double x2, double y2)Sets the end points of the line using double coordinates.voidsetLine(Line2D line)Set the end points of a line to the same as a given linevoidsetLine(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 lejos.robotics.geometry.Shape
getBounds2D
-
-
-
-
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 pointy1- the y coordinate of the start pointx2- the x coordinate of the end pointy2- 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 pointp2- 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:ShapeTest if the shape contains the point (x,y)
-
contains
public boolean contains(Point2D p)
Description copied from interface:ShapeTest if the shape contains the Point2D
-
contains
public boolean contains(double x, double y, double w, double h)Description copied from interface:ShapeTest if the shape contains the rectangle with top left at (x,y), width w and height h.
-
contains
public boolean contains(Rectangle2D r)
Description copied from interface:ShapeTest if the shape contains the Rectangle2D
-
intersects
public boolean intersects(double x, double y, double w, double h)Description copied from interface:ShapeTest if the shape intersects the rectangle with top left at (x,y), width w and height h.- Specified by:
intersectsin interfaceShape- Parameters:
x- the x-coordinate of the top left point of the rectangley- the y-coordinate of the top left point of the rectanglew- the width of the rectangleh- 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 liney1- the y coordinate of the start of the given linex2- the x coordinate of the end of the given liney2- 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 liney1- the y coordinate of the start of the first linex2- the x coordinate of the end of the first liney2- the y coordinate of the end of the first linex3- the x coordinate of the start of the second liney3- the y coordinate of the start of the second linex4- the x coordinate of the end of the second liney4- the y coordinate of the end of the second line- Returns:
- true iff the lines intersect
-
getBounds
public RectangleInt32 getBounds()
Description copied from interface:ShapeGet the bounding Rectangle for the shape
-
clone
public java.lang.Object clone()
- Overrides:
clonein classjava.lang.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 liney1- the y coordinate of the start of the linex2- the x coordinate of the end of the liney2- the y coordinate of the end of the linepx- the x coordinate of the specified pointpy- 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 pointpy- 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:ShapeTest if the shape intersects the Rectangle2D r- Specified by:
intersectsin interfaceShape- Parameters:
r- the Recangle2D- Returns:
- true iff the shape intersects the Rectangle2D
-
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:
x1- the first x coordinate of the segmenty1- the first y coordinate of the segmentx2- the second x coordinate of the segmenty2- the second y coordinate of the segmentpx- the x coordinate of the pointpy- the y coordinate of the point- Returns:
- the square of the distance from the point to the segment
-
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:
x1- the first x coordinate of the segmenty1- the first y coordinate of the segmentx2- the second x coordinate of the segmenty2- the second y coordinate of the segmentpx- the x coordinate of the pointpy- the y coordinate of the point- Returns:
- the distance from the point to the segment
-
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:
px- the x coordinate of the pointpy- the y coordinate of the point- Returns:
- the square of the distance from the point to the segment
- See Also:
ptSegDistSq(double, double, double, double, double, double)
-
ptSegDistSq
public double ptSegDistSq(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:
p- the point- Returns:
- the square of the distance from the point to the segment
- Throws:
java.lang.NullPointerException- if p is null- See Also:
ptSegDistSq(double, double, double, double, double, double)
-
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:
px- the x coordinate of the pointpy- the y coordinate of the point- Returns:
- the distance from the point to the segment
- See Also:
ptSegDist(double, double, double, double, double, double)
-
ptSegDist
public double ptSegDist(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:
p- the point- Returns:
- the distance from the point to the segment
- Throws:
java.lang.NullPointerException- if p is null- See Also:
ptSegDist(double, double, double, double, double, double)
-
-