Class PolylineWithZProfile

java.lang.Object
com.amalgamasimulation.geometry.geometry3d.PolylineWithZProfile

public class PolylineWithZProfile extends Object
Class representing a polyline in 3D space that is defined by a 2D Polyline and an elevation (z) profile along its length. Vertical segments are not considered correctly; z changes are distributed along the XY length using the provided profile.

NaNs and infinite coordinates are allowed and there are no checks that prevent creating such polylines. These coordinates are not supported in most methods and may cause errors; such special cases are not described below.

Author:
Andrey Malykhanov
  • Constructor Details

    • PolylineWithZProfile

      public PolylineWithZProfile(List<Point3D> points)
      Creates a new polyline with z profile from the specified list of 3D points. Points are connected in order in the XY-plane, and z is interpolated along each XY segment according to the provided point elevations.
      Parameters:
      points - ordered list of points forming the polyline
      Throws:
      IllegalArgumentException - if fewer than two points are provided
    • PolylineWithZProfile

      public PolylineWithZProfile(Point3D... points)
  • Method Details

    • getZAtAbsOffset

      public double getZAtAbsOffset(double absOffset)
      Returns the z-coordinate at the specified absolute offset along the polyline measured in the XY-plane.
      Parameters:
      absOffset - absolute offset along the polyline length in the XY-plane
      Returns:
      z-coordinate at the specified offset
    • getPointByAbsoluteOffset

      public Point3D getPointByAbsoluteOffset(double absOffset)
      Returns the point at the specified absolute offset measured in the XY-plane. Returns null for offsets outside the XY length, using Compare just like Polyline.getPointByAbsoluteOffset(double).
      Parameters:
      absOffset - absolute offset along the XY path
      Returns:
      the 3D point, or null if the offset is outside the path
    • getReversed

      public PolylineWithZProfile getReversed()
      Returns a polyline with the order of its 3D points reversed.
      Returns:
      a polyline directed in the reverse direction
    • getSubPolylineByAbsOffsets

      public PolylineWithZProfile getSubPolylineByAbsOffsets(double start, double end)
      Returns the part of this polyline between two offsets along the XY path. The result is reversed when start is greater than end. Equal offsets produce a single-point XY path. Invalid offsets return null, as in Polyline.getSubPolylineByAbsoluteOffsets(double, double).
      Parameters:
      start - absolute offset of the first point in the XY-plane
      end - absolute offset of the last point in the XY-plane
      Returns:
      the subpolyline, or null if either offset is outside the path
    • getParallelPolyline

      public PolylineWithZProfile getParallelPolyline(double distance)
      Returns a parallel XY path, retaining the elevation of each corresponding vertex. Elevations are interpolated along the new segment lengths. The distance sign and XY geometry follow Polyline.getParallelPolyline(double).
      Parameters:
      distance - signed distance from the XY path
      Returns:
      the parallel polyline with the original vertex elevations
      Throws:
      IllegalStateException - if the XY path has fewer than two points
    • getAllIntersections

      public List<IntersectionDescriptor3D> getAllIntersections(PolylineWithZProfile other)
      Returns all intersection descriptors between this polyline and the specified polyline, where both XY intersection and equal z are present at the same offsets.
      Parameters:
      other - the specified polyline with z profile
      Returns:
      list of intersection descriptors with matching XY and z
    • getXRange

      public Interval getXRange()
      Returns the range of x-coordinates covered by this polyline as an interval.
      Returns:
      interval representing the minimum and maximum x-coordinates
    • getYRange

      public Interval getYRange()
      Returns the range of y-coordinates covered by this polyline as an interval.
      Returns:
      interval representing the minimum and maximum y-coordinates
    • getZRange

      public Interval getZRange()
      Returns the range of z-coordinates (elevations) covered by this polyline as an interval.
      Returns:
      interval representing the minimum and maximum z-coordinates
    • splitAtAbsOffsets

      public List<PolylineWithZProfile> splitAtAbsOffsets(List<Double> absOffsets)
      Splits this polyline into sub-polylines at the specified absolute offsets measured along the XY-plane. The offsets collection should be sorted in ascending order.
      Parameters:
      absOffsets - absolute offsets where the polyline should be split
      Returns:
      list of sub-polylines covering the full length
    • getLength

      public double getLength()
      Calculates the total length of this polyline taking into account both the 2D path and the Z-profile (elevation changes).
      Returns:
      the total 3D length of the polyline, calculated as the sum of 3D Euclidean distances of all segments
    • getPoints

      public List<Point3D> getPoints()
      Returns list of all points of this polyline.
      Returns:
      list of 3D points
    • getInnerPoints

      public List<Point3D> getInnerPoints()
      Returns all inner points of the polyline (i.e., points between the first and last) as 3D coordinates.
      Returns:
      list of inner 3D points
    • getFirstPoint

      public Point3D getFirstPoint()
      Returns the first point of the polyline as a Point3D instance.
      Returns:
      first 3D point of the polyline
    • getLastPoint

      public Point3D getLastPoint()
      Returns the last point of the polyline as a Point3D instance.
      Returns:
      last 3D point of the polyline
    • getPolyline2d

      public Polyline getPolyline2d()
    • getSimplified

      public PolylineWithZProfile getSimplified()
      Simplifies this polyline by removing consecutive points that do not change either its direction in the XY-plane or the rate of change of its Z-profile. The first and last points are always preserved. Consecutive points with the same XY coordinates are ignored when determining direction changes.
      Returns:
      a new polyline containing only the points that define its shape
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hashCode

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

      public boolean equals(Object obj)
      Overrides:
      equals in class Object