# Clipping and offsetting algorithms

<div class="page view" id="bkmrk-for-optimizing-geome"><article>For optimizing geometry for cutting technologies there are a lot of important tools and algorithms out there to solve a lot of common problems. There are a lot of clipping algorithms out there. Most of them work kind a sweep line algorithm - that's a kind of scanning routine which mostly works by visiting elements and brute-forcing them with different methods.

<p class="callout info">[https://de.m.wikipedia.org/wiki/Sweep\_(Informatik)](https://de.m.wikipedia.org/wiki/Sweep_(Informatik))</p>

## [Greiner Hormann Clipping Algorithm](https://en.wikipedia.org/wiki/Greiner%E2%80%93Hormann_clipping_algorithm)

used for polygon clipping. It can process both self-intersecting and non-convex polygons) - also known as [EvenOdd ](https://en.wikipedia.org/wiki/Even%E2%80%93odd_rule)problem

<div class="wiki-content">- [https://github.com/karimbahgat/Clippy](https://github.com/karimbahgat/Clippy) (works for polygons, not for bezier paths)
- [https://oreillymedia.github.io/Using\_SVG/extras/ch06-fill-rule.html](https://oreillymedia.github.io/Using_SVG/extras/ch06-fill-rule.html) see "winding rule"

</div>## [Bentley Ottmann Clipping Algorithm](https://en.wikipedia.org/wiki/Bentley%E2%80%93Ottmann_algorithm)

a sweep line algorithm for listing all crossings in a set of line segments, i.e. it finds the intersection points (or, simply, intersections) of line segments (does not work for bezier paths)

<div class="wiki-content">- [https://github.com/ideasman42/isect\_segments-bentley\_ottmann](https://github.com/ideasman42/isect_segments-bentley_ottmann) (python)
- [https://github.com/lycantropos/bentley\_ottmann](https://github.com/lycantropos/bentley_ottmann) (python)
- [https://github.com/anvaka/isect](https://github.com/anvaka/isect) (NodeJS)

</div>## Bush algorithm

[https://github.com/anvaka/isect](https://github.com/anvaka/isect)

## [Sutherland–Hodgman Algorithm](https://en.wikipedia.org/wiki/Sutherland%E2%80%93Hodgman)

## [Vatti Clipping Algorithm](https://en.wikipedia.org/wiki/Vatti_clipping_algorithm)

Allows clipping of any number of arbitrarily shaped subject [polygons](https://en.wikipedia.org/wiki/Polygon "Polygon") by any number of arbitrarily shaped clip polygons. Unlike the [Sutherland–Hodgman](https://en.wikipedia.org/wiki/Sutherland%E2%80%93Hodgman) and [Weiler–Atherton](https://en.wikipedia.org/wiki/Weiler%E2%80%93Atherton) polygon clipping algorithms, the Vatti algorithm does not restrict the types of polygons that can be used as subjects or clips. Even complex (self-intersecting) polygons, and polygons with holes can be processed. The algorithm is generally applicable only in [2D space](https://en.wikipedia.org/wiki/2D_computer_graphics "2D computer graphics").

Libraries:

<div class="wiki-content">- [https://github.com/karimbahgat/Clippy](https://github.com/karimbahgat/Clippy)
- [https://github.com/fonttools/pyclipper](https://github.com/fonttools/pyclipper) (works for lines and polygons, not for bezier paths) 
    - clipping and offsetting lines and polygons → performs line &amp; polygon clipping - intersection, union, difference &amp; exclusive-or, and line &amp; polygon offsetting
    - [http://www.angusj.com/delphi/clipper/documentation/Docs/Overview/\_Body.htm](http://www.angusj.com/delphi/clipper/documentation/Docs/Overview/_Body.htm)
    - [https://sourceforge.net/projects/polyclipping](https://sourceforge.net/projects/polyclipping/files/)

</div>## [Weiler-Atherton Algorithm](https://de.wikipedia.org/wiki/Weiler-Atherton-Algorithmus)

## Martinez-Rueda polygon clipping algorithm

Libraries:

<div class="wiki-content">- [https://github.com/w8r/martinez](https://github.com/w8r/martinez)
- [https://github.com/karimbahgat/Clippy](https://github.com/karimbahgat/Clippy)

</div>## Offsetting curves

 A really good primer about Bezier curves can be found at [https://pomax.github.io/bezierinfo/#offsetting](https://pomax.github.io/bezierinfo/#offsetting)

<div class="wiki-content" id="bkmrk-"></div></article></div>