# volume

## `volume(V, T)`

Computes a vector containing the volumes of all tetrahedra in a mesh

Parameters:

Name Type Description Default
`V` `numpy double array`

Matrix of mesh vertex position coordinates

required
`T` `numpy double array`

Matrix of mesh tetrahedra indices into V

required

Returns:

Name Type Description
`vols` `numpy double array`

Vector of per-tetrahedron volumes

doublearea

Examples:

``````v = np.array([[0.0,0.0,0.0],
[1.0,0.0,0.0],
[0.0,1.0,0.0],
[0.0,0.0,1.0]
])
# This tet is properly oriented
t = np.array([[0,1,2,3]])
vols = gpytoolbox.volume(v,t)
# This volume should be 1/6
``````
Source code in `src/gpytoolbox/volume.py`
 ``` 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46``` ``````def volume(V,T): """Computes a vector containing the volumes of all tetrahedra in a mesh Parameters ---------- V : numpy double array Matrix of mesh vertex position coordinates T : numpy double array Matrix of mesh tetrahedra indices into V Returns ------- vols : numpy double array Vector of per-tetrahedron volumes See Also -------- doublearea Examples -------- ```python v = np.array([[0.0,0.0,0.0], [1.0,0.0,0.0], [0.0,1.0,0.0], [0.0,0.0,1.0] ]) # This tet is properly oriented t = np.array([[0,1,2,3]]) vols = gpytoolbox.volume(v,t) # This volume should be 1/6 ``` """ # Dimension: a = V[T[:,0],:] b = V[T[:,1],:] c = V[T[:,2],:] d = V[T[:,3],:] vols = -np.sum(np.multiply(a-d,np.cross(b-c,c-d,axis=1)),axis=1)/6. return vols ``````