A convex body is simply a convex polygon , so you can easily try {this} or {this} to find the area of ββa two-dimensional polygon.
Something like the following (our version):
def PolyArea2D(pts): lines = np.hstack([pts,np.roll(pts,-1,axis=0)]) area = 0.5*abs(sum(x1*y2-x2*y1 for x1,y1,x2,y2 in lines)) return area
in which pts is an array of polygonal vertices, i.e. array (nx2).
Full use:
import numpy as np def PolyArea2D(pts): lines = np.hstack([pts,np.roll(pts,-1,axis=0)]) area = 0.5*abs(sum(x1*y2-x2*y1 for x1,y1,x2,y2 in lines)) return area pts = [[0,0],[1,0],[1,1],[0,1]] print PolyArea2D(pts) pts = [[0,0],[1,0],[0,1]] print PolyArea2D(pts) pts = [[0,0],[1,0],[0.5,0.5]] print PolyArea2D(pts) >>> 1.0 0.5 0.25