Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating regular Delaunay grid in with scipy

Is there some method to get a triangulation in 2D that is more ordered like Matlab Delaunay produces? Here is an example of Matlab's 2D Delaunay triangulation.

matlab delaunay

Using this code:

xPoints = np.arange(0,11,1)
yPoints = np.arange(0,11,1)
gridPoints = np.array([[x,y] for y in yPoints for x in xPoints])
tri = Delaunay(gridPoints)
plt.triplot(gridPoints[:,0],gridPoints[:,1],tri.simplices.copy())
plt.plot(gridPoints[:,0],gridPoints[:,1],'bo')
plt.title("Triangulation Visualization")

I get the triangulation below:

scipy delaunay

Notice how diagonal arcs in the Matlab result all have the same slope; but those in the scipy result are varying. Since Matlab and Scipy both use QHull internally, I presume there is some method to mimic the Matlab result.

like image 683
Vance T Avatar asked Apr 27 '15 04:04

Vance T


1 Answers

You could try Triangulation instead of Delaunay:

import matplotlib.tri as tri

xlen = 10
ylen = 16
xPoints = np.arange(0,xlen+1,1)
yPoints = np.arange(0,ylen+1,1)

gridPoints = np.array([[[x,y] for y in yPoints] for x in xPoints])
a = [[i+j*(ylen+1),(i+1)+j*(ylen+1),i+(j+1)*(ylen+1)] for i in range(ylen) for j in range(xlen)]
triang = tri.Triangulation(gridPoints[:,:,0].flatten(), gridPoints[:,:,1].flatten(),a)

plt.triplot(triang)
plt.plot(gridPoints[:,:,0],gridPoints[:,:,1],'bo')
plt.title("Triangulation Visualization")

enter image description here

like image 142
Vlad Mironov Avatar answered Nov 18 '22 00:11

Vlad Mironov