如何在 Python 中创建一个随机的圆圈数组,而不重叠? [英] How to create a random array of circles in Python, without overlapping?

查看:60
本文介绍了如何在 Python 中创建一个随机的圆圈数组,而不重叠?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在 Python 中创建一些不重叠的圆圈.

I would like to know how to create some circles without overlapping in Python.

让我分享我的脚本的一部分

Let me share a part of my script

在第 55,56 和 57 行,我打印了坐标,见证了重叠.在每个 for 语句中,我认为我避免了重叠,例如二分法(求根法).

In lines 55,56 and 57 I print the coordinates, witnessing overlapping. Inside each for statement I thought I avoided the overlapping doing something like bisection method (root finding method).

源代码适用于 5 或​​ 6 个空洞,但当增加空洞数量时,我会重叠.

The source code works good for 5 or 6 voids but when increasing the number of voids I get overlapping.

推荐答案

您的最大半径为 B=10.因此,假设您想要以最大半径分隔的点,您可以使用 Poisson 对这些点进行采样磁盘算法.

Your maximum radius is B=10. So assuming you want points separated by maximum radius, you could sample such points using Poisson disk algorithm.

然后,采样中心,围绕每个中心绘制随机半径,它们不会重叠,因为所有半径都小于您的最大值.

Then, having sampled centers, draw random radius around each center, and they wont overlap because all radii are smaller than your max.

这篇关于如何在 Python 中创建一个随机的圆圈数组,而不重叠?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