Rotating jamming case -- a rectangle with the smallest area of a convex polygon

Source: Internet
Author: User
Convex Polygon minimum area external rectangle

Returns a convex polygon.PThe minimum area can be mountedPWhat is the rectangle of (as far as the periphery is concerned? Technically speaking, given a direction, we can calculatePAnd create an external rectangle. But do we need to test each case to obtain each rectangle to calculate the minimum area? Thank God, we don't have to do that.

For PolygonPAn external rectangle of is located with an edge of the original polygon.

The above conclusions effectively limit the possible range of rectangles. We not only do not need to detect all possible directions, but also only need to detect the number of rectangles equal to the number of polygon edges.

As shown in the preceding figure, the four tangent lines (red) overlap with one side of the polygon and determine the external rectangle (blue ).


A simple algorithm is to calculate each edge in sequence as an edge that overlaps with a rectangle. However, this method of constructing a rectangle involves the calculation of each edge endpoint of a polygon.O (N)Time (becauseNSide. The whole algorithm will have a second time complexity.

A more efficient algorithm has been found. Using the rotating jamming case, we can update the data in real time within the constant time, instead of re-calculating the endpoint.
In fact, considering a convex polygon, there are two pairs andXAndYTangent tangent to the last four endpoints. The four lines have determined the external rectangle of a polygon. However, unless a polygon has a horizontal or vertical edge, the area of the rectangle cannot be included in the minimum area.
However, you can rotate the line until the condition is met. This process is the core of subordinate algorithms. Assume that a convex polygon is input clockwise.NVertex.

  1. Calculate the endpoints of all four polygon.Xminp,Xmaxp,Yminp,Ymaxp.
  2. Constructed by four pointsP. They identified two "shells.
  3. If one or two lines overlap with one side, the area of the rectangle determined by the four lines is calculated and saved as the current minimum value. Otherwise, the current minimum value is defined as Infinity.
  4. Rotate the line clockwise until one of the lines overlaps with one of the sides of the polygon.
  5. Calculate the area of the new rectangle and compare it with the current minimum value. If it is smaller than the current minimum value, it is updated and information about the rectangle that determines the minimum value is saved.
  6. Repeat steps 4 and 5 until the angle of line rotation is greater than 90 degrees.
  7. The minimum area of the output external rectangle.

Because the two pairs of "shells" determine an external rectangle, this algorithm takes into account all the rectangles that may calculate the minimum area. In addition to the initial values, the main cycle of the algorithm only needs to execute the total number of vertices multiple times. Therefore, the algorithm is linear in time complexity.

A similar but little-known problem is the problem of the smallest perimeter external rectangle. Interestingly, these two problems are completely different, because there are (although very few) polygon with no overlap between the smallest area external rectangle and the smallest perimeter external rectangle polygon.

 

 

Http://cgm.cs.mcgill.ca /~ Orm/maer.html

 

Please indicate the source for reprinting. Thank you!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.