forked from dantros/grafica
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex_delaunay.py
37 lines (27 loc) · 833 Bytes
/
ex_delaunay.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# coding=utf-8
"""
Using Delaunay triangluation from the scipy library
documentation:
https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.spatial.Delaunay.html
"""
import numpy as np
from scipy.spatial import Delaunay
import matplotlib.pyplot as mpl
__author__ = "Daniel Calderon"
__license__ = "MIT"
#points = np.array([[0, 0], [0, 1.1], [1, 0], [1, 1]])
points = np.random.rand(20,2)
print("Random 2D points:")
print(points)
# Computing the Delaunay triangulation
tri = Delaunay(points)
# Plotting the triangulation => triplot
fig, axs = mpl.subplots(1,2)
axs[0].plot(points[:,0], points[:,1], 'o')
axs[0].set_xlabel('x')
axs[0].set_ylabel('y')
axs[1].triplot(points[:,0], points[:,1], tri.simplices.copy())
axs[1].plot(points[:,0], points[:,1], 'o')
axs[1].set_xlabel('x')
axs[1].set_ylabel('y')
mpl.show()