check whether a point is visible from a face of a 2d convex hull - computational-geometry

I am trying to implement the Bowyer-Watson algorithm for generating a Delaunay Triangulation of a set of points in a plane. The algorithm assumes a presence of a bounding super-triangle, but some alternatives like maintaining the convex hull of the set of points have also been mentioned.
Thus, when we decide to produce a delaunay triangulation of points by assuming a convex hull in an incremental algorithm, if a point lies outside the convex hull, we should draw vertices from the point to all the vertices on the convex hull which comprise the faces of the hull from which the point is visible.
I was wondering how could I approach this problem? Should I initially generate a convex hull of all the points or like in the incremental approach where points are added one at a time, should i maintain a convex hull in the form of a DCEL?
EDIT: In the image above, if I have the point P which is outside the convex hull of a set of points in a plane, I need to calculate the edges of the hull from which the point is visible. [The green edge of the hull]
I hope the image helps in clarifying the question.
Thanks in advance

The edges that see P are those that form a clockwise triangle with P when the hull is traversed counterclockwise (compute the signed area).

Related

Computing the upper convex hull in 3d using Qhull

I am trying to compute the upper convex hull of a cloud of point in 3D using Qhull. I do not know if there is a simple way to do it.
I've looked into several options of the modules ConvexHull and Delaunay, 'Qu' furthest site, but i do not think it does what I want, as it seems to be a way of computing the Delaunay triangulation using lower/upper convex hulls.
Another way of engineering a solution could be for each simplice of the convex hull to compute the normal and the center point of the surface, as to introduce a new point close to the center following a translation upon the normal.
Having added this point I could just compute the convex hull of the original ensemble plus this point and see if this point is interior to the hull or not.
I could then deduce if the simplice belongs to the upper and/or the lower hull.

Algorithm to add points at the edge of other points

Let's say the initial map has only the red dots. Then I want to add all the green dots. Note that the shape is not always circular.
Any idea how to do that?
I was thinking to consider all as a cluster and then get the edge (or approximation) of the cluster and add new dots.
One possibility that comes to mind would be to conmpute the convex hull polygon of the input, using one of the known algorithms for that. Next, the center of gravity of the convex hull polygon could be used to shift the points of the convex hull outwards, resulting in a dilation of the boundary. If more points for the boundary are needed, one could interpolate between the points of the convex hull polygon.

Confusion on Delaunay Triangulation and Largest inscribed circle

