On 28 April 2011 08:51, Luke <hazelnu...@gmail.com> wrote:
> I have a set of unstructured (x,y) points which I would like to
> compute a boundary polygon for. I don't want the convex hull.
>
> I was able to use matplotlib.tri to get a Delaunay triangulation for
> my points by following the examples online, but I'm having trouble
> masking everything but the triangles with a boundary edge.
> Additionally, once I get this, I'm not clear on how to plot just the
> boundary.
>
> Here is what it seems like the mask should be, assume triang comes
> from matplotlib.tri.Triangulation().
>
> mask = np.where(np.where(triang.neighbors < 0, 0, 1).all(axis=1), 1, 0)
> triang.set_mask(mask)
>
> but, when I plot triang using plot.triplot(), or plt.plot() to plot
> the edges, I am getting a bunch of extra stuff that isn't just the
> boundary triangles/edges.
>
> Anybody have example code for properly masking and plotting only the
> boundary edges?
>
> ~Luke
>
Luke,
I am not entirely clear exactly what you want to do, but I'll try to help.
Your masking of the triangulation masks the triangles not the edges, and so
your triplot call displays those triangles that include a boundary edge but
also the other edges of those triangles. As you say, this isn't what you
want.
I've attached an example script that follows on from your idea of testing
triang.neighbors to determine the boundary edges, and displays just those
edges. However, this is the convex hull as, by definition, the boundary of
an unconstrained Delaunay triangulation is the convex hull. As you don't
want the convex hull, I am not clear what you want instead.
If I have misunderstood your requirements and/or you have further questions,
please post your example code as it is much easier for others on the mailing
list to correct existing code than come up with their own freestanding
example.
I hope some of this helps!
Ian Thomas
import matplotlib.pyplot as plt
import matplotlib.tri as tri
import numpy as np
# Create triangulation of random (x,y) points.
np.random.seed(0)
x = np.random.rand(10)
y = np.random.rand(10)
triang = tri.Triangulation(x, y)
# Determine which triangulation edges are boundary edges; these
# correspond to edges that have no neighboring triangle. Store them as
# pairs of (start,end) point indices.
# This is all calculated long-hand to demonstrate the logic. It could
# be simplified by rewriting in a more pythonic way.
boundaries = []
for i in range(len(triang.triangles)):
for j in range(3):
if triang.neighbors[i,j] < 0:
# Triangle edge (i,j) has no neighbor so is a boundary edge.
boundaries.append((triang.triangles[i,j],
triang.triangles[i,(j+1)%3]))
boundaries = np.asarray(boundaries)
# The following line plots the boundary edges.
plt.plot(x[boundaries].T, y[boundaries].T, 'b-')
plt.plot(x, y, 'bo')
plt.show()
------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network
management toolset available today. Delivers lowest initial
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users