### Fiddles

Calculate the volume of on object given by a set of points.

Object: Volume: calculated actual

The volume is calculated by using the Divergence theorem.

$\displaystyle\iiint_V\left(\mathbf{\nabla}\cdot\mathbf{F}\right)\,dV= \iint_S (\mathbf{F}\cdot\mathbf{n})\,dS$

where the left hand integral is over the internal volume and the right hand integral is over the surface, $\mathbf{n}$ is the outward unit length surface normal, $\nabla$ is the divergence, $\operatorname{div}\,\mathbf{F} = \nabla\cdot \mathbf{F} = \left(\frac{\partial}{\partial x}, \frac{\partial}{\partial y},\frac{\partial}{\partial z}\right) \cdot \mathbf{F}$

If $F$ is the field giving the position vector $\mathbf{F}(x,y,z) = x\mathbf{i} + y\mathbf{j} + z\mathbf{k}$ then $\operatorname{div}\,\mathbf{F} = 3$, so the left hand integral is just $\iiint_V 3\,dV$, three times the volume.

Hence to find the volume of a surface we just need to calculate $\iint_S (\mathbf{F}\cdot\mathbf{n})\,dS$. If the surface is polyhedron with set pologonal faces $P_1, \ldots P_n$ the integral can be reduced to a sum over all the faces. The dot product $\mathbf{F} \cdot \mathbf{n}$ is constant for all points on the face, so the integral over any face $P$ is just $area(P)\ \mathbf{v} \cdot \mathbf{n}$ where $\mathbf{v}$ is any vertex on the surface. Hence the volume is given by

$\displaystyle\frac13 \sum_{i=1}^n area(P_i)\ \mathbf{v}_i \cdot \mathbf{n}_i$

where $\mathbf{v}_i$ is a vectex of the i-th face and $\mathbf{n}_1, \ldots, \mathbf{n}_n$ are the outward pointing normals.

If $\mathbf{a}_i$, $\mathbf{b}_i$, $\mathbf{c}_i$ are the three vertices of a triangular face the (non unit length) normal can be calculate as $\mathbf{n}_i = (\mathbf{b}_i-\mathbf{a}_i)\times(\mathbf{c}_i-\mathbf{a}_i)$. The unit length normal is $\hat{\mathbf{n}}_i = \mathbf{n}_i/ |\mathbf{n}_i|$ and area of the triangle is $\frac12|\mathbf{n}_i|$. The dot product becomes $\mathbf{a}_i \cdot \hat{\mathbf{n}}_i$. The whole volume becomes

$\displaystyle\frac16 \sum_{i=1}^n \pm \mathbf{a}_i \cdot \mathbf{n}_i$,

where the signs are chosen so the normals are outwards.

### vectex of the ith face

David Seed Fri Jun 17 2016

please give a simple workd example. with a diagram i presume you mean any vertex in the i-th face and that v.n represents the vertical dstance from the face to the origin. but perhaps the outward facng sense requires the origin to be outside the solid i dont