11/28/2021

python polygon list to rectangle

 refer to below code:

--

def returnRect(ploygon):
x_list = []
y_list = []
for v in polygon:
x_list.append(v[0])
y_list.append(v[1])

left = min(x_list)
right = max(x_list)
top = min(y_list)
bottom = max(y_list)
return left, top, right, bottom

polygon = [[776.1818181818181, 221.2121212121212], [895.8787878787879, 219.6969696969697], [892.8484848484848, 198.48484848484847], [879.2121212121211, 146.96969696969697], [795.8787878787879, 150.0], [779.2121212121211, 160.6060606060606]]
x1,y1,x2,y2 = returnRect(polygon)
print(x1,y1,x2,y2)

--


Thank you.

www.marearts.com