# Weiler Atherton – Polygon Clipping Algorithm

__Background__:

__Background__:

Weiler Atherton Polygon Clipping Algorithm is an algorithm made to allow clipping of even concave algorithms to be possible. Unlike Sutherland – Hodgman polygon clipping algorithm, this algorithm is able to clip concave polygons without leaving any residue behind.

__Algorithm__:

__Algorithm__:

1. First make a list of all intersection points namely i_{1}, i_{2}, i_{3}, ... 2. Classify those intersection points as entering or exiting. 3. Now, make two lists, one for the clipping polygon, and the other for the clipped polygon. 4. Fill both the lists up in such a way that the intersection points lie between the correct vertices of each of the polygon. That is the clipping polygon list is filled up with all the vertices of the clipping polygon along with the intersecting points lying between the corresponding vertices. 5. Now, start at the 'to be clipped' polygon's list. 6. Choose the first intersection point which has been labelled as an entering point. Follow the points in the list (looping back to the top of the list, in case the list ends) and keep on pushing them into a vector or something similar of the sorts. Keep on following the list until an exiting intersection point is found. 7. Now switch the list to the 'polygon that is clipping' list, and find the exiting the intersection that was previously encountered. Now keep on following the points in this list (similar to how we followed the previous list) until the entering intersection point is found (the one that was found in the previous 'to be clipped' polygon's list). 8. This vector now formed by pushing all the encountered points in the two lists, is now the clipped polygon (one of the many clipped polygons if any of the clipping polygons is concave). 9. Repeat this clipping procedure (i.e. from step 5) until all the entering intersection points have been visited once.

__Explanation__:

__Explanation__:

** 1. Finding all the intersection points and grouping them**

Here, let there be a polygon ABCD and another polygon VWXYZ. Let ABCD be the clipping polygon and let VWXYZ be the clipped polygon.

So, we can find the intersection points using any method. For example, we can find the intersecting points separately and then find for each intersecting point find if it is entering or leaving, or, we can use Cyrus Beck and find all the intersecting points and also get if a point is entering or exiting. Refer Cyrus Beck for more information on this algorithm.

** 2. Making and filling of two lists**

Now, we make two lists. One for the clipping polygon and one for the clipped polygon.

Now this is how we fill it:

** 3. Running of the algorithm**

We start at the clipped polygon’s list, i.e. VWXYZ.

Now, we find the first intersecting point that is entering. Hence we choose i_{1}.

From here we begin the making of the list of vertices (or vector) to make a clipped sub-polygon.

According to the given example, **i _{1} Y i_{2}** is a clipped sub-polygon.

Similarly, we get:

**i**as another sub-polygon also.

_{0}V i_{3}Hence, we were able to get two sub-polygons as a result of this polygon clipping, which involved a concave polygon, which resulted in:

Similarly, this clipping works for convex polygons.

__Limitations__:

__Limitations__:

This polygon clipping algorithm does not work for self – intersecting polygons, although some methods have been proposed to be able to solve this issue also, and have successfully worked.

__Example__:

__Example__:

Let V_{1}V_{2}V_{3}V_{4}V_{5}V_{6} be the clipping window and P_{1} P_{2} P_{3} P_{4} P_{5} P_{6} be the polygon.

Now, here is how the algorithm will operate.

Two lists are generated, one for the clipping window, and the other for the polygon. We will start from the polygon’s list. (Note that the polygon’s list only contains the polygon’s vertices and the intersections and similarly for the clipping window’s list.)

So, according to the algorithm, the first polygon to be formed will be *i*_{2} *i*_{3} *i*_{8} *i*_{1}

Then the next subpolygon, *i*_{4} *i*_{5} *i*_{6} *i*_{7}.

The output will look like:

__Citation__:

__Citation__:

K. Weiler and P. Atherton. 1988. Hidden surface removal using polygon area sorting. In Tutorial: computer graphics; image synthesis, Kenneth I. Joy, Charles W. Grant, Nelson L. Max, and Lansing Hatfield (Eds.). Computer Science Press, Inc., New York, NY, USA 209-217.

** Source:** https://www.cs.drexel.edu/~david/Classes/CS430/HWs/p214-weiler.pdf

For implementation of Weiler Atherton, check Implementation

## Recommended Posts:

- Different Types of Clustering Algorithm
- Apriori Algorithm
- Raft Consensus Algorithm
- Introduction to MATLAB
- Adaptive Resonance Theory (ART)
- OpenCV - Overview
- Python | Extractive Text Summarization using Gensim
- Pattern Recognition | Phases and Activities
- Pattern Recognition | Basics and Design Principles
- Difference between Fuzzification and Defuzzification
- OpenCv | Coloured Blank Image
- OpenCV | Saving an Image
- OpenCV | Loading Video
- Age of AI-based recruitment... What to expect?

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.