# [SciPy-User] scipy.spatial.Delaunay.convex_hull problelm

Pauli Virtanen pav@iki...
Sat Feb 4 09:53:05 CST 2012

```04.02.2012 14:13, Pauli Virtanen kirjoitti:
> 04.02.2012 11:48, Dan Richards kirjoitti:
> [clip]
>> This allows me to create a three-dimensional tetragedron. I had thought
>> to find the 3D convex hull could simply change either: “v = x.verticies”
>> into “v=x.*convex_hull*” ; or “Del = scipy.spatial.Delaunay (Points)”
>> into “Del = scipy.spatial.Delaunay.*convex_hull*(Points)”.However,
>> neither of these have worked as planned?
>
> Elements of the convex hull are triangles, not tetrahedra, so you need
> to change the code also below.
>
> for i1, i2, i3 in Del.convex_hull:
>       faces.extend([(v[i1,0], ............), .... (.... v[i3,3]),])

Like so:

import numpy as np
from scipy.spatial import Delaunay

points = np.random.randn(300, 3)
tri = Delaunay(points)

# -- Make a list of faces, [(p1, p2, p3), ...];  pj = (xj, yj, zj)

faces = []
for ia, ib, ic in tri.convex_hull:
faces.append(points[[ia, ib, ic]])

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from mpl_toolkits.mplot3d.art3d import Poly3DCollection

fig = plt.figure()
ax = fig.gca(projection='3d')
items = Poly3DCollection(faces, facecolors=[(0, 0, 0, 0.1)])