views:

42

answers:

2

I have search and researched the internet last days to find a suitable method for my problem.

Problem:

Clip a concave polygon against an infinite line without direction (Actually a polygon against a plane in 3d but the problem is similar i think). Currently i use Sutherland-Hodgman but the resulting polygons sometimes contains zero-area parts created from degenerate edges and it also do not support polygons containing holes.

The best algorithm i have found that could solve my problem is the Weiler-Atherton algorithm but it is for clipping against a polygon with clockwise edges and all i have is an infinite line (in 3d a plane) missing direction info.

Question:

Is there a algorithm to clip a concave polygon that suits my needs or do anyone have a suggestion on how to modify the Weiler-Atherton algorithm to work for this case? There are webpages that suggests it can be generalized to support more cases but i can not figure it out.

//Regards Eiken

A: 

You could use a polygon clipper* to solve this by converting the line into a clipping polygon. Assuming you aren't clipping in a near horizontal plane, just make sure the critical (clipping) edge of the clipping polygon is a little larger than the subject polygon's vertical dimensions (ie the edge extends a above and below the subject polygon). If clipping in a near horizontal plane, make sure the critical edge is a little wider than the subject.

*eg Clipper - http://sourceforge.net/projects/polyclipping/

Disclosure: I'm the author of Clipper, so there's the potential for a personal bias.

Angus Johnson
Yeah i have tried to figure out a good way todo this. My polygon being in 3d space makes it hard to decide how to convert the line into a suitable polygon as subject polygon can be rotated weird that makes it hard to decide in what direction from the line (that i get from plane/plane intersection) to expand the polygon.
Eiken
I presume you can define the clipping line in 2D space. If its absolute slope is less than 1 (ie approaching horizontal) then the clipping line segment (and one edge of your clipping polygon) needs to extend just beyond the left and right extents of the subject polygon. The other edges can be axis aligned just making sure the horizontal edge is above (or below) the extent of the subject polygon. Likewise, if the clipping line's absolute slope is greater than 1, use the same logic but rotate it 90 degrees.
Angus Johnson
Yeah this will work its basicly the same theory as the algorithm i Found in Graphic Gems V except that it is even more simplified for exactly what i wanna do and i can skip the step of representing my plane as a line. Still thanks for your answer. Stackoverflow is an amazing resource.
Eiken
A: 

Found a suitable algorithm in Graphic Gems V which solves my problem. If someone have the same problem this is the reference:

Glassner, A., ''Clipping a Concave Polygon'' , in Graphics Gems V, A. Paeth, ed., Academic Press, Cambridge, 1995

Eiken