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

Daniel Richards D.Richards at mmu.ac.uk
Sun Feb 5 09:36:28 EST 2012


Hi Pauli,

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

Dan


________________________________________
From: scipy-user-bounces at scipy.org [scipy-user-bounces at scipy.org] on behalf of Pauli Virtanen [pav at iki.fi]
Sent: 04 February 2012 15:53
To: scipy-user at 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)])
ax.add_collection(items)
ax.scatter(points[:,0], points[:,1], points[:,2], 'o')
plt.show()

_______________________________________________
SciPy-User mailing list
SciPy-User at scipy.org
http://mail.scipy.org/mailman/listinfo/scipy-user
"Before acting on this email or opening any attachments you should read the Manchester Metropolitan University email disclaimer available on its website http://www.mmu.ac.uk/emaildisclaimer "



More information about the SciPy-User mailing list