0

I must be missing something incredibly obvious, but there seems to be a huge difference in the area computed by scipy.ConvexHull.area compared to shapely.convex_hull.area. I get

Scipy Convex Hull Area: 457761.9061526276, Shapely Convex Hull Area: 13192154623.86528

from shapely.geometry import MultiPoint
from scipy.spatial import ConvexHull
import json


def convex_hull_compare():
    with open("./test_points.json", 'r') as f:
        points = json.load(f)
        print(points)
        hull = ConvexHull(points)
        ch_area = MultiPoint(points).convex_hull.area

        print(
            f"Scipy Convex Hull Area: {hull.area}, Shapely Convex Hull Area: {ch_area}")
        # Scipy Convex Hull Area: 457761.9061526276, Shapely Convex Hull Area: 13192154623.86528


if __name__ == "__main__":
    convex_hull_compare()

I've uploaded the test_points.json on a Github Gist here and written a minimal version of the code for easy reproduction.

Lieu Zheng Hong
  • 676
  • 1
  • 10
  • 22

1 Answers1

1

A helpful commenter linked the following question: the gist of it is that for 2D points, we want ConvexHull.volume, not ConvexHull.area.

This indeed gives us the right answer, but this is really confusing because the documentation doesn't mention this at all.

from shapely.geometry import MultiPoint
from scipy.spatial import ConvexHull
import json


def convex_hull_compare():
    with open("./test_points.json", 'r') as f:
        points = json.load(f)
        print(points)
        hull = ConvexHull(points)
        ch_area = MultiPoint(points).convex_hull.area

        print(
            f"Scipy Convex Hull Area: {hull.area}, Shapely Convex Hull Area: {ch_area}")
        # Scipy Convex Hull Area: 457761.9061526276, Shapely Convex Hull Area: 13192154623.86528

        print(
            f"Scipy Convex Hull Area: {hull.volume}, Shapely Convex Hull Area: {ch_area}")
        #Scipy Convex Hull Area: 13192154623.865295, Shapely Convex Hull Area: 13192154623.86528


if __name__ == "__main__":
    convex_hull_compare()
Lieu Zheng Hong
  • 676
  • 1
  • 10
  • 22
  • The documentation does explain it: see my answer here https://stackoverflow.com/a/65660582/1048456 – Vic Jan 11 '21 at 02:22