I need to find a largest inscribed circle of a convex polygon, I've searched many sites and I get that this can be done by using Delaunay triangulation. I found a thread in CGAL discussion with an algorithm using CGAL:
You can compute this easily with CGAL:
First, compute the Delaunay triangulation of the points.
Then, iterate on all the finite faces of the triangulation.
For each finite face f
compute its circumcenter c
locate c in the triangulation (to speed up things, you can give one
vertex of f as starting hint for the point location)
if the face returned by locate(c,hint) is finite, then the circumcenter
c lies in the convex hull of the points, so, f is a candidate
if f is such a candidate face, compute its squared circumradius
keep only the face with minimum squared circumradius
The CGAL manual (chapter 2D triangulation, together with a few things
from the kernel) shows every basic function to do this.
I was a bit confused with the last part of this algorithm. When I read it what I understand from it is that the minimum circumradius of the triangulation face is the radius for the largest inscibed circle. But from examples of polygon with Delaunay triangulation, it seems that even the smallest circumcircle sometimes cannot fit inside the polygon, so how can this has the same radius as the largest inscribed circle?
Maximum inscribed circle in polygons.
The classical computational-geometry solution to the maximum inscribed circle problem for polygons is to use the generalized Voronoi diagram of the polygon's faces resp. the medial axis of the polygon. This approach works in a more general setting like polygons with holes, see this stackoverflow answer to a similar question.
Convex input.
The convexity of your input polygon, however, gives the problem more structure, which I would like to comment on. Consider the following convex input polygon (black), the Voronoi diagram (blue), and the maximum inscribed circle (green) centered on a Voronoi node.
The classical Voronoi-based solution is to (i) compute the Voronoi diagram and (ii) take the Voronoi node with largest clearance (i.e., distance to its defining faces).
The Voronoi diagram of a polygon with holes (i.e., the set of vertices and edges) can be computed in O(n log n) time, c.f. Fortune's algorithm (1986). Later Chin et alii (1999) gave an O(n) algorithm for the medial axis of a simple polygon.
For convex polygons, however, a time-optimal algorithm for Voronoi diagram that runs in O(n) time was already known in 1989 due to Aggarwal et alii. This algorithm follows basically the following idea: Consider the grey offset curves moving inwards at unit speed. If you project this movement into three-space where the z-axis is time you get a unit-slop roof over the polygon:
This roof model could also be characterized as follows: Put a half-space on each polygon edge at 45° slope with polygon (such that they contain the polygon) and intersect them all. So if you can quickly compute the intersect of half-spaces then you can also quickly compute Voronoi diagrams of convex polygons. Actually, for the maximum inscribed circle problem we do not need to go back to the Voronoi diagram but take the one peak of the roof, which marks the center of the maximum inscribed circle.
Now the half-spaces are dualized to points, and then the intersection of half-spaces corresponds the convex hull of its dual points. Aggarwal et al. now found an O(n) algorithm for the convex hull of points that stem from this setting.
A summary of this construction that leads to a Voronoi diagram algorithm for convex polyhedra in any dimension can be found in a blog article of mine.
Simple & fast implementation. A simpler algorithm to compute the Voronoi diagram is motivated by straight skeletons. For convex polygons the Voronoi diagram and the straight skeleton are the same.
The algorithm behind the straight-skeleton implementation Stalgo basically simulates the evolution of the wavefront structure (the grey offset curves). For convex polygons this reduces to finding the sequence of edges that collapse.
So a simple O(n log n) algorithm could look like this:
Construct a circular list of the polygon edges. Compute the collapse time of each edge during wavefront propagation, and insert this event into a priority queue.
Until the queue is empty: Take out the next edge-collapse event: Remove the edge from the circular structure and update the collapse times of the neighboring edges of the removed edge.
Actually, you can simplify the above algorithm further: You do not need to update edge collapses in the priority queue but simply insert new ones: Since the new collapse time of edges are strictly lower, you always get the right event first and dismiss the others and the queue is not growing larger than 2n. Hence, you do not compromise the O(n log n) time complexity.
For the maximum inscribed circle problem you can simplify the above algorithm even further: The Voronoi node (resp. straight skeleton node) you look for is due to the collapse of the final triangle at the end of the loop over the priority queue.
This algorithm should be quick in practice and only a few lines of code.
The last step can mean to select the minimum face of the triangle. Then rinse and repeat.

Minkowski sum for shapes with arcs

There is a problem: I wanna compute Minkowski sum for two almost convex polygons, where almost convex polygon - polygon, obtained by replacing some edges with arcs with 0 to PI radians in convex polygon.
I hope there is O(n + m) solution, where n, m - numbers of verteces in almost convex polygons.
For convex shapes the problem is trivial, but this problem puzzles me. Could anyone help me with any advice/idea/solution. Thanks in advance!
First, visualize the Minkowski sum (help with that here). Next, understand the area between an arc and a chord (that's the semi-hard part here). If your polygons are convex, and the arc is in the convex direction, then it will only add area to the Minkowski sum. To be specific, it will add exactly that area described by the arc and chord. If and only if you are dealing with convex polygons and arcs in the convex direction, you can simply substitute the exact same arc you used on the polygon as the corresponding edge of the Minkowski sum. Note that each edge of the Minkowski sum corresponds exactly to an edge of one of the relevant polygons.
I made a quick screen cap of a slide from the Minkowski link to illustrate my point. Forgive me that it's inexact, but I think you will get the idea. The purple area would be added to the area of the Minkowski sum.
If you are using this for motion planning or similar, you can adapt traditional algorithms for point containment almost trivially.
Edit:
I think if the arcs are in the concave direction, it's simply a matter of area subtraction rather than addition. The important thing to maintain simplicity is that one of the polygons is convex and arc substitution happens on the convex polygon or an edge in the convex hull of the other.

Point in Polygon Algorithm in Programming Contests

What is the best algorithm to solve point in polygon in programming contests?
Shoot a ray(in arbitrary direction) from the point and check the number of times it has crossed the edges of polygon if it is even then the point is outside the polygon otherwise the point is inside the polygon.
If you need to do it for lots of query points, you can triangulate the polygon (actually triangulate both inside and the region between the polygon the convex containing it) so that you could do ray shooting in O(log n)
if you have a convex polygon you can use this :
http://e-maxx.ru/algo/pt_in_polygon

Resources