Class OtsLine2d
- All Implemented Interfaces:
Iterable<Point2d>,Locatable,Drawable<Point2d>,Drawable2d,PolyLine<PolyLine2d,,Point2d, Ray2d, DirectedPoint2d, LineSegment2d> Project<Point2d>
- Direct Known Subclasses:
DirectionalPolyLine
Copyright (c) 2013-2026 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.
- Author:
- Alexander Verbraeck, Peter Knoppers, Guus Tamminga, Wouter Schakel
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.djutils.draw.line.PolyLine
PolyLine.TransitionFunction -
Field Summary
Fields inherited from interface org.djutils.draw.line.PolyLine
DEFAULT_CIRCLE_PRECISION, DEFAULT_OFFSET_FILTER_RATIO, DEFAULT_OFFSET_MAXIMUM_FILTER_VALUE, DEFAULT_OFFSET_MINIMUM_FILTER_VALUE, DEFAULT_OFFSET_PRECISION, NO_FILTER -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic OtsLine2dconcatenate(double toleranceSI, OtsLine2d... lines) Concatenate several OtsLine2d instances.static OtsLine2dconcatenate(double toleranceSI, OtsLine2d line1, OtsLine2d line2) Concatenate two OtsLine2d instances.static OtsLine2dconcatenate(OtsLine2d... lines) Concatenate several OtsLine2d instances.extract(double start, double end) Create a new line that covers a sub-section of this line.extract(org.djunits.value.vdouble.scalar.Length start, org.djunits.value.vdouble.scalar.Length end) Create a new line that covers a sub-section of this line.extractFractional(double start, double end) Create a new line covering the indicated fraction of this line.getLocation(org.djunits.value.vdouble.scalar.Length position) Get the location at a position on the line, with its direction.getLocationExtended(org.djunits.value.vdouble.scalar.Length position) Get the location at a position on the line, with its direction.Bounds<?,?> org.djunits.value.vdouble.scalar.LengthReturn the length of this line.offsetLine(double offset) Construct parallel line.offsetLine(double[] relativeFractions, double[] offsets) Create a line at linearly varying offset from this line.offsetLine(double offsetAtStart, double offsetAtEnd) Create a line at linearly varying offset from this line.doubleprojectFractionalAt(org.djunits.value.vdouble.scalar.Direction start, org.djunits.value.vdouble.scalar.Direction end, double x, double y, FractionalProjectionHelper.FractionalFallback fallback) Returns the fractional projection of a point to a line.doubleprojectOrthogonalSnapAt(double x, double y) Orthogonally project a point onto this polyline.doubleprojectOrthogonalSnapAt(double x, double y, boolean clampToDomain) Orthogonally project a point onto this polyline.Optional<org.djunits.value.vdouble.scalar.Length>radiusAtFraction(double fraction) Returns the projected directional radius of the line at a given fraction.Optional<org.djunits.value.vdouble.scalar.Length>radiusAtVertex(int index) Calculates the directional radius at a vertex.reverse()Returns a reversed instance of this line.truncate(double lengthSI) Truncate line at the given length in range (0..length).doublevertexFraction(int index) Returns the length fraction at the vertex.Methods inherited from class org.djutils.draw.line.PolyLine2d
closestPointOnPolyLine, concatenate, concatenate, concatenate, equals, get, getAbsoluteBounds, getLength, getLocation, getLocationExtended, getSegment, getX, getY, hashCode, instantiate, iterator, iteratorToList, lengthAtIndex, makeArray, noiseFilteredLine, offsetLine, offsetLine, offsetLine, projectOrthogonal, projectOrthogonalExtended, projectOrthogonalFractional, projectOrthogonalFractionalExtended, projectRay, size, toPath2D, toString, toString, transitionLineMethods 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.Drawable2d
getDimensionsMethods inherited from interface java.lang.Iterable
forEach, spliteratorMethods inherited from interface org.djutils.draw.line.PolyLine
filterNearDuplicates, find, getFirst, getLast, getLocationFraction, getLocationFraction, getLocationFractionExtended, instantiate
-
Constructor Details
-
OtsLine2d
Constructor from points.- Parameters:
points- array of points
-
OtsLine2d
Constructor based on 2d line.- Parameters:
line2d- 2d line
-
OtsLine2d
Constructor based on point iterator.- Parameters:
line2d- point iterator
-
OtsLine2d
- Parameters:
pointList- list of points
-
-
Method Details
-
offsetLine
Construct parallel line.- Specified by:
offsetLinein interfacePolyLine<PolyLine2d,Point2d, Ray2d, DirectedPoint2d, LineSegment2d> - Parameters:
offset- offset distance from the reference line; positive is LEFT, negative is RIGHT- Returns:
- the line that has the specified offset from this reference line
-
offsetLine
Create a line at linearly varying offset from this line. The offset may change linearly from its initial value at the start of the reference line to its final offset value at the end of the reference line.- Specified by:
offsetLinein interfacePolyLine<PolyLine2d,Point2d, Ray2d, DirectedPoint2d, LineSegment2d> - Parameters:
offsetAtStart- offset at the start of the reference line (positive value is Left, negative value is Right)offsetAtEnd- offset at the end of the reference line (positive value is Left, negative value is Right)- Returns:
- line with linear offset
-
offsetLine
Create a line at linearly varying offset from this line. The offset may change linearly from its initial value at the start of the reference line via a number of intermediate offsets at intermediate positions to its final offset value at the end of the reference line.- Parameters:
relativeFractions- positional fractions for which the offsets have to be generatedoffsets- offsets at the relative positions (positive value is Left, negative value is Right)- Returns:
- line with profiled offset
-
concatenate
Concatenate several OtsLine2d instances.- Parameters:
lines- OtsLine2d... one or more OtsLine2d. The last point of the first <strong>must</strong> match the first of the second, etc.- Returns:
- concatenated line
-
concatenate
Concatenate two OtsLine2d instances. This method is separate for efficiency reasons.- Parameters:
toleranceSI- the tolerance between the end point of a line and the first point of the next lineline1- first lineline2- second line- Returns:
- concatenated line
-
concatenate
Concatenate several OtsLine2d instances.- Parameters:
toleranceSI- the tolerance between the end point of a line and the first point of the next linelines- OtsLine2d... one or more OtsLine2d; the last point of the first must match the first of the second, etc.- Returns:
- concatenated line
-
reverse
Returns a reversed instance of this line.- Specified by:
reversein interfacePolyLine<PolyLine2d,Point2d, Ray2d, DirectedPoint2d, LineSegment2d> - Returns:
- reversed line
-
extractFractional
Create a new line covering the indicated fraction of this line.- Specified by:
extractFractionalin interfacePolyLine<PolyLine2d,Point2d, Ray2d, DirectedPoint2d, LineSegment2d> - Parameters:
start- starting point, valid range [0..end)end- ending point, valid range (start..1]- Returns:
- extracted line
-
extract
public OtsLine2d extract(org.djunits.value.vdouble.scalar.Length start, org.djunits.value.vdouble.scalar.Length end) Create a new line that covers a sub-section of this line.- Parameters:
start- the length along this OtsLine2d where the sub-section starts, valid range [0..end)end- length along this OtsLine2d where the sub-section ends, valid range (start..length (length is the length of this line)- Returns:
- extracted line
-
extract
Create a new line that covers a sub-section of this line.- Specified by:
extractin interfacePolyLine<PolyLine2d,Point2d, Ray2d, DirectedPoint2d, LineSegment2d> - Overrides:
extractin classPolyLine2d- Parameters:
start- length along this line where the sub-section starts, valid range [0..end)end- length along this line where the sub-section ends, valid range (start..length] (length is the length of this line)- Returns:
- extracted line
-
getTypedLength
public org.djunits.value.vdouble.scalar.Length getTypedLength()Return the length of this line.- Returns:
- length of the line
-
getLocationExtended
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.- Parameters:
position- the position on the line for which to calculate the point on, before, of after the line- Returns:
- a directed point
-
getLocation
Get the location at a position on the line, with its direction. Position should be in [0..length].- Parameters:
position- the position on the line for which to calculate the point on the line- Returns:
- a directed point
-
truncate
Truncate line at the given length in range (0..length).- Specified by:
truncatein interfacePolyLine<PolyLine2d,Point2d, Ray2d, DirectedPoint2d, LineSegment2d> - Overrides:
truncatein classPolyLine2d- Parameters:
lengthSI- the location where to truncate the line- Returns:
- truncated line
-
projectOrthogonalSnapAt
public double projectOrthogonalSnapAt(double x, double y) Orthogonally project a point onto this polyline. If the perpendicular foot on the closest segment falls outside that segment, this method snaps to the nearest vertex of that segment. The result is returned as a fraction along the entire polyline. The returned fraction is clamped to [0..1].- Parameters:
x- x-coordinate of the point to projecty- y-coordinate of the point to project- Returns:
- fraction along the line in [0..1]
-
projectOrthogonalSnapAt
public double projectOrthogonalSnapAt(double x, double y, boolean clampToDomain) Orthogonally project a point onto this polyline. If the perpendicular foot on the closest segment falls outside that segment, this method snaps to the nearest vertex of that segment. The result is returned as a fraction along the entire polyline.If
clampToDomainistrue, the returned fraction is clamped to [0..1]. Iffalse, the fraction may be negative (before the start of the line) or larger than 1 (beyond the end of the line) when the closest point is the first or last vertex, respectively.- Parameters:
x- x-coordinate of the point to projecty- y-coordinate of the point to projectclampToDomain- whether to clamp the resulting fraction to [0..1]- Returns:
- fraction along the line; in [0..1] when
clampToDomainis true; otherwise possibly <0 or >1
-
projectFractionalAt
public double projectFractionalAt(org.djunits.value.vdouble.scalar.Direction start, org.djunits.value.vdouble.scalar.Direction end, double x, double y, FractionalProjectionHelper.FractionalFallback fallback) Returns the fractional projection of a point to a line. The projection works by taking slices in space per line segment as shown below. A point is always projected to the nearest segment, but not necessarily to the closest point on that segment. The slices in space are analogous to a Voronoi diagram, but for the line segments instead of points. If fractional projection fails, a fallback projection is returned.The point 'A' is projected to point 'B' on the 3rd segment of line 'C-D'. The line from 'A' to 'B' extends towards point 'E', which is the intersection of lines 'E-F' and 'E-G'. Line 'E-F' cuts the first bend of the 3rd segment (at point 'H') in half, while the line 'E-G' cuts the second bend of the 3rd segment (at point 'I') in half.
____________________________ G . . | | . . . | . . . . helper lines | . . . | _.._.._ projection line | I. . . |____________________________| _.'._ . L F. _.' . '-. . .. B _.' . '-. . . _.\ . . D . . _.' : . . J . . _.' \ . . .. . _.' : . M . . ..-' \ . . . /H. A . . . / . . C _________/ . . . . . . K . . . . . . . . . . . . N . . . . . . . . . . . . . . . . . .E . . . . . .Fractional projection may fail in three cases.- Numerical difficulties at slight bend, orthogonal projection returns the correct point.
- Fractional projection is possible only to segments that aren't the nearest segment(s).
- Fractional projection is possible for no segment.
- Parameters:
start- direction in first pointend- direction in last pointx- x-coordinate of point to projecty- y-coordinate of point to projectfallback- fallback method for when fractional projection fails- Returns:
- fractional position along this line of the fractional projection on that line of a point
-
radiusAtFraction
public Optional<org.djunits.value.vdouble.scalar.Length> radiusAtFraction(double fraction) throws IllegalArgumentException Returns the projected directional radius of the line at a given fraction. Negative values reflect right-hand curvature in the design-line direction. The radius is taken as the minimum of the radii at the vertices before and after the given fraction. The radius at a vertex is calculated as the radius of a circle that is equidistant from both edges connected to the vertex. The circle center is on a line perpendicular to the shortest edge, crossing through the middle of the shortest edge. This method ignores Z components.- Parameters:
fraction- fraction along the line, between 0.0 and 1.0 (both inclusive)- Returns:
- radius; the local radius; empty if there is no radius as two segments have the same direction
- Throws:
IllegalArgumentException- fraction out of bounds
-
radiusAtVertex
public Optional<org.djunits.value.vdouble.scalar.Length> radiusAtVertex(int index) throws IndexOutOfBoundsException Calculates the directional radius at a vertex. Negative values reflect right-hand curvature in the design-line direction. The radius at a vertex is calculated as the radius of a circle that is equidistant from both edges connected to the vertex. The circle center is on a line perpendicular to the shortest edge, crossing through the middle of the shortest edge. This function ignores Z components.- Parameters:
index- index of the vertex in range [1 ... size() - 2]- Returns:
- radius at the vertex, empty if there is no radius as two segments have the same direction
- Throws:
IndexOutOfBoundsException- if the index is out of bounds
-
vertexFraction
Returns the length fraction at the vertex.- Parameters:
index- index of vertex [0 ... size() - 1]- Returns:
- length fraction at the vertex
- Throws:
IndexOutOfBoundsException- if the index is out of bounds
-
getRelativeBounds
- Specified by:
getRelativeBoundsin interfaceLocatable
-
getLocation
- Specified by:
getLocationin interfaceLocatable
-