Created
November 10, 2022 10:28
-
-
Save marmakoide/4b0b1cf79b2bf1b40bd2080d8f89569c to your computer and use it in GitHub Desktop.
Computes the centroid (ie. center of mass) of a 2d convex hull
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy | |
from scipy.spatial import ConvexHull | |
def get_convex_hull_2d_centroid(hull): | |
C = numpy.zeros(2) | |
for i in range(hull.vertices.shape[0]): | |
Pi, Pj = hull.points[hull.vertices[i - 1]], hull.points[hull.vertices[i]] | |
C += numpy.cross(Pi, Pj) * (Pi + Pj) | |
return C / 6. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment