将矩形分解为随机形状的多边形

发布于 2024-10-05 16:40:24 字数 350 浏览 0 评论 0原文

就像标题所说,我需要将一个矩形分解成随机形状的多边形。

例如,有 7 个多边形:

+--------+--------+
|\       |   2    |
| \  1   |''--..__|
|  ------|  5     |
| 3  /   \________|
|   /    /\   6   |
|__/ 4  /  \______|
|      /  7       |
+-----+-----------+

我不知道是否已经有一个算法可以解决这个问题,但我似乎无法理解这个问题。

我并不特别关心你用什么语言回答,但我将用 Java/Swing 来实现。

Just like the title says, I need to break a rectangle into randomly shaped polygons.

Example, with 7 polygons:

+--------+--------+
|\       |   2    |
| \  1   |''--..__|
|  ------|  5     |
| 3  /   \________|
|   /    /\   6   |
|__/ 4  /  \______|
|      /  7       |
+-----+-----------+

I don't know if there's an algorithm already out there for this, but I can't seem to get my head around this.

I don't particularly care what language you answer in, but I'll be implementing in Java/Swing.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

溺ぐ爱和你が 2024-10-12 16:40:24

您可以在矩形上放置一堆随机点,并计算 Voronoi 图。

这是一个 Java/Swing 实现。

我做了一些示例(但是使用 Mathematica,而不是上面的实现)

< img src="https://i.sstatic.net/627Bj.png" alt="替代文本">

替代文本

alt text

哈!

You may drop a bunch of random points on the rectangle, and calculate the Voronoi Diagram.

Here is a Java/Swing implementation.

I did some samples (but using Mathematica, not the above implementation)

alt text

alt text

alt text

HTH!

花期渐远 2024-10-12 16:40:24

我会在整个矩形上绘制一堆随机线,然后在每个线交叉点“分割”这些线,这样你基本上就有了某种线网。然后根据需要删除任意数量的随机线段,直到达到所需的多边形数量。

编辑:所以对于您的示例,添加行后会是这样的:

+----+---+----+---+
|\'--.\_/|   /    |
| \    X |''/-..__|
|--\--+-\+-/------|
|___\/___\/_______|
|   /\   /\       |
|__/__\_/|_\______|
| /    X |  \     |
++----+-++---+----+

I'd draw a bunch of random lines across the full rectangle and then "split" the lines at each line intersection, so that you basically have some kind of net of lines. Then remove as many random line segments as you like until you reach the desired number of polygons.

Edit: So for your sample it would have been like this after adding the lines:

+----+---+----+---+
|\'--.\_/|   /    |
| \    X |''/-..__|
|--\--+-\+-/------|
|___\/___\/_______|
|   /\   /\       |
|__/__\_/|_\______|
| /    X |  \     |
++----+-++---+----+
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文