How to get the maximum distance between a polygons centroid and its outer ring?

Viewed 477

I got the centroid x_0, y_0 of a polygon and two lists of points list_x, list_ywhich represent the row and column indexes of vertices for my polygon, respectively. They were obtained from a 2D semantic mask using shapely. How can i find the maximum distance between my polygon and the polygon centroid using python?

1 Answers

You can simply do :

max_dist = 0
for i in range(len(list_x)):
    dist = (abs(list_x[i]-x_0)**2 + abs(list_y[i]-y_0)**2)**0.5
    if dist > max_dist:
        max_dist = dist

# max_dist should know be the maximum distance to centroid

Related