Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import matplotlib.pyplot as plt
- import numpy as np
- from scipy.spatial import ConvexHull
- #a = [0, 1, 1j, 0.7+0.8j]
- #a = [0, 1, 2, 3, 4]
- #a = [0, 1] * 3
- #a = [0, 1, .5+.5j*3**.5] * 30
- a = [0, 1, 2] * 30
- p = np.array([1])
- for i, ai in enumerate(a):
- p = np.polyint(p)
- p = np.polysub(p, np.polyval(p, ai))
- r = np.roots(p)
- plt.plot(np.real(r), np.imag(r), 'o', label=str(ai))
- print('p', p, 'r', r)
- if i == 0:
- continue
- elif i == 1:
- plt.fill(np.real(r), np.imag(r), edgecolor="#000000", alpha=0.5)
- else:
- if i < 5 or i % 20 != 0: continue
- points = np.reshape(np.concatenate([np.real(r), np.imag(r)]),
- (len(r), 2), order='F')
- hull = ConvexHull(points)
- print('vert', hull.vertices)
- plt.fill(points[hull.vertices, 0], points[hull.vertices, 1],
- alpha=0.3)
- #plt.legend()
- plt.show()
Advertisement