The width of a convex polygon is defined as the minimum distance between parallel tangents. This definition has been given a hint in the word width. However, the tangents of a convex polygon are allowed to be in any direction, and the widths (usually) are different for each direction. But fortunately, not every direction must be detected.
We set up a line segment [A, A,], and two parallel lines through a and B. By rotating these two lines around these points, the distance between them is either incremented or decremented. In particular, there is always a particular direction of rotation that makes the distance between the two lines smaller by rotation.
This simple conclusion can be applied to the problem of finding the width: Not all directions need to be considered. Suppose a polygon is given, and there are two parallel tangent lines. If they are not coincident with the edge, then we can always rotate to reduce the distance between them. Therefore, two parallel tangents are not possible to determine the width of the polygon until at least one of them is coincident with the edge.
This means that only "point-to-side" and "Edge-edge" pairs need to be considered in the calculation width process.
The figure above is a schematic of the width of a convex polygon. The diameter is represented by a black point through which a parallel tangent (red line) crosses the graph. The diameter is the one indicated by the highlighted light blue line.
An algorithm that is very similar to the calculation of the diameter problem can be obtained by traversing the polygon to the heel point pair list, determining the vertex-edge and edge-edge pair to calculate the width. The selection process is as follows:
1. Calculates the endpoint in the Y direction of the polygon. We call it ymin and Ymax.
2, through the ymin and ymax constructs two horizontal tangent line. If a (or two) line coincides with the edge, then a "pair heel point-edge" pair or "edge-edge" pair has been established. At this point, the distance between the two lines is calculated and saved as the current minimum distance.
3. Rotate two lines at the same time until one of them coincides with an edge of the polygon.
4, a new "point to heel Point-edge" pair (or when two lines are coincident with the edge, "Edge-edge" pair) is generated at this time. Calculates the new distance, and compares it with the current minimum value, which is less than the current minimum.
5. Repeat step 3 and step 4 (jam) until the original parallel edge is reached again.
6. The pair of the minimum value to be obtained as the pair output to determine the width.
The more intuitive algorithm is again due to the need to introduce the calculation of the angle to reflect its shortcomings. However, sometimes a simpler, more intuitive rotation jam algorithm has to be introduced into the calculation, just like the problem of maximum distance between convex polygons.