#! /usr/bin/env python3 # def delaunay_test ( ): from scipy.spatial import Delaunay import matplotlib.pyplot as plt import numpy as np points = np.loadtxt ( 'i18.txt' ) # # Display just the points. # plt.clf ( ) plt.plot ( points[:,0], points[:,1], 'o' ) for i in range ( 0, 18 ): s = str(i) plt.text ( points[i,0]+0.15, points[i,1]+0.15, s ) plt.grid ( 'True' ) plt.axis ( 'equal' ) filename = 'i18_points_labeled.png' plt.savefig ( filename ) print ( ' Graphics saved as "' + filename + '"' ) plt.show ( ) plt.close ( ) # # Display an arbitrary triangulation. # t = np.array ( [ \ [0,2,1], \ [0,1,17], \ [0,17,16], \ [1,2,3], \ [1,3,7], \ [1,7,8], \ [1,8,15], \ [3,6,7], \ [3,4,6], \ [4,11,6], \ [5,6,9], \ [5,9,8], \ [5,8,7], \ [5,7,6], \ [6,11,10], \ [6,10,9], \ [8,9,14], \ [8,14,13], \ [8,13,15], \ [9,10,11], \ [9,11,14], \ [11,12,14], \ [12,16,13], \ [12,13,14], \ [13,16,15], [15,16,17] ] ) plt.clf ( ) plt.triplot ( points[:,0], points[:,1], t ) plt.plot ( points[:,0], points[:,1], 'o' ) for i in range ( 0, 18 ): s = str(i) plt.text ( points[i,0]+0.15, points[i,1]+0.15, s ) plt.grid ( 'True' ) plt.axis ( 'equal' ) plt.title ( 'Arbitrary triangulation' ) filename = 'i18_triangulation_bad.png' plt.savefig ( filename ) print ( ' Graphics saved as "' + filename + '"' ) plt.show ( ) plt.close ( ) # # Display Delaunay triangulation. # tri = Delaunay ( points ) plt.clf ( ) plt.triplot ( points[:,0], points[:,1], tri.simplices ) plt.plot ( points[:,0], points[:,1], 'o' ) for i in range ( 0, 18 ): s = str(i) plt.text ( points[i,0]+0.15, points[i,1]+0.15, s ) plt.grid ( 'True' ) plt.axis ( 'equal' ) plt.title ( 'Delaunay triangulation' ) filename = 'i18_triangulation_delaunay.png' plt.savefig ( filename ) print ( ' Graphics saved as "' + filename + '"' ) plt.show ( ) plt.close ( ) return if ( __name__ == "__main__" ): delaunay_test ( )