擅长:python、mysql、java
<p>从几何学上讲,处于边缘要求一个点满足某些条件。假设我们讨论的网格的维度由<code>x ~ [0, a]</code>和<code>y ~ [0, b]</code>定义:</p>
<ul>
<li>y坐标为0或<code>b</code>,x坐标在<code>[0, a]</code>范围内,或</li>
<li>x坐标为0或<code>a</code>,y坐标位于<code>[0, b]</code></li>
</ul>
<p>显然有不止一种方法可以做到这一点,但这里有一个简单的方法让你开始</p>
<pre class="lang-py prettyprint-override"><code>def plot_edges(n_points, x_max, y_max, x_min=0, y_min=0):
# if x_max - x_min = y_max - y_min, plot a square
# otherwise, plot a rectangle
vertical_edge_x = np.random.uniform(x_min, x_max, n_points)
vertical_edige_y = np.asarray([y_min, y_max])[
np.random.randint(2, size=n_points)
]
horizontal_edge_x = np.asarray([x_min, x_max])[
np.random.randint(2, size=n_points)
]
horizontal_edge_y = np.random.uniform(x_min, x_max, n_points)
# plot generated points
plt.scatter(vertical_edge_x, vertical_edige_y)
plt.scatter(horizontal_edge_x, horizontal_edge_y)
plt.show()
</code></pre>