Package org.djutils.draw.line
Class LineSegment3d
- java.lang.Object
-
- org.djutils.draw.line.LineSegment3d
-
- All Implemented Interfaces:
Serializable,Drawable<Point3d>,Drawable3d,LineSegment<Point3d,Ray3d>,Project<Point3d>
public class LineSegment3d extends Object implements Drawable3d, LineSegment<Point3d,Ray3d>
LineSegment3d is a line segment bound by 2 end points in 3D-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-2023 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 Summary
Constructors Constructor Description LineSegment3d(double startX, double startY, double startZ, double endX, double endY, double endZ)Construct a new LineSegment3d start six coordinates.LineSegment3d(double startX, double startY, double startZ, Point3d end)Construct a new LineSegment3d start three coordinates and a Point3d.LineSegment3d(Point3d start, double endX, double endY, double endZ)Construct a new LineSegment3d start a Point3d and three coordinates.LineSegment3d(Point3d start, Point3d end)Construct a new LineSegment3d start two Point3d objects.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Point3dclosestPointOnSegment(Point3d point)Project a Point on this LineSegment.booleanequals(Object obj)Bounds3dgetBounds()Retrieve the bounding box of the object.Point3dgetEndPoint()Get the end point of this LineSegment.doublegetLength()Get the length (distance from start point to end point) of this LineSegment.Ray3dgetLocationExtended(double position)Create a Ray on a specified point on this LineSegment.Iterator<? extends Point3d>getPoints()Retrieve, or generate all points that make up the object.Point3dgetStartPoint()Get the start point of this LineSegment.inthashCode()LineSegment2dproject()Project the object onto the z=0 plane.Point3dprojectOrthogonal(Point3d point)Project a point onto this object.Point3dprojectOrthogonalExtended(Point3d point)Project a point onto this object.doubleprojectOrthogonalFractional(Point3d point)Project a point onto this object.doubleprojectOrthogonalFractionalExtended(Point3d point)Project a point onto this object.LineSegment3dreverse()Construct a new LineSegment with the points of this LineSegment in reverse order.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.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.djutils.draw.Drawable
getPointList, toString, toString
-
Methods inherited from interface org.djutils.draw.Drawable3d
getDimensions
-
Methods inherited from interface org.djutils.draw.line.LineSegment
getLocation
-
-
-
-
Field Detail
-
startX
public final double startX
The start x-coordinate.
-
startY
public final double startY
The start y-coordinate.
-
startZ
public final double startZ
The start z-coordinate.
-
endX
public final double endX
The end x-coordinate.
-
endY
public final double endY
The end y-coordinate.
-
endZ
public final double endZ
The end z-coordinate.
-
-
Constructor Detail
-
LineSegment3d
public LineSegment3d(double startX, double startY, double startZ, double endX, double endY, double endZ) throws DrawRuntimeExceptionConstruct a new LineSegment3d start six coordinates.- Parameters:
startX- double; the x-coordinate of the start pointstartY- double; the y-coordinate of the start pointstartZ- double; the z-coordinate of the start pointendX- double; the x-coordinate of the end pointendY- double; the y-coordinate of the end pointendZ- double; the z-coordinate of the end point- Throws:
DrawRuntimeException- when (startX,startY) is equals end (endX,endY)
-
LineSegment3d
public LineSegment3d(Point3d start, double endX, double endY, double endZ) throws NullPointerException, DrawRuntimeException
Construct a new LineSegment3d start a Point3d and three coordinates.- Parameters:
start- Point3d; the start pointendX- double; the x-coordinate of the end pointendY- double; the y-coordinate of the end pointendZ- double; the z-coordinate of the end point- Throws:
NullPointerException- when start is nullDrawRuntimeException- when start has the exact coordinates endX, endY
-
LineSegment3d
public LineSegment3d(double startX, double startY, double startZ, Point3d end) throws NullPointerException, DrawRuntimeExceptionConstruct a new LineSegment3d start three coordinates and a Point3d.- Parameters:
startX- double; the x-coordinate of the start pointstartY- double; the y-coordinate of the start pointstartZ- double; the z-coordinate of the start pointend- Point3d; the end point- Throws:
NullPointerException- when end is nullDrawRuntimeException- when end has the exact coordinates startX, startY
-
LineSegment3d
public LineSegment3d(Point3d start, Point3d end) throws NullPointerException, DrawRuntimeException
Construct a new LineSegment3d start two Point3d objects.- Parameters:
start- Point3d; the start pointend- Point3d; the end point- Throws:
NullPointerException- when start is nullDrawRuntimeException- when start has the exact coordinates endX, endY
-
-
Method Detail
-
getStartPoint
public Point3d getStartPoint()
Get the start point of this LineSegment.- Specified by:
getStartPointin interfaceLineSegment<Point3d,Ray3d>- Returns:
- P; the start point of the LineSegment
-
getEndPoint
public Point3d getEndPoint()
Get the end point of this LineSegment.- Specified by:
getEndPointin interfaceLineSegment<Point3d,Ray3d>- Returns:
- P; the end point of the LineSegment
-
getLength
public double getLength()
Get the length (distance from start point to end point) of this LineSegment.- Specified by:
getLengthin interfaceLineSegment<Point3d,Ray3d>- Returns:
- double; (distance from start point to end point) of this LineSegment
-
getPoints
public Iterator<? extends Point3d> getPoints()
Retrieve, or generate all points that make up the object.
-
size
public int size()
Retrieve the number of points that make up the object.
-
getBounds
public Bounds3d getBounds()
Retrieve the bounding box of the object.- Specified by:
getBoundsin interfaceDrawable3d- Returns:
- Bounds3d; the bounding box of the object
-
project
public LineSegment2d project() throws DrawRuntimeException
Project the object onto the z=0 plane.- Specified by:
projectin interfaceDrawable3d- Returns:
- Drawable2d; the projected object
- Throws:
DrawRuntimeException- when projecting onto the z=0 plane results in an invalid object. E.g. a Line3d that consists of points that all have the exact same x and y coordinates cannot be a line after projecting on the z=0 plane.
-
getLocationExtended
public Ray3d getLocationExtended(double position) throws DrawRuntimeException
Create a Ray on a specified point on this LineSegment.- Specified by:
getLocationExtendedin interfaceLineSegment<Point3d,Ray3d>- 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
-
closestPointOnSegment
public Point3d closestPointOnSegment(Point3d point)
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 interfaceLineSegment<Point3d,Ray3d>- 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.
-
reverse
public LineSegment3d reverse()
Construct a new LineSegment with the points of this LineSegment in reverse order.- Specified by:
reversein interfaceLineSegment<Point3d,Ray3d>- Returns:
- LineSegment; the new LineSegment
-
projectOrthogonal
public Point3d projectOrthogonal(Point3d 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 interfaceProject<Point3d>- 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;
-
projectOrthogonalExtended
public Point3d projectOrthogonalExtended(Point3d 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:
projectOrthogonalExtendedin interfaceProject<Point3d>- 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
- Throws:
NullPointerException- when point is null;
-
projectOrthogonalFractional
public double projectOrthogonalFractional(Point3d 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 interfaceProject<Point3d>- 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;
-
projectOrthogonalFractionalExtended
public double projectOrthogonalFractionalExtended(Point3d 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 interfaceProject<Point3d>- 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;
-
toString
public 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.
-
toString
public String toString(String doubleFormat, boolean doNotIncludeClassName)
Produce a String describing the Drawable.- Specified by:
toStringin interfaceDrawable<Point3d>- 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
-
toExcel
public String toExcel()
Convert this PolyLine to something that MS-Excel can plot.- Specified by:
toExcelin interfaceLineSegment<Point3d,Ray3d>- Returns:
- String MS-excel XY, or XYZ plottable output
-
-