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.
You can image my needs by taking a look at the image of the game "Commandos - Behind enemy lines":
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With