Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Polygon Clipping: Only "viewable" area

In the image below you see in (1) a triangle and a circle. Given a dedicated point X in that triangle I want clip away everything that is not visible from this point. There's no problem with removing just the circle with a simple polygon difference algorithm like in (2). But what kind of algorithm can I use to get a polygon like in (3) ?

The Polygon is always simple.

Edit: The circle is just an example. Every simple polygon should be possible.

Image #1

You can image my needs by taking a look at the image of the game "Commandos - Behind enemy lines":

Image #2

like image 461
tur1ng Avatar asked Sep 05 '11 19:09

tur1ng


1 Answers

This is the basic idea.

I'm assuming a problem a few more general, but it will be a lot easier to adapt it to your problem: given a plan containing all the shapes, a point and a set of geometrical shapes, we want to remove from the plan the area not visible from that point.

What we want to do is to get, for each shape, it's starting_polar and ending_polar points, that are the 2 points with the minimum and maximum polar angle belonging to the shape.

Now we'll remove from the plan the shape and we'll remove the quadrilateral formed by the points: starting_polar, ending_polar, and the intersections between the 2 straight lines (x, starting_polar) and (x, ending_polar) and the boundaries of the plan.

In your case the plan will simply be the triangle.

like image 62
Simone Avatar answered Nov 06 '22 22:11

Simone