-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen.py
36 lines (29 loc) · 911 Bytes
/
gen.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
import csv
import numpy as np
import matplotlib.pyplot as plt
# centers = []
points = []
# centers.append(np.random.randn(2))
# centers.append(np.random.randn(2) + 2)
# centers.append(np.random.randn(2) + 3)
# centers.append(np.random.randn(2) + 1.5)
# centers.append(np.random.randn(2) + 2.3)
for i in range(300):
r = np.random.uniform(0.0, 1)
theta = np.random.uniform(0, 6.28)
points.append(np.array([r * np.cos(theta), r * np.sin(theta)]))
for i in range(300):
r = np.random.uniform(0.0, 1.0)
theta = np.random.uniform(0, 6.28)
p = np.array([r * np.cos(theta), r * np.sin(theta)])
u = p/np.linalg.norm(p)
u *= 2
points.append(p + u)
print(points[0])
with open("example2.csv", 'w', newline='') as f:
wr = csv.writer(f)
wr.writerow([0, 1])
for i in points:
wr.writerow(i)
plt.plot([p[0] for p in points], [p[1] for p in points], 'ro')
plt.show()