Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can someone explain the rotating calipers to me?

I'm struggling with calculating the smallest enclosing rectangle (arbitrarily aligned) of a set of points.

I was able to calculate the convex hull using graham's algorithm.

Where I'm stuck is the next step. I thought about using the rotating calipers method, but I can't seem to find an adequate explanation of the algorithm.

like image 734
mish Avatar asked Dec 07 '12 14:12

mish


1 Answers

If you have the convex hull, then a basic algorithm easy. You just go through each edge of the convex hull and rotate your points so that edge is along a major axis, let's say the X-axis. Then you find an axis-aligned bounding box of those points. Choose whichever bounding box is smallest.

An axis-aligned bounding box can be found by getting the minimum and maximum in each dimension.

If you rotate your bounding box by the opposite amount, it will now enclose your original points.

To make this more efficient, note that the only points that can affect the bounding box are on the convex hull.

To make it really efficient, note that there are only four points around the convex hull that are touching the bounding box at any one time (this isn't strictly true, but ignore that for now). If you rotate the points just enough that the next edge is aligned with the bounding box, then three of those points are the same and one of the points is replaced with the next point around the convex hull. This lets you create an algorithm that is linear in the number of points on the convex hull.

Now there are special cases where two edges are parallel or perpendicular. This will cause more than four points to be touching the bounding box at any one time, but it actually doesn't matter. If you have a choice between which of two parallel edges to use next, you can just pick one arbitrarily.

like image 171
Vaughn Cato Avatar answered Sep 18 '22 22:09

Vaughn Cato