将矩形分解为随机形状的多边形
就像标题所说,我需要将一个矩形分解成随机形状的多边形。
例如,有 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在矩形上放置一堆随机点,并计算 Voronoi 图。
这是一个 Java/Swing 实现。
我做了一些示例(但是使用 Mathematica,而不是上面的实现)
< img src="https://i.sstatic.net/627Bj.png" alt="替代文本">
哈!
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)
HTH!
我会在整个矩形上绘制一堆随机线,然后在每个线交叉点“分割”这些线,这样你基本上就有了某种线网。然后根据需要删除任意数量的随机线段,直到达到所需的多边形数量。
编辑:所以对于您的示例,添加行后会是这样的:
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: