rambalachandran
rambalachandran

Reputation: 2211

Python library to calculate surface area and volume of an arbirary polyhedron

If I have an array of coordinates of the vertices of an arbitrary polyhedron, is there a library (preferably in python) that can calculate the surface area and volume of that polyhedron. The approach for these calculations appear established, but I could not find a library that has implemented this. More specifically, if I give the coordinates of a regular octahderon

arr1 = [[1,0,0],[-1,0,0],[0,1,0], [0,-1,0], [0,0,1], [0,0,-1]],

the code must return me a volume of

4/3 (formula: sqrt(2)*a^3/4)

Upvotes: 2

Views: 2834

Answers (1)

rambalachandran
rambalachandran

Reputation: 2211

As long as the polyhedron is convex (which is my current interest), scipy has a class ConvexHull that can calculate both area and volume. For example, the volume for the above scenario can be calculated as follows

import numpy as np
from scipy.spatial import ConvexHull
arr1 = [[1,0,0],[-1,0,0],[0,1,0], [0,-1,0], [0,0,1], [0,0,-1]]
arr1 = np.asarray(arr1)
volume = ConvexHull(arr1).volume
print volume

The above code produces the correct volume of 1.33333

Upvotes: 3

Related Questions