I have a set of 2D points.
I want to find a set of (possibly overlapping and arbitrarily oriented) bounding-boxes for subsets of these points such that each point lies within at least one box, each box contains at least k points and such that the combined area of the boxes is minimized.
One idea for an algorithm I have is:
use a concave-hull algorithm to find a concave hull for the points.
use convex decomposition algorithm to find a set of convex hulls.
compute arbitrarily oriented minimum bounding box for each of the convex hulls.
I'm looking for a list of other (potentially better suited) algorithms for this problem?
Related
The minimum bounding box (MBB) is the box around a cloud of 3D points with the smallest volume.
Joseph O'Rourke published [2] a cubic-time algorithm to find the minimum-volume enclosing box of a 3-dimensional point set. O'Rourke's approach uses a 3-dimensional rotating calipers technique.
I read the article and wiki (Minimum bounding box algorithms) [1]. Due to the
extremely complicated, I gained nothing. Furthermore, the execution steps of the algorithm are my next problem.
I want to write O'Rourke's algorithm by Fortran.
Any tips about algorithm or flowchart, etc, makes me happy.
Just a hint about the spirit of the algorithm.
In the first place you need to compute the convex hull of the points set, an O(N Log N) process in 2 and 3D. This gives a convex polygon (described by a ring of vertices) or polyhedron (described as a planar graph).
The next step is combinatorial and consists in trying all the positions that are potentially the tightest. In 2D, a minimum bounding box is flush with an edge, and it suffices to try the directions of all edges in turn (you rotate the polygon so that the edge becomes horizontal, and construct the AABB).
The 3D case is more elaborate and uses the fact that a tightest box is flush with two edges of the polyhedron, on two adjacent faces of the box (the box is not necessarily flush with a face). This property allows to generate a finite number of orientations by trying all pairs of edges, and as above, bring the edges in two coordinate planes and construct the AABB. This takes a little of spherical trigonometry.
I'm implementing the A* pathfinding algorithm into a grid based engine, but I'm wanting to create nodes in polygonal areas rather than just using the grid points.
There will be obstacles in the area, that shouldn't be moved through.
I'm wondering is there some algorithm that can split up a larger area with obstacles into a graph with the smallest possible number of connected convex polygons?
There's a lot of them. Typically you're dealing with your triangulation algorithms. You remove the lines that travel through an obstacle and likely do a shortest path algorithm on it. I'm not sure why you want the smallest number of connected convex polygons though, but that could equally be done. The answer is simply the convex hull of the points. One polygon is by definition the smallest number there.
Given a set of points in the plane, I want to find the smallest polygon containing all the points. More precisely, the vertices of this polygon must be a subset of the original set of points.
The easiest approach would be to find the convex hull, which can be computed in O(N log(N)) time using Graham's scanning algorithm, but I would ideally like to drop the requirement that the polygon be convex. Are there any standard approaches to this? I imagine this problem is a fair bit harder because it seems to me there is not guaranteed to be a unique solution.
Do you need the absolutely smallest area solution or just a 'fairly good' solution. If the latter then one possible algorithm would be:
1) calculate the convex hull of all your points - all these points must be vertexes of your final solution.
2) calculate the convex hull of the remaining points - repeat this process until you have no points left. You will end up with n non-intersecting convex hulls.
3) Determine (possibly by greedy algorithm), where to join these hulls to form a single contiguous path between all the points by adding pairs of lines between neighboring points in neighboring hulls and removing lines in the hulls.
This might not be the minimal area but should be a fairly good solution.
Added comment: Greedy removal from the outermost hull to the next inner one should be by removing the largest area region separating the two. Greedy removal from the second hull to the next inner one should be by 'removing' (which is actually retaining) the smallest area separating the hulls...and so on inwards swapping between largest and smallest areas...
Picture added to explain better than my 100 words.
given a convex polgyon and a number N, how do I find the smallest polygon that
contains every point from the original polygon
has exactly N corner points
For example, suppose I have a set of points and compute the convex hull for them (green). Now I want to find the smallest quadrangle that contains all the points (red)
It is easy to see that any other polygon with 4 corners would either be bigger or fail to contain all the points. But how do I find this polygon in the general case?
EDIT:
With smallest polygon I mean the the one that covers the smallest area, although I am not sure whether the smallest circumference would give different results.
I added two more example pictures that unfortunately do not seem to work with the 'remove edges' approach in one of the answers
Some background information:
The goal is to accurately determine shapes with image recognition. For example take a foto of a cuboid. All points inside the box in the 2D-photo will be contained in a 6-corner convex polygon. However since real-world shapes do not have perfect corners, and the camera adds some blur, the edges of this polygon will be rounded.
See the attached image from the question Getting corners from convex points
You need to define the notion of "smallest" in your question. Whatever your definition,
this question has been heavily studied in the computational geometry literature.
The key search phrase is minimal enclosing k-gon:
Mictchell et al.: "Minimum-Perimeter Enclosing k-gon" 2006 (CiteSeer link)
Aggarwal et al.: "Minimum Area Circumscribing Polygons" 1985 (CiteSeer link)
O'Rourke et al.: "An optimal algorithm for fnding minimal enclosing triangles" 1986, Algorithmica (ACM link)
The general algorithms are not simple
(although algorithms for min area triangles or rectangles are simple).
Depending on your goals, you might have to abandon any mathematical notion of
"smallest" and head for a heuristic.
While number of edges > N do
remove the shortest edge by replacing its endpoints
with the intersection point of the adjacent edges
I am looking for / trying to develop an optimal algorithm for rectilinear polygon intersection with rectangles. The polygons I am testing do not have holes.
Answers like those given here and here are for very general polygons, and the solutions are understandably quite complex.
Hoping that the S.O. community can help me document algorithms for the special cases with just rectilinear polygons.
I am looking for the polygon filled in green in the image below:
The book Computational Geometry: an Introduction by Preparata and Shamos has a chapter on rectilinear polygons.
Use a sweep line algorithm, making use of the fact that a rectilinear polygon is defined by its vertices.
Represent the vertices along with the rectangle that they belong to, i.e. something like (x, y, #rect). To this set of points, add those points that result from the intersections of all edges. These new points are of the form (x, y, final), since we already know that they belong to the resulting set of points.
Now:
sort all points by their x-value
use a sweep line, starting at the first x-coordinate; for each new point:
if it's a "start point", add it to a temporary set T. Mark it "final" if it's a point from rectangle A and between y-coordinates from points from rectangle B in T (or vice versa).
if it's an "end point", remove it and its corresponding start point from T.
After that, all points that are marked "final" denote the vertices of the resulting polygon.
Let N be the total number of points. Further assuming that testing whether we should mark a point as being "final" takes time O(log(n)) by looking up T, this whole algorithm is in O(N*log(N)).
Note that the task of finding all intersections can be incorporated into the above algorithm, since finding all intersections efficiently is itself a sweep line algorithm usually. Also note that the resulting set of points may contain more than one polygon, which makes it slightly harder to reconstruct the solution polygons out of the "final" vertices.