python - Area of polygon calculation inconsistent -
i using voronoi_finite_polygons_2d(vor, radius=none) function found elsewhere on stackoverflow . want modify show centroid of each voronoi cell . debugging why centroids appear dramatically wrong (see green arror pointing out centroid way off in weeds). first error identified: of calculations weren't processing vertices in proper all-clockwise or all-counterclockwise order. not sure why points don't sorted correctly, before investigate that, found anomaly. i should same area (with opposite sign) if go clockwise or counterclockwise. in simple examples, do. in random polygon made, /slightly/ different results. import numpy np import matplotlib.pyplot plt scipy.spatial import voronoi import random import math def measure_polygon(vertices): xs = vertices[:,0] ys = vertices[:,1] xs = np.append(xs,xs[0]) ys = np.append(ys,ys[0]) #https://en.wikipedia.org/wiki/centroid#centroid_of_polygon area = sum(xs[i]*(ys[i+1]-ys[i-1]) in range(0, le...