The past few months there has been a lot of questions on polygon clipping.
So you might find this interesting.
I have implemented the algorithm for general polygon clipping described
by Bala R. Vatti in Communications of the ACM July 1992 Vol. 35 No 7
pp 57-63. (I read a few weeks back of someone asking if anyone had
implemented "that *ing algorithm" :-)
The algorithm is based on a scanline technique and it handles all sorts
of polygons. They can be self-intersecting and contain holes, you can
define as many clip and subject polygons as you wish.
The output can be polygons or trapezoids (trapezoids are not implemented).
You can not only do clipping but union and difference (that's why I
The problem is that the code was written in a hurry (less than a week).
Another thing is that the paper wasn't totally good, (lot's of errors
and left out parts), the pseudo-code wasn't the best either so...
Don't get me wrong the algorithm is great, it's quite simple and very
flexible (and fast).
The code isn't very good at the moment, it's good enough to be used in
my application but not good enough to be spread on the net.
BUT if there is enough interest I can make an effort of rewriting and
fixing and commenting the code so you can enjoy it.
Are you interested? Email me and we'll see.