Package org.djutils.draw.line
Class PolyLine3d
- java.lang.Object
-
- org.djutils.draw.line.PolyLine3d
-
- All Implemented Interfaces:
Serializable
,Drawable<Point3d,Space3d>
,Drawable3d
,PolyLine<PolyLine3d,Point3d,Space3d,OrientedPoint3d>
public class PolyLine3d extends Object implements Drawable3d, PolyLine<PolyLine3d,Point3d,Space3d,OrientedPoint3d>
Implementation of Line for 3D space.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 Summary
Constructors Constructor Description PolyLine3d(Iterator<Point3d> iterator)
Construct a new Line3d and initialize its length indexed line, bounds, centroid and length.PolyLine3d(List<Point3d> pointList)
Construct a new Line3d from a List<Point3d>.PolyLine3d(Point3d[] points)
Construct a new PolyLine3d from an array of Point3d.PolyLine3d(Point3d point1, Point3d point2, Point3d... otherPoints)
Construct a new PolyLine3d from an array of Point3d.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static PolyLine3d
concatenate(double tolerance, PolyLine3d... lines)
Concatenate several Line3d instances.static PolyLine3d
concatenate(double tolerance, PolyLine3d line1, PolyLine3d line2)
Concatenate two Line3d instances.static PolyLine3d
concatenate(PolyLine3d... lines)
Concatenate several Line3d instances.static PolyLine3d
createAndCleanLine3d(List<Point3d> pointList)
Create an Line3d, while filtering out repeating successive points.static PolyLine3d
createAndCleanLine3d(Point3d... points)
Create a new Line3d, filtering out repeating successive points.boolean
equals(Object obj)
PolyLine3d
extract(double start, double end)
Create a new L that covers a sub-section of this L.Point3d
get(int i)
Return one of the points of this line.Bounds3d
getBounds()
Retrieve the bounding box of the object.double
getLength()
Return the length of this line.OrientedPoint3d
getLocation(double position)
Get the location at a position on the line, with its direction.OrientedPoint3d
getLocationExtended(double position)
Get the location at a position on the line, with its direction.Iterator<Point3d>
getPoints()
Retrieve, or generate all points that make up the object.int
hashCode()
PolyLine3d
instantiate(List<Point3d> pointList)
Constructor that can be accessed as a method (used to implement default methods in this interface).double
lengthAtIndex(int index)
Access the internal lengthIndexedLine.PolyLine3d
noiseFilteredLine(double noiseLevel)
Construct a new Line3d that is equal to this line except for segments that are shorter than the noiseLevel.PolyLine2d
project()
Project the object onto the z=0 plane.int
size()
Retrieve the number of points that make up the object.String
toString()
PolyLine3d
truncate(double position)
Truncate this Line at the given length (less than the length of the line, and larger than zero) and return a new line.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.djutils.draw.line.PolyLine
extractFractional, find, getFirst, getLast, getLocationFraction, getLocationFraction, getLocationFractionExtended, reverse
-
-
-
-
Constructor Detail
-
PolyLine3d
public PolyLine3d(Point3d point1, Point3d point2, Point3d... otherPoints) throws NullPointerException, DrawRuntimeException
Construct a new PolyLine3d from an array of Point3d.- Parameters:
point1
- Point3d; starting point of the PolyLine3dpoint2
- Point3d; second point of the PolyLine3dotherPoints
- Point3d...; additional points of the PolyLine3d- Throws:
NullPointerException
- when iterator is nullDrawRuntimeException
- when the provided points do not constitute a valid line (too few points or identical adjacent points)
-
PolyLine3d
public PolyLine3d(Point3d[] points) throws NullPointerException, DrawRuntimeException
Construct a new PolyLine3d from an array of Point3d.- Parameters:
points
- Point3d[]; points of the PolyLine3d- Throws:
NullPointerException
- when iterator is nullDrawRuntimeException
- when the provided points do not constitute a valid line (too few points or identical adjacent points)
-
PolyLine3d
public PolyLine3d(Iterator<Point3d> iterator) throws NullPointerException, DrawException
Construct a new Line3d and initialize its length indexed line, bounds, centroid and length.- Parameters:
iterator
- Iterator<Point3d>; iterator that will provide all points that constitute the new Line3d- Throws:
NullPointerException
- when iterator is nullDrawException
- when the iterator provides too few points, or some adjacent identical points)
-
PolyLine3d
public PolyLine3d(List<Point3d> pointList) throws DrawRuntimeException
Construct a new Line3d from a List<Point3d>.- Parameters:
pointList
- List<Point3d>; the list of points to construct this Line3d from.- Throws:
DrawRuntimeException
- when the provided points do not constitute a valid line (too few points or identical adjacent points)
-
-
Method Detail
-
instantiate
public PolyLine3d instantiate(List<Point3d> pointList) throws NullPointerException, DrawRuntimeException
Constructor that can be accessed as a method (used to implement default methods in this interface).- Specified by:
instantiate
in interfacePolyLine<PolyLine3d,Point3d,Space3d,OrientedPoint3d>
- Parameters:
pointList
- List<P>; a list of points- Returns:
- L; the new line
- Throws:
NullPointerException
- when pointList is nullDrawRuntimeException
- when pointList has fewer than two points or contains successive duplicate points
-
size
public int size()
Retrieve the number of points that make up the object.
-
get
public final Point3d get(int i) throws IndexOutOfBoundsException
Return one of the points of this line.- Specified by:
get
in interfacePolyLine<PolyLine3d,Point3d,Space3d,OrientedPoint3d>
- Parameters:
i
- int; the index of the requested point- Returns:
- P; the point at the specified index
- Throws:
IndexOutOfBoundsException
- when index < 0 or index >= size
-
lengthAtIndex
public final double lengthAtIndex(int index)
Access the internal lengthIndexedLine. Return the cumulative length up to pointindex
of this line- Specified by:
lengthAtIndex
in interfacePolyLine<PolyLine3d,Point3d,Space3d,OrientedPoint3d>
- Parameters:
index
- int; the index- Returns:
- double; the cumulative length of this line up to point
index
-
getLength
public final double getLength()
Return the length of this line. This is NOT the number of points; it is the sum of the lengths of the segments.- Specified by:
getLength
in interfacePolyLine<PolyLine3d,Point3d,Space3d,OrientedPoint3d>
- Returns:
- double; the length of this line
-
getPoints
public Iterator<Point3d> getPoints()
Retrieve, or generate all points that make up the object.
-
getBounds
public Bounds3d getBounds()
Retrieve the bounding box of the object.- Specified by:
getBounds
in interfaceDrawable3d
- Returns:
- Bounds3d; the bounding box of the object
-
noiseFilteredLine
public final PolyLine3d noiseFilteredLine(double noiseLevel)
Construct a new Line3d that is equal to this line except for segments that are shorter than the noiseLevel. The result is guaranteed to start with the first point of this line and end with the last point of this line.- Parameters:
noiseLevel
- double; the minimum segment length that is not removed- Returns:
- Line3d; the filtered line
-
concatenate
public static PolyLine3d concatenate(PolyLine3d... lines) throws DrawException
Concatenate several Line3d instances.- Parameters:
lines
- PolyLine3d...; Line3d... one or more Line3d. The last point of the first <strong>must</strong> match the first of the second, etc.- Returns:
- Line3d
- Throws:
DrawException
- if zero lines are given, or when there is a gap between consecutive lines
-
concatenate
public static PolyLine3d concatenate(double tolerance, PolyLine3d line1, PolyLine3d line2) throws DrawException
Concatenate two Line3d instances. This method is separate for efficiency reasons.- Parameters:
tolerance
- double; the tolerance between the end point of a line and the first point of the next lineline1
- PolyLine3d; first lineline2
- PolyLine3d; second line- Returns:
- Line3d; the concatenation of the two lines
- Throws:
DrawException
- if zero lines are given, or when there is a gap between consecutive lines
-
concatenate
public static PolyLine3d concatenate(double tolerance, PolyLine3d... lines) throws DrawException
Concatenate several Line3d instances.- Parameters:
tolerance
- double; the tolerance between the end point of a line and the first point of the next linelines
- PolyLine3d...; Line3d... one or more Line3d. The last point of the first <strong>must</strong> match the first of the second, etc.- Returns:
- Line3d; the concatenation of the lines
- Throws:
DrawException
- if zero lines are given, or when there is a gap between consecutive lines
-
project
public PolyLine2d project() throws DrawRuntimeException
Project the object onto the z=0 plane.- Specified by:
project
in 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.
-
createAndCleanLine3d
public static PolyLine3d createAndCleanLine3d(Point3d... points) throws DrawException
Create a new Line3d, filtering out repeating successive points.- Parameters:
points
- Point3d...; the coordinates of the line as Point3d- Returns:
- the line
- Throws:
DrawException
- when number of points < 2
-
createAndCleanLine3d
public static PolyLine3d createAndCleanLine3d(List<Point3d> pointList) throws DrawException
Create an Line3d, while filtering out repeating successive points.- Parameters:
pointList
- List<Point3d>; list of the coordinates of the line as Point3d; any duplicate points in this list are removed (this method may modify the provided list)- Returns:
- Line3d; the line
- Throws:
DrawException
- when number of non-equal points < 2
-
getLocationExtended
public final OrientedPoint3d getLocationExtended(double position)
Get the location at a position on the line, with its direction. Position can be below 0 or more than the line length. In that case, the position will be extrapolated in the direction of the line at its start or end.- Specified by:
getLocationExtended
in interfacePolyLine<PolyLine3d,Point3d,Space3d,OrientedPoint3d>
- Parameters:
position
- double; the position on the line for which to calculate the point on, before, or after the line- Returns:
- OP; an oriented point
-
getLocation
public final OrientedPoint3d getLocation(double position) throws DrawException
Get the location at a position on the line, with its direction. Position should be between 0.0 and line length.- Specified by:
getLocation
in interfacePolyLine<PolyLine3d,Point3d,Space3d,OrientedPoint3d>
- Parameters:
position
- double; the position on the line for which to calculate the point on the line- Returns:
- OP; an oriented point
- Throws:
DrawException
- when position less than 0.0 or more than line length.
-
extract
public PolyLine3d extract(double start, double end) throws DrawException
Create a new L that covers a sub-section of this L.- Specified by:
extract
in interfacePolyLine<PolyLine3d,Point3d,Space3d,OrientedPoint3d>
- Parameters:
start
- double; length along this Line3d where the sub-section starts, valid range [0..end)end
- double; length along this Line3d where the sub-section ends, valid range (start..length (length is the length of this L)- Returns:
- L; the selected sub-section
- Throws:
DrawException
- when start >= end, or start < 0, or end > length
-
truncate
public PolyLine3d truncate(double position) throws DrawException
Truncate this Line at the given length (less than the length of the line, and larger than zero) and return a new line.- Specified by:
truncate
in interfacePolyLine<PolyLine3d,Point3d,Space3d,OrientedPoint3d>
- Parameters:
position
- double; the position along the line where to truncate the line- Returns:
- L; a new Line that follows this line, but ends at the position where line.getLength() == lengthSI
- Throws:
DrawException
- when position less than 0.0 or more than line length.
-
-