Convex Polygon diameter
We define the maximum distance between any two points on a polygon as the diameter of the polygon. The number of vertices that determine the diameter may be more than one pair. In factNPolygon of a vertex may haveNThere is a "diameter point.
A simple example of a polygon diameter is shown in the left figure. The diameter point is shown as the Black Point (a red parallel line) that is passed by parallel lines in the figure. The diameter is highlighted in light blue.
Apparently, determine a convex polygonPThe point of diameter cannot be in a polygon.PInternal. Therefore, the search should be performed on the boundary. In fact, because the diameter is determined by the maximum distance of the parallel tangent of the polygon, we only need to query the vertex. Shamos (1978) providesO (N)Time Complexity calculation of n-point convex Packet PairsAlgorithm. Diameter: traverse the vertex list to obtain the maximum distance. As shown in the following table: Preparata and shamos published in 1985ArticlePseudo-shamos Algorithm inCode.
The input is a polygon.P= {P1,...,Pn}.
Begin P0: = pN; Q: = next [p]; while (area (p, next [p], next [Q])> area (p, next [p], q) do Q: = next [Q]; q0: = Q; while (Q! = P0) Do begin P: = next [p]; print (p, q); While (area (p, next [p], next [Q])> area (p, next [p], q) Do begin Q: = next [Q]; If (p, q )! = (Q0, P0) then print (p, q) else return end; If (area (p, next [p], next [Q]) = Area (p, next [p], q) then if (p, q )! = (Q0, P0) then print (p, next [Q]) else print (next [p], q) endend.
HerePrint (p, q)
Indicates(P, q)As a pair of vertex-to-output,Area (P, Q, R)
TrianglePqrOf the forward area.
Although this process is different from the conventional rotary jamming algorithm, they are essentially the same and avoid all angle calculations.
The following is a more intuitive algorithm:
- Calculate a polygonYThe endpoint in the direction. We call itYminAndYmax.
- PassYminAndYmaxConstruct two horizontal tangent lines. Since they are already pair of vertex, the distance between them is calculated and maintained as the current maximum value.
- Rotate two lines at the same time until one of them overlaps with one side of the polygon.
- A new pair of vertex points is generated at this time. Calculate the new distance and compare it with the current maximum value. If it is greater than the current maximum value, it is updated.
- Repeat steps 3 and 4 until a pair of vertex points is generated again.(Ymin, Ymax).
- Output a pair of vertices that determine the maximum diameter.
So far, the above process (in pseudo-code) is very useful. We can get other information from the trim point, such as the width of the polygon.
Http://cgm.cs.mcgill.ca /~ Orm/diam.html
Please indicate the source for reprinting. Thank you!