Package org.djutils.draw.line
Class LineSegment3d
java.lang.Object
org.djutils.draw.line.LineSegment3d
- All Implemented Interfaces:
Serializable,Iterable<Point3d>,Drawable<Point3d>,Drawable3d,LineSegment<Point3d,,DirectedPoint3d> Project<Point3d>
public class LineSegment3d
extends Object
implements Drawable3d, LineSegment<Point3d,DirectedPoint3d>
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-2025 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, Wouter Schakel
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionLineSegment3d(double startX, double startY, double startZ, double endX, double endY, double endZ) Construct a new LineSegment3d from six coordinates.LineSegment3d(double startX, double startY, double startZ, Point3d end) Construct a new LineSegment3d from three coordinates and a Point3d.LineSegment3d(Point3d start, double endX, double endY, double endZ) Construct a new LineSegment3d from a Point3d and three coordinates.LineSegment3d(Point3d start, Point3d end) Construct a new LineSegment3d from two Point3d objects. -
Method Summary
Modifier and TypeMethodDescriptionclosestPointOnSegment(Point3d point) Project a Point on this LineSegment.booleanRetrieve the bounding box of the object in absolute coordinates.Get the end point of this LineSegment.doubleGet the length (distance from start point to end point) of this LineSegment.getLocationExtended(double position) Create a DirectedPoint at the specified position along this LineSegment.Get the start point of this LineSegment.inthashCode()iterator()project()Project the object onto the z=0 plane.projectOrthogonal(Point3d point) Project a point onto this object.projectOrthogonalExtended(Point3d point) Project a point onto this object.doubleProject a point onto this object.doubleProject a point onto this object.reverse()Construct a new LineSegment with the points of this LineSegment in reverse order.intsize()Retrieve the number of points that make up the object.toString()Produce a string describing the Drawable using default conversion for the (double) coordinate values.Produce a String describing the Drawable.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.djutils.draw.Drawable
getPointList, toString, toStringMethods inherited from interface org.djutils.draw.Drawable3d
getDimensionsMethods inherited from interface java.lang.Iterable
forEach, spliteratorMethods inherited from interface org.djutils.draw.line.LineSegment
getLocation
-
Field Details
-
startX
public final double startXThe start x-coordinate. -
startY
public final double startYThe start y-coordinate. -
startZ
public final double startZThe start z-coordinate. -
endX
public final double endXThe end x-coordinate. -
endY
public final double endYThe end y-coordinate. -
endZ
public final double endZThe end z-coordinate.
-
-
Constructor Details
-
LineSegment3d
public LineSegment3d(double startX, double startY, double startZ, double endX, double endY, double endZ) Construct a new LineSegment3d from six coordinates.- Parameters:
startX- the x-coordinate of the start pointstartY- the y-coordinate of the start pointstartZ- the z-coordinate of the start pointendX- the x-coordinate of the end pointendY- the y-coordinate of the end pointendZ- the z-coordinate of the end point- Throws:
IllegalArgumentException- when(startX,startY,startZ)is equal to(endX,endY,endZ)
-
LineSegment3d
Construct a new LineSegment3d from a Point3d and three coordinates.- Parameters:
start- the start pointendX- the x-coordinate of the end pointendY- the y-coordinate of the end pointendZ- the z-coordinate of the end point- Throws:
NullPointerException- whenstartisnullIllegalArgumentException- whenstarthas the exact coordinates(endX,endY,endZ)
-
LineSegment3d
Construct a new LineSegment3d from three coordinates and a Point3d.- Parameters:
startX- the x-coordinate of the start pointstartY- the y-coordinate of the start pointstartZ- the z-coordinate of the start pointend- the end point- Throws:
NullPointerException- whenendisnullIllegalArgumentException- whenendhas the exact coordinates(startX,startY,startZ
-
LineSegment3d
Construct a new LineSegment3d from two Point3d objects.- Parameters:
start- the start pointend- the end point- Throws:
NullPointerException- whenstart, orendisnullIllegalArgumentException- whenstarthas the same coordinates asend
-
-
Method Details
-
getStartPoint
Description copied from interface:LineSegmentGet the start point of this LineSegment.- Specified by:
getStartPointin interfaceLineSegment<Point3d,DirectedPoint3d> - Returns:
- the start point of this LineSegment
-
getEndPoint
Description copied from interface:LineSegmentGet the end point of this LineSegment.- Specified by:
getEndPointin interfaceLineSegment<Point3d,DirectedPoint3d> - Returns:
- the end point of this LineSegment
-
getLength
public double getLength()Description copied from interface:LineSegmentGet the length (distance from start point to end point) of this LineSegment.- Specified by:
getLengthin interfaceLineSegment<Point3d,DirectedPoint3d> - Returns:
- (distance from start point to end point) of this LineSegment
-
iterator
-
size
public int size()Description copied from interface:DrawableRetrieve the number of points that make up the object. -
getAbsoluteBounds
Description copied from interface:Drawable3dRetrieve the bounding box of the object in absolute coordinates.- Specified by:
getAbsoluteBoundsin interfaceDrawable3d- Returns:
- the bounding box of the object in absolute coordinates
-
project
Description copied from interface:Drawable3dProject the object onto the z=0 plane.- Specified by:
projectin interfaceDrawable3d- Returns:
- the projected object
- Throws:
InvalidProjectionException- when projecting onto thez=0plane results in an invalid object. E.g. a Line3d that consists of points that all have the exact samexandycoordinates cannot be a line after projecting on thez=0plane.
-
getLocationExtended
Description copied from interface:LineSegmentCreate a DirectedPoint at the specified position along this LineSegment.- Specified by:
getLocationExtendedin interfaceLineSegment<Point3d,DirectedPoint3d> - Parameters:
position- the distance from the start point of this LineSegment.- Returns:
- a DirectedPoint at the specified position
- Throws:
IllegalArgumentException- whenpositionisinfinite
-
closestPointOnSegment
Description copied from interface:LineSegmentProject 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,DirectedPoint3d> - Parameters:
point- the point to project onto this segment- Returns:
- either the start point, or the end point of this segment or a Point that lies somewhere in between those two.
-
reverse
Description copied from interface:LineSegmentConstruct a new LineSegment with the points of this LineSegment in reverse order.- Specified by:
reversein interfaceLineSegment<Point3d,DirectedPoint3d> - Returns:
- the new LineSegment
-
projectOrthogonal
Description copied from interface:ProjectProject a point onto this object. For PolyLines and Polygons, 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,nullis returned.- Specified by:
projectOrthogonalin interfaceProject<Point3d>- Parameters:
point- the point- Returns:
- 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.
-
projectOrthogonalExtended
Description copied from interface:ProjectProject a point onto this object. For PolyLines and Polygons, 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- the point- Returns:
- 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
-
projectOrthogonalFractional
Description copied from interface:ProjectProject a point onto this object. For PolyLines and Polygons, 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,NaNis returned.- Specified by:
projectOrthogonalFractionalin interfaceProject<Point3d>- Parameters:
point- the point- Returns:
- the fractional position of the projection of the point (may be
NaNif no sensible projection is possible). If the result is notNaN; the result lies somewhere on this object.
-
projectOrthogonalFractionalExtended
Description copied from interface:ProjectProject a point onto this object. For PolyLines and Polygons, 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- the point- Returns:
- 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.
-
toString
Description copied from interface:DrawableProduce 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
Description copied from interface:DrawableProduce a String describing the Drawable.- Specified by:
toStringin interfaceDrawable<Point3d>- Parameters:
doubleFormat- a format string (something like "%6.3f") which will be used to render every coordinate value)doNotIncludeClassName- iftrue; the output oftoStringis 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:
- textual representation of the Drawable
-
hashCode
public int hashCode() -
equals
-