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

Daniel Richards D.Richards@mmu.ac...
Sun Feb 5 08:36:28 CST 2012

```Hi Pauli,

This is great, it works! Thanks for the help.

Dan

________________________________________
From: scipy-user-bounces@scipy.org [scipy-user-bounces@scipy.org] on behalf of Pauli Virtanen [pav@iki.fi]
Sent: 04 February 2012 15:53
To: scipy-user@scipy.org
Subject: Re: [SciPy-User] scipy.spatial.Delaunay.convex_hull problelm

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)])