General formula for calculating the volume of a polyhedron

Given the list of vertices ( v) and the list of edges connecting the vertices ( e) and the list of surfaces connecting the edges ( s), how to calculate the volume of the Polyhedron?

+5
source share
5 answers
  1. Take the polygons and divide them into triangles.
  2. Consider the tetrahedron formed by each triangle and an arbitrary point (origin).
  3. Sum the signed volumes of these tetrahedrons.

Notes:

  1. This will only work if you can maintain a consistent CW or CCW order for triangles when viewed from the side.
  2. The volume with a tetrahedron sign is 1/6 of the determinant of the following matrix:

[x1 x2 x3 x4]
[y1 y2 y3 y4]
[z1 z2 z3 z4]
[1 1 1 1]

- (x, y, z, 1).

, , , , .

, 1/6 .

+8

, , . , .

( , /, , .
http://mathoverflow.net)

+2

-, , .

, "" ( ). , . {h1, h2, h3} - , A - , A (h1 + h2 + h3)/3. , .

, , . , .

, (1) (2) "" "". , , , , . , . xy . , , .

, ? , , , , . , . , -1 ( , , ).

: ! , , , . , , .

+1

, , , . , . TetGen, . , . TetGen , CGAL , . CGAL , .

+1

Here's a potential implementation for Python. Can anyone check if this is correct? I believe that I don’t have enough permutations of the points, because my second test (cube) gives 0.666, not 1. Ideas anyone?

Greetings EL

class Simplex(object):
    '''
    Simplex
    '''


    def __init__(self,coordinates):
        '''
        Constructor
        '''

        if not len(coordinates) == 4:
            raise RuntimeError('You must provide only 4 coordinates!')

        self.coordinates = coordinates



    def volume(self):
        '''
        volume: Return volume of simplex. Formula from http://de.wikipedia.org/wiki/Tetraeder
        '''
        import numpy

        vA = numpy.array(self.coordinates[1]) - numpy.array(self.coordinates[0])
        vB = numpy.array(self.coordinates[2]) - numpy.array(self.coordinates[0])
        vC = numpy.array(self.coordinates[3]) - numpy.array(self.coordinates[0])

        return numpy.abs(numpy.dot(numpy.cross(vA,vB),vC)) / 6.0  


class Polyeder(object):

    def __init__(self,coordinates):
        '''
        Constructor
        '''

        if len(coordinates) < 4:
            raise RuntimeError('You must provide at least 4 coordinates!')

        self.coordinates = coordinates


    def volume(self):

        pivotCoordinate = self.coordinates[0]

        volumeSum = 0

        for i in xrange(1,len(self.coordinates)-3):

            newCoordinates = [pivotCoordinate]

            for j in xrange(i,i+3):
                newCoordinates.append(self.coordinates[j])

            simplex = Simplex(newCoordinates)
            volumeSum += simplex.volume()

        return volumeSum


coords = []

coords.append([0,0,0])
coords.append([1,0,0])
coords.append([0,1,0])
coords.append([0,0,1])

s = Simplex(coords)
print s.volume()

coords.append([0,1,1])
coords.append([1,0,1])
coords.append([1,1,0])
coords.append([1,1,1])

p = Polyeder(coords)
print p.volume()
0
source

All Articles