Module org.dyn4j

Package org.dyn4j.geometry.simplify

This package contains algorithms to simplify simple polygons without holes with the intent for better performance and stability within dyn4j.

Three implementations of the Simplifier interface are provided: VertexClusterReduction, Visvalingam, and DouglasPeucker.

All three Simplifier require tuning parameters to set the level of allowed simplification.

NOTE: All Simplifier algorithms operate on simple polygons without holes and assume the input already confirms to this constraint.

All the algorithms in this package have O(n log n) complexity and are intended for use real-time, but selection of the tuning parameters will be the challenge. Generally, they should be chosen based on the input polygon to simplify. For example, imagine we have two polygons we want to simplify, A and B. Polygon A's vertices hover around the 1.0-2.0 units while Polygon B's vertices hover around the 100-200 units. These might be the same polygon, but scaled, but would require different tuning parameters. The recommendation is to first scale the polygon down to a known range, then apply the simplification.

The VertexClusterReduction algorithm is primarily for pre-processing but can be used by itself. It's used, by default, in both the Visvalingam and DouglasPeucker classes.

Each algorithm has a different method for simplifying the input polygon and will therefore produce different results. It's also not guaranteed that the algorithms will produce a valid output in the case of poorly chosen tuning parameters - always check the output before sending to the next step (which is typically a convex decomposition process).

If the input is null, null is returned. If the input contains null elements, they are removed before simplification. If the input is less than 4 vertices, no simplification is done and the input is returned with exception of VertexClusterReduction. If the tuning parameters, as mentioned above, are not appropriate, the output can contain 0, 1, or 2 vertices - i.e. not a valid simple polygon.

William Bittle