Input: points set of carbon foam: S1 = {P[n] = (P[n]. x, P[n]. y)}. |
Output: the maximum diameter of each carbon foam. |
Initialization: U and L as distance thresholds between two points; Cross as the cross product. |
1: Set the value of U and L; |
2: M_temp: =0; j: = n-i; |
begin |
for i: =0 to n/2 do |
begin |
while Cross(P[i+1] - P[i], P [(k: =1) +1] – P[i]) > Cross(P[i+1] - P[i], P[k] – P[i]) do |
begin |
k = (k+1) % n; |
M = max (M_temp, max (the distance between P[i], P[k] and P[i+1], P[k+1])); |
end |
if L≤M≤U then |
begin |
delete P[k+1]; |
M = M_temp; |
end |
M_temp = M; |
end |
3: Operation in the reverse direction; |
while Cross(P[j+1] - P[j], P [k+1] – P[j]) > Cross(P[j+1] - P[j], P[k] – P[j]) do |
begin |
k = (k+1) % n; |
M = max (M_temp, max (the distance between P[j], P[k] and P[j+1], P[k+1])); |
end |
if L≤M≤U then |
begin |
delete P[k+1]; |
M = M_temp; |
end |
M_temp = M; |
end |
4: Get the Convex Hull (CH). |
5: Get points set of Convex Hull: S2 = {P[n]/Q[n] = (P[n]/Q[n]. x, P[n]/Q [n]. y)}; |
6: Find the convex hull's two extreme points: P1[n] and Q1[n], Construct two horizontal lines of support through P1[n] and Q1[n]; |
7: Compute the distance between P1[n] and Q1[n], and mark it as Distance; |
8: Rotate the lines until one is flush with an edge of CH, and obtain an anti-podal pair; |
9: compute the distance, and mark it as Distance_temp; |
begin |
while anti-podal pair! = P1[n] and Q1[n] do |
if Distance_temp > Distance then |
Distance: = Distance_temp |
end |
10: Determining the maximum as the diameter pair(s). |