-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_sample_points.py
More file actions
43 lines (36 loc) · 1.06 KB
/
generate_sample_points.py
File metadata and controls
43 lines (36 loc) · 1.06 KB
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
38
39
40
41
42
43
import numpy as np
from matplotlib import pyplot as plt
n = 10
domain_size = 0.2
delta = 0.04
delta_boundary = 0.01
rng = np.random.default_rng(seed=2351254)
points = []
while len(points) < n:
p_new = rng.uniform(low=0, high=domain_size, size=(2))
# discard points that are too close to the boundary of the domain
if (
(p_new[0] < delta_boundary)
or (domain_size - p_new[0] < delta_boundary)
or (p_new[1] < delta_boundary)
or (domain_size - p_new[1] < delta_boundary)
):
continue
for p in points:
if (p_new[0] - p[0]) ** 2 + (p_new[1] - p[1]) ** 2 < delta**2:
break
else:
points.append(p_new)
points = np.asarray(points)
plt.clf()
plt.plot(
points[:, 0], points[:, 1], linewidth=0, marker="o", markersize=4, color="blue"
)
ax = plt.gca()
ax.set_xlim(0, domain_size)
ax.set_ylim(0, domain_size)
plt.savefig("points.pdf", bbox_inches="tight")
print("[", end="")
for j, p in enumerate(points):
print(f"[{p[0]:.3f},{p[1]:.3f}]", end="," if j < len(points) - 1 else "")
print("]")