Package org.djutils.draw.line
Class LineSegment2d
- java.lang.Object
- 
- org.djutils.draw.line.LineSegment2d
 
- 
- All Implemented Interfaces:
- Serializable,- Drawable<Point2d>,- Drawable2d,- LineSegment<Point2d,Ray2d>,- Project<Point2d>
 
 public class LineSegment2d extends Object implements Drawable2d, LineSegment<Point2d,Ray2d> LineSegment2d is a line segment bound by 2 end points in 2D-space. A line segment stores the order in which it has been created, so the end points are known as 'start' and 'end'.Copyright (c) 2020-2021 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. 
 BSD-style license. See DJUTILS License.- Author:
- Alexander Verbraeck, Peter Knoppers
- See Also:
- Serialized Form
 
- 
- 
Constructor SummaryConstructors Constructor Description LineSegment2d(double startX, double startY, double endX, double endY)Construct a new LineSegment2d start four coordinates.LineSegment2d(double startX, double startY, Point2d end)Construct a new LineSegment2d start two coordinates and a Point2d.LineSegment2d(Point2d start, double endX, double endY)Construct a new LineSegment2d start a Point2d and two coordinates.LineSegment2d(Point2d start, Point2d end)Construct a new LineSegment2d start two Point2d objects.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description Point2dclosestPointOnSegment(Point2d point)Project a Point on this LineSegment.booleanequals(Object obj)Bounds2dgetBounds()Retrieve the bounding rectangle of the object.Point2dgetEndPoint()Get the end point of this LineSegment.doublegetLength()Get the length (distance from start point to end point) of this LineSegment.Ray2dgetLocationExtended(double position)Create a Ray on a specified point on this LineSegment.Iterator<? extends Point2d>getPoints()Retrieve, or generate all points that make up the object.Point2dgetStartPoint()Get the start point of this LineSegment.inthashCode()Point2dprojectOrthogonal(Point2d point)Project a point onto this object.Point2dprojectOrthogonalExtended(Point2d point)Project a point onto this object.doubleprojectOrthogonalFractional(Point2d point)Project a point onto this object.doubleprojectOrthogonalFractionalExtended(Point2d point)Project a point onto this object.intsize()Retrieve the number of points that make up the object.StringtoExcel()Convert this PolyLine to something that MS-Excel can plot.StringtoString()Produce a string describing the Drawable using default conversion for the (double) coordinate values.StringtoString(String doubleFormat, boolean doNotIncludeClassName)Produce a String describing the Drawable.- 
Methods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, wait
 - 
Methods inherited from interface org.djutils.draw.Drawable2dgetDimensions
 - 
Methods inherited from interface org.djutils.draw.line.LineSegmentgetLocation
 
- 
 
- 
- 
- 
Constructor Detail- 
LineSegment2dpublic LineSegment2d(double startX, double startY, double endX, double endY) throws DrawRuntimeExceptionConstruct a new LineSegment2d start four coordinates.- Parameters:
- startX- double; the x-coordinate of the start point
- startY- double; the y-coordinate of the start point
- endX- double; the x-coordinate of the end point
- endY- double; the y-coordinate of the end point
- Throws:
- DrawRuntimeException- when (startX,startY) is equals end (endX,endY)
 
 - 
LineSegment2dpublic LineSegment2d(Point2d start, double endX, double endY) throws NullPointerException, DrawRuntimeException Construct a new LineSegment2d start a Point2d and two coordinates.- Parameters:
- start- Point2d; the start point
- endX- double; the x-coordinate of the end point
- endY- double; the y-coordinate of the end point
- Throws:
- NullPointerException- when start is null
- DrawRuntimeException- when start has the exact coordinates endX, endY
 
 - 
LineSegment2dpublic LineSegment2d(double startX, double startY, Point2d end) throws NullPointerException, DrawRuntimeExceptionConstruct a new LineSegment2d start two coordinates and a Point2d.- Parameters:
- startX- double; the x-coordinate of the start point
- startY- double; the y-coordinate of the start point
- end- Point2d; the end point
- Throws:
- NullPointerException- when end is null
- DrawRuntimeException- when end has the exact coordinates startX, startY
 
 - 
LineSegment2dpublic LineSegment2d(Point2d start, Point2d end) throws NullPointerException, DrawRuntimeException Construct a new LineSegment2d start two Point2d objects.- Parameters:
- start- Point2d; the start point
- end- Point2d; the end point
- Throws:
- NullPointerException- when start is null
- DrawRuntimeException- when start has the exact coordinates endX, endY
 
 
- 
 - 
Method Detail- 
getStartPointpublic Point2d getStartPoint() Get the start point of this LineSegment.- Specified by:
- getStartPointin interface- LineSegment<Point2d,Ray2d>
- Returns:
- P; the start point of the LineSegment
 
 - 
getEndPointpublic Point2d getEndPoint() Get the end point of this LineSegment.- Specified by:
- getEndPointin interface- LineSegment<Point2d,Ray2d>
- Returns:
- P; the end point of the LineSegment
 
 - 
