Module org.dyn4j

Class DouglasPeucker

  • All Implemented Interfaces:
    Simplifier

    public final class DouglasPeucker
    extends VertexClusterReduction
    implements Simplifier
    Simple polygon (without holes) simplifier that reduces the number of vertices by removing points that are less than epsilon distance away from a guide line.

    NOTE: This algorithm is designed for polylines, but has been adapted for simple polygons without holes by first sub-dividing the polygon into two polylines. This first sub-division process will always be from the first vertex in the polygon to the vertex farthest from the first vertex.

    The guide line is defined by the line from the start to the end of the polyline being processed. If all points between the start and end point of the polyline are epsilon or more distant from the guide line, the algorithm splits the polyline and processes each part. This continues recursively until the algorithm is complete.

    This algorithm has O(n log n) complexity where n is the number of vertices in the source polygon. This algorithm prevents self-intersections arising from the simplification process by skipping the simplification.

    This method does not require the polygon to have any defined winding, but does assume that it does not have holes and is not self-intersecting.

    This method handles null/empty lists, null elements, and all null elements. In these cases it's possible the returned list will be empty or have less than 3 vertices.

    NOTE: This algorithm's result is highly dependent on the given cluster tolerance, epsilon and the input polygon. There's no guarantee that the result will have 3 or more vertices.

    Since:
    4.2.0
    Version:
    5.0.0
    Author:
    William Bittle
    See Also:
    Vertex Cluster Reduction
    • Constructor Detail

      • DouglasPeucker

        public DouglasPeucker​(double clusterTolerance,
                              double epsilon)
        Minimal constructor.
        Parameters:
        clusterTolerance - the cluster tolerance; must be zero or greater
        epsilon - the minimum distance epsilon; must be zero or greater
        Throws:
        IllegalArgumentException - if clusterTolerance is less than zero or epsilon is less than zero