5

I'm trying to work on some datasets using the scipy.spatial.Delaunay object. But the problem is that I'm not able to set a maximum triangle side lenght. I would like to do something like How to set maximum length of triangle side in Delaunay triangulation?, but in Python

Krogiar
  • 137
  • 2
  • 7

1 Answers1

5

Here is some code that separates large edges from small:

# Computing Delaunay
tri = Delaunay(points)

# Separating small and large edges:
thresh = 1.0  # user defined threshold
small_edges = set()
large_edges = set()
for tr in tri.vertices:
    for i in xrange(3):
        edge_idx0 = tr[i]
        edge_idx1 = tr[(i+1)%3]
        if (edge_idx1, edge_idx0) in small_edges:
            continue  # already visited this edge from other side
        if (edge_idx1, edge_idx0) in large_edges:
            continue
        p0 = points[edge_idx0]
        p1 = points[edge_idx1]
        if np.linalg.norm(p1 - p0) <  thresh:
            small_edges.add((edge_idx0, edge_idx1))
        else:
            large_edges.add((edge_idx0, edge_idx1))

# Plotting the output
figure()
plot(points[:, 0], points[:, 1], '.')
for i, j in small_edges:
    plot(points[[i, j], 0], points[[i, j], 1], 'b')
for i, j in large_edges:
    plot(points[[i, j], 0], points[[i, j], 1], 'c')

On the data generated from the following code, I get this figure: enter image description here

# Constructing the input point set
np.random.seed(0)
x = 3.0 * np.random.rand(1000)
y = 2.0 * np.random.rand(1000) - 1.0
inside = ((x ** 2 + y ** 2 > 1.0) & ((x - 3) ** 2 + y ** 2 > 1.0) & ((x-1.5) ** 2 + y ** 2 > 0.09))
points = np.vstack([x[inside], y[inside]]).T
Iddo Hanniel
  • 1,636
  • 10
  • 18