Class OTSLine3D

    • Constructor Detail

      • OTSLine3D

        public OTSLine3D​(OTSPoint3D... points)
                  throws OTSGeometryException
        Construct a new OTSLine3D.
        Parameters:
        points - OTSPoint3D...; the array of points to construct this OTSLine3D from.
        Throws:
        OTSGeometryException - when the provided points do not constitute a valid line (too few points or identical adjacent points)
      • OTSLine3D

        public OTSLine3D​(org.locationtech.jts.geom.Coordinate[] coordinates)
                  throws OTSGeometryException
        Construct a new OTSLine3D from an array of Coordinate.
        Parameters:
        coordinates - Coordinate[]; the array of coordinates to construct this OTSLine3D from
        Throws:
        OTSGeometryException - when the provided points do not constitute a valid line (too few points or identical adjacent points)
      • OTSLine3D

        public OTSLine3D​(org.locationtech.jts.geom.LineString lineString)
                  throws OTSGeometryException
        Construct a new OTSLine3D from a LineString.
        Parameters:
        lineString - LineString; the lineString to construct this OTSLine3D from.
        Throws:
        OTSGeometryException - when the provided LineString does not constitute a valid line (too few points or identical adjacent points)
      • OTSLine3D

        public OTSLine3D​(org.locationtech.jts.geom.Geometry geometry)
                  throws OTSGeometryException
        Construct a new OTSLine3D from a Geometry.
        Parameters:
        geometry - Geometry; the geometry to construct this OTSLine3D from
        Throws:
        OTSGeometryException - when the provided Geometry do not constitute a valid line (too few points or identical adjacent points)
      • OTSLine3D

        public OTSLine3D​(List<OTSPoint3D> pointList)
                  throws OTSGeometryException
        Construct a new OTSLine3D from a List<OTSPoint3D>.
        Parameters:
        pointList - List<OTSPoint3D>; the list of points to construct this OTSLine3D from.
        Throws:
        OTSGeometryException - when the provided points do not constitute a valid line (too few points or identical adjacent points)
      • OTSLine3D

        public OTSLine3D​(Path2D path)
                  throws OTSGeometryException
        Construct a new OTSShape (closed shape) from a Path2D.
        Parameters:
        path - Path2D; the Path2D to construct this OTSLine3D from.
        Throws:
        OTSGeometryException - when the provided points do not constitute a valid line (too few points or identical adjacent points)
    • Method Detail

      • offsetLine

        public final OTSLine3D offsetLine​(double offset)
        Construct parallel line.
        TODO Let the Z-component of the result follow the Z-values of the reference line.
        Parameters:
        offset - double; offset distance from the reference line; positive is LEFT, negative is RIGHT
        Returns:
        OTSLine3D; the line that has the specified offset from the reference line
      • noiseFilteredLine

        public final OTSLine3D noiseFilteredLine​(double noiseLevel)
        Construct a line 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:
        OTSLine3D; the filtered line
      • noiseFilterRamerDouglasPeucker

        public final OTSLine3D noiseFilterRamerDouglasPeucker​(double epsilon,
                                                              boolean useHorizontalDistance)
        Clean up a list of points that describe a polyLine by removing points that lie within epsilon distance of a more straightened version of the line.
        TODO Test this code (currently untested).
        Parameters:
        epsilon - double; maximal deviation
        useHorizontalDistance - boolean; if true; the horizontal distance is used; if false; the 3D distance is used
        Returns:
        OTSLine3D; a new OTSLine3D containing all the remaining points
      • offsetLine

        public final OTSLine3D offsetLine​(double offsetAtStart,
                                          double offsetAtEnd)
                                   throws OTSGeometryException
        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.
        Parameters:
        offsetAtStart - double; offset at the start of the reference line (positive value is Left, negative value is Right)
        offsetAtEnd - double; offset at the end of the reference line (positive value is Left, negative value is Right)
        Returns:
        Geometry; the Geometry of the line at linearly changing offset of the reference line
        Throws:
        OTSGeometryException - when this method fails to create the offset line
      • offsetLine

        public final OTSLine3D offsetLine​(double[] relativeFractions,
                                          double[] offsets)
                                   throws OTSGeometryException
        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 - double[]; positional fractions for which the offsets have to be generated
        offsets - double[]; offsets at the relative positions (positive value is Left, negative value is Right)
        Returns:
        Geometry; the Geometry of the line at linearly changing offset of the reference line
        Throws:
        OTSGeometryException - when this method fails to create the offset line
      • concatenate

        public static OTSLine3D concatenate​(OTSLine3D... lines)
                                     throws OTSGeometryException
        Concatenate several OTSLine3D instances.
        Parameters:
        lines - OTSLine3D...; OTSLine3D... one or more OTSLine3D. The last point of the first <strong>must</strong> match the first of the second, etc.
        Returns:
        OTSLine3D
        Throws:
        OTSGeometryException - if zero lines are given, or when there is a gap between consecutive lines
      • concatenate

        public static OTSLine3D concatenate​(double toleranceSI,
                                            OTSLine3D line1,
                                            OTSLine3D line2)
                                     throws OTSGeometryException
        Concatenate two OTSLine3D instances. This method is separate for efficiency reasons.
        Parameters:
        toleranceSI - double; the tolerance between the end point of a line and the first point of the next line
        line1 - OTSLine3D; first line
        line2 - OTSLine3D; second line
        Returns:
        OTSLine3D
        Throws:
        OTSGeometryException - if zero lines are given, or when there is a gap between consecutive lines
      • concatenate

        public static OTSLine3D concatenate​(double toleranceSI,
                                            OTSLine3D... lines)
                                     throws OTSGeometryException
        Concatenate several OTSLine3D instances.
        Parameters:
        toleranceSI - double; the tolerance between the end point of a line and the first point of the next line
        lines - OTSLine3D...; OTSLine3D... one or more OTSLine3D. The last point of the first <strong>must</strong> match the first of the second, etc.
        Returns:
        OTSLine3D
        Throws:
        OTSGeometryException - if zero lines are given, or when there is a gap between consecutive lines
      • reverse

        public final OTSLine3D reverse()
        Construct a new OTSLine3D with all points of this OTSLine3D in reverse order.
        Returns:
        OTSLine3D; the new OTSLine3D
      • extractFractional

        public final OTSLine3D extractFractional​(double start,
                                                 double end)
                                          throws OTSGeometryException
        Construct a new OTSLine3D covering the indicated fraction of this OTSLine3D.
        Parameters:
        start - double; starting point, valid range [0..end)
        end - double; ending point, valid range (start..1]
        Returns:
        OTSLine3D; the new OTSLine3D
        Throws:
        OTSGeometryException - when start >= end, or start < 0, or end > 1
      • extract

        public final OTSLine3D extract​(Length start,
                                       Length end)
                                throws OTSGeometryException
        Create a new OTSLine3D that covers a sub-section of this OTSLine3D.
        Parameters:
        start - Length; the length along this OTSLine3D where the sub-section starts, valid range [0..end)
        end - Length; length along this OTSLine3D where the sub-section ends, valid range (start..length (length is the length of this OTSLine3D)
        Returns:
        OTSLine3D; the selected sub-section
        Throws:
        OTSGeometryException - when start >= end, or start < 0, or end > length
      • extract

        public final OTSLine3D extract​(double start,
                                       double end)
                                throws OTSGeometryException
        Create a new OTSLine3D that covers a sub-section of this OTSLine3D.
        Parameters:
        start - double; length along this OTSLine3D where the sub-section starts, valid range [0..end)
        end - double; length along this OTSLine3D where the sub-section ends, valid range (start..length (length is the length of this OTSLine3D)
        Returns:
        OTSLine3D; the selected sub-section
        Throws:
        OTSGeometryException - when start >= end, or start < 0, or end > length
      • createAndCleanOTSLine3D

        public static OTSLine3D createAndCleanOTSLine3D​(OTSPoint3D... points)
                                                 throws OTSGeometryException
        Create an OTSLine3D, while cleaning repeating successive points.
        Parameters:
        points - OTSPoint3D...; the coordinates of the line as OTSPoint3D
        Returns:
        the line
        Throws:
        OTSGeometryException - when number of points < 2
      • createAndCleanOTSLine3D

        public static OTSLine3D createAndCleanOTSLine3D​(List<OTSPoint3D> pointList)
                                                 throws OTSGeometryException
        Create an OTSLine3D, while cleaning repeating successive points.
        Parameters:
        pointList - List<OTSPoint3D>; list of the coordinates of the line as OTSPoint3D; any duplicate points in this list are removed (this method may modify the provided list)
        Returns:
        OTSLine3D; the line
        Throws:
        OTSGeometryException - when number of non-equal points < 2
      • getCoordinates

        public final org.locationtech.jts.geom.Coordinate[] getCoordinates()
        Construct a Coordinate array and fill it with the points of this OTSLine3D.
        Returns:
        an array of Coordinates corresponding to this OTSLine
      • getLineString

        public final org.locationtech.jts.geom.LineString getLineString()
        Construct a LineString from this OTSLine3D.
        Returns:
        a LineString corresponding to this OTSLine
      • size

        public final int size()
        Return the number of points in this OTSLine3D.
        Returns:
        the number of points on the line
      • getFirst

        public final OTSPoint3D getFirst()
        Return the first point of this OTSLine3D.
        Returns:
        the first point on the line
      • getLast

        public final OTSPoint3D getLast()
        Return the last point of this OTSLine3D.
        Returns:
        the last point on the line
      • get

        public final OTSPoint3D get​(int i)
                             throws OTSGeometryException
        Return one point of this OTSLine3D.
        Parameters:
        i - int; the index of the point to retrieve
        Returns:
        OTSPoint3d; the i-th point of the line
        Throws:
        OTSGeometryException - when i < 0 or i > the number of points
      • getLengthSI

        public final double getLengthSI()
        Return the length of this OTSLine3D as a double value in SI units. (Assumes that the coordinates of the points constituting this line are expressed in meters.)
        Returns:
        the length of the line in SI units
      • getLength

        public final Length getLength()
        Return the length of this OTSLine3D in meters. (Assuming that the coordinates of the points constituting this line are expressed in meters.)
        Returns:
        the length of the line
      • getPoints

        public final OTSPoint3D[] getPoints()
        Return an array of OTSPoint3D that represents this OTSLine3D. Do not modify the result.
        Returns:
        the points of this line
      • getLocationExtended

        public final DirectedPoint getLocationExtended​(Length 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.
        Parameters:
        position - Length; the position on the line for which to calculate the point on, before, of after the line
        Returns:
        a directed point
      • getLocationExtendedSI

        public final DirectedPoint getLocationExtendedSI​(double positionSI)
        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:
        positionSI - double; the position on the line for which to calculate the point on, before, of after the line, in SI units
        Returns:
        a directed point
      • getLocationFraction

        public final DirectedPoint getLocationFraction​(double fraction)
                                                throws OTSGeometryException
        Get the location at a fraction of the line, with its direction. Fraction should be between 0.0 and 1.0.
        Parameters:
        fraction - double; the fraction for which to calculate the point on the line
        Returns:
        a directed point
        Throws:
        OTSGeometryException - when fraction less than 0.0 or more than 1.0.
      • getLocationFraction

        public final DirectedPoint getLocationFraction​(double fraction,
                                                       double tolerance)
                                                throws OTSGeometryException
        Get the location at a fraction of the line, with its direction. Fraction should be between 0.0 and 1.0.
        Parameters:
        fraction - double; the fraction for which to calculate the point on the line
        tolerance - double; the delta from 0.0 and 1.0 that will be forgiven
        Returns:
        a directed point
        Throws:
        OTSGeometryException - when fraction less than 0.0 or more than 1.0.
      • getLocationFractionExtended

        public final DirectedPoint getLocationFractionExtended​(double fraction)
        Get the location at a fraction of the line (or outside the line), with its direction.
        Parameters:
        fraction - double; the fraction for which to calculate the point on the line
        Returns:
        a directed point
      • getLocation

        public final DirectedPoint getLocation​(Length position)
                                        throws OTSGeometryException
        Get the location at a position on the line, with its direction. Position should be between 0.0 and line length.
        Parameters:
        position - Length; the position on the line for which to calculate the point on the line
        Returns:
        a directed point
        Throws:
        OTSGeometryException - when position less than 0.0 or more than line length.
      • getLocationSI

        public final DirectedPoint getLocationSI​(double positionSI)
                                          throws OTSGeometryException
        Get the location at a position on the line, with its direction. Position should be between 0.0 and line length.
        Parameters:
        positionSI - double; the position on the line for which to calculate the point on the line
        Returns:
        a directed point
        Throws:
        OTSGeometryException - when position less than 0.0 or more than line length.
      • truncate

        public final OTSLine3D truncate​(double lengthSI)
                                 throws OTSGeometryException
        Truncate a line at the given length (less than the length of the line, and larger than zero) and return a new line.
        Parameters:
        lengthSI - double; the location where to truncate the line
        Returns:
        a new OTSLine3D truncated at the exact position where line.getLength() == lengthSI
        Throws:
        OTSGeometryException - when position less than 0.0 or more than line length.
      • projectOrthogonal

        public final double projectOrthogonal​(double x,
                                              double y)
        Returns the fractional position along this line of the orthogonal projection of point (x, y) on this line. If the point is not orthogonal to the closest line segment, the nearest point is selected.
        Parameters:
        x - double; x-coordinate of point to project
        y - double; y-coordinate of point to project
        Returns:
        fractional position along this line of the orthogonal projection on this line of a point
      • projectFractional

        public final double projectFractional​(Direction start,
                                              Direction end,
                                              double x,
                                              double y,
                                              OTSLine3D.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, the orthogonal 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.
        1. Numerical difficulties at slight bend, orthogonal projection returns the correct point.
        2. Fractional projection is possible only to segments that aren't the nearest segment(s).
        3. Fractional projection is possible for no segment.
        In the latter two cases the projection is undefined and a orthogonal projection is returned if orthoFallback = true, or NaN if orthoFallback = false.
        Parameters:
        start - Direction; direction in first point
        end - Direction; direction in last point
        x - double; x-coordinate of point to project
        y - double; y-coordinate of point to project
        fallback - FractionalFallback; fallback method for when fractional projection fails
        Returns:
        fractional position along this line of the fractional projection on that line of a point
      • getProjectedRadius

        public Length getProjectedRadius​(double fraction)
                                  throws OTSGeometryException
        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 - double; fraction along the line, between 0.0 and 1.0 (both inclusive)
        Returns:
        Length; radius; the local radius; or si field set to Double.NaN if line is totally straight
        Throws:
        OTSGeometryException - fraction out of bounds
      • getProjectedVertexRadius

        public Length getProjectedVertexRadius​(int index)
                                        throws OTSGeometryException
        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 - int; index of the vertex in range [1 ... size() - 2]
        Returns:
        Length; radius at the vertex
        Throws:
        OTSGeometryException - if the index is out of bounds
      • getVertexFraction

        public double getVertexFraction​(int index)
                                 throws OTSGeometryException
        Returns the length fraction at the vertex.
        Parameters:
        index - int; index of vertex [0 ... size() - 1]
        Returns:
        double; length fraction at the vertex
        Throws:
        OTSGeometryException - if the index is out of bounds
      • getCentroid

        public final OTSPoint3D getCentroid()
        Retrieve the centroid of this OTSLine3D.
        Returns:
        OTSPoint3D; the centroid of this OTSLine3D
      • getEnvelope

        public final org.locationtech.jts.geom.Envelope getEnvelope()
        Get the bounding rectangle of this OTSLine3D.
        Returns:
        Rectangle2D; the bounding rectangle of this OTSLine3D
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • toExcel

        public final String toExcel()
        Convert the 2D projection of this OTSLine3D to something that MS-Excel can plot.
        Returns:
        excel XY plottable output
      • toPlot

        public final String toPlot()
        Convert the 2D projection of this OTSLine3D to Peter's plot format.
        Returns:
        Peter's format plot output