Commit d9e3725c by Jigyasa Watwani

fixed bug in perimeter calculation

parent 07690244
Showing with 5 additions and 1 deletions
...@@ -7,7 +7,11 @@ from scipy.spatial import ConvexHull ...@@ -7,7 +7,11 @@ from scipy.spatial import ConvexHull
def perimeter(X, Y): def perimeter(X, Y):
points = np.column_stack((X, Y)) points = np.column_stack((X, Y))
hull = ConvexHull(points) hull = ConvexHull(points)
value = sum(np.linalg.norm(points[hull.vertices[i]] - points[hull.vertices[(i+1)%len(hull.vertices)]]) for i in range(len(hull.vertices))) N = len(hull.vertices)
value = 0
for i in range(N):
value += np.linalg.norm(points[hull.vertices[i]] - points[hull.vertices[(i+1)%N]])
# The (i+1)%N part ensures that after the last vertex, we go back to the first vertex, creating a closed loop
return value return value
def long_axis(x, y): def long_axis(x, y):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment