0
$\begingroup$

Is there a single algorithm that I can use to clip a polygon by a polygon or a line by a polygon?

If not, what are two good algorithms that can handle both complex geometries (self intersecting) lines and polygons?

1 Answers 1

0

Clipping a polygon $P$ by a line $\ell$ can be done in $\mathcal{O}(n)$ time where $n$ is the number of vertices of $P$ using the Sutherland-Hodgeman algorithm. Assuming you have your polygon boundary stored as a list of consecutive vertices. Then, the main idea is to walk along the boundary and every time you cross $\ell$ you add the intersection as a vertex to the boundary list. On the side that you want to clip you just remove the vertices until the boundary crosses $\ell$ again.

Clipping a polygon with another polygon should be possible using the Weiler–Atherton clipping algorithm.

  • 0
    Thank you, I will investigate these today! – 2017-02-28