getLengthpublic double getLength() Get the length (distance from start point to end point) of this LineSegment.- Specified by:
- getLengthin interface- LineSegment<Point2d,Ray2d>
- Returns:
- double; (distance from start point to end point) of this LineSegment
 
 - 
getPointspublic Iterator<? extends Point2d> getPoints() Retrieve, or generate all points that make up the object.
 - 
sizepublic int size() Retrieve the number of points that make up the object.
 - 
getBoundspublic Bounds2d getBounds() Retrieve the bounding rectangle of the object.- Specified by:
- getBoundsin interface- Drawable2d
- Returns:
- Bounds2d; the bounding box of the object
 
 - 
getLocationExtendedpublic Ray2d getLocationExtended(double position) throws DrawRuntimeException Create a Ray on a specified point on this LineSegment.- Specified by:
- getLocationExtendedin interface- LineSegment<Point2d,Ray2d>
- Parameters:
- position- double; the distance from the start point of this LineSegment.
- Returns:
- R; a ray beginning at the specified position
- Throws:
- DrawRuntimeException- when position is NaN or infinite
 
 - 
closestPointOnSegmentpublic Point2d closestPointOnSegment(Point2d point) throws NullPointerException Project a Point on this LineSegment. If the the projected points lies outside the line segment, the nearest end point of the line segment is returned. Otherwise the returned point lies between the end points of the line segment.
 Adapted from example code provided by Paul Bourke.- Specified by:
- closestPointOnSegmentin interface- LineSegment<Point2d,Ray2d>
- Parameters:
- point- P; the point to project onto the segment
- Returns:
- P; either the start point, or the end point of the segment or a Point that lies somewhere in between those two.
- Throws:
- NullPointerException- when point is null
 
 - 
projectOrthogonalpublic Point2d projectOrthogonal(Point2d point) throws NullPointerException Project a point onto this object. For PolyLines, there may be multiple valid solutions. In that case the solution that lies on the closest segment is returned. If there is no valid solution on the closest segment, null is returned.- Specified by:
- projectOrthogonalin interface- Project<Point2d>
- Parameters:
- point- P; the point
- Returns:
- P; the projection of the point (may be null if no sensible projection is possible). If the result is not null; the result lies somewhere on this object.
- Throws:
- NullPointerException- when point is null;
 
 - 
projectOrthogonalExtendedpublic Point2d projectOrthogonalExtended(Point2d point) Project a point onto this object. For PolyLines, there may be multiple valid solutions. In that case the solution that lies on the closest segment is returned.- Specified by:
- projectOrthogonalExtendedin interface- Project<Point2d>
- Parameters:
- point- P; the point
- Returns:
- P; the projection of the point. This result cannot be null, but it may not lie on this object, but, in stead, lie on a line, or plane that extends this object
 
 - 
projectOrthogonalFractionalpublic double projectOrthogonalFractional(Point2d point) throws NullPointerException Project a point onto this object. For PolyLines, there may be multiple valid solutions. In that case the solution that lies on the closest segment is returned. If there is no valid solution on the closest segment, null is returned.- Specified by:
- projectOrthogonalFractionalin interface- Project<Point2d>
- Parameters:
- point- P; the point
- Returns:
- double; the fractional position of the projection of the point (may be NaN if no sensible projection is possible). If the result is not null; the result lies somewhere on this object.
- Throws:
- NullPointerException- when point is null;
 
 - 
projectOrthogonalFractionalExtendedpublic double projectOrthogonalFractionalExtended(Point2d point) throws NullPointerException Project a point onto this object. For PolyLines, there may be multiple valid solutions. In that case the solution that lies on the closest segment is returned.- Specified by:
- projectOrthogonalFractionalExtendedin interface- Project<Point2d>
- Parameters:
- point- P; the point
- Returns:
- double; the fractional position of the projection of the point. This result cannot be NaN, but it may be outside the range 0.0 .. 1.0.
- Throws:
- NullPointerException- when point is null;
 
 - 
toStringpublic String toString() Produce a string describing the Drawable using default conversion for the (double) coordinate values. Regrettably, it is not allowed to provide a default implementation here.
 - 
toStringpublic String toString(String doubleFormat, boolean doNotIncludeClassName) Produce a String describing the Drawable.- Specified by:
- toStringin interface- Drawable<Point2d>
- Parameters:
- doubleFormat- String; a format string (something like "%6.3f") which will be used to render every coordinate value)
- doNotIncludeClassName- boolean; if true; the output of toString is not prefixed by the class name. This is useful for concatenating the textual representation of lots of Drawables (e.g. an array, or a List).
- Returns:
- String; textual representation of the Drawable
 
 - 
toExcelpublic String toExcel() Convert this PolyLine to something that MS-Excel can plot.- Specified by:
- toExcelin interface- LineSegment<Point2d,Ray2d>
- Returns:
- String MS-excel XY, or XYZ plottable output
 
 
- 
 
-