网格上一组块的空间组织

发布于 2024-09-29 16:51:54 字数 343 浏览 4 评论 0原文

我有一个单元格网格(一开始为空),以及一组块,这些块是矩形或正方形,其大小是单元格的倍数(例如,一个块可能是 2 个单元格 x 3 个单元格)。我不会提前知道所有的方块,但必须在它们到达时将它们放置好。如果有人想知道,这与将一堆较小的位图放置在一个大的位图上有关,其中所有位图的大小都是 32 的倍数。

我一直在想我可以简单地遍历网格,寻找一个位置来适应这个块,如果我找到一个地方,就把它放在那里。我还可以有一个四叉树来跟踪网格的哪些块被占用,所以我不必多次迭代已经分配的单元格。

我尝试过在谷歌上搜索示例和解决方案,但由于英语不是我的母语,因此我很难明确要搜索的内容。

所以我的问题是使用什么算法和数据结构来解决这类问题?

I have a grid of cells (empty at beginning), and a collection of blocks which are rectangles or squares whose size are a multiple of a cell (for example, a block might be 2 cells by 3 cells). I won't know all the blocks in advance, but will have to place them as they arrive. In case anyone's wondering, this has to do with placing a bunch of smaller bitmaps on a large one, where all the bitmaps's sizes are a multiple of 32.

I've been thinking that I could simply iterate through the grid, looking for a place to fit the block, and if I find a place, put it there. I could also have a quadtree that keeps tracks of which chunks of the grid are occupied, so I don't have to iterate through already allocated cells much.

I've tried googling for examples and solutions, but since English is not my native language, I've had trouble formulating what I want to search for.

So my question is what algorithms and data structures are used for this kinds of problems?

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

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

发布评论

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

评论(1

堇年纸鸢 2024-10-06 16:51:54

您正在搜索有关所谓“装箱”的信息(请参阅 http://en.wikipedia.org/ wiki/Bin_packing_problem),更准确地说,是问题的 2D 版本,更具体地说,是“纹理打包”。

您可能想看看那里:https://gamedev.stackexchange.com/questions/2829/texture -packing-algorithm(参考的几种算法和数据结构)

如果你实在有动力,也可以看看这方面的文章!

http://citeseerx. ist.psu.edu/viewdoc/download?doi=10.1.1.98.3502&rep=rep1&type=pdf

http://citeseerx.ist.psu.edu/search?q=texture+packing&submit=Search&sort=rel

You are searching information on what is called "bin packing" (see http://en.wikipedia.org/wiki/Bin_packing_problem), more precisely, the 2D version of the problem, and even more specificaly, "texture packing".

You might want to have a look there: https://gamedev.stackexchange.com/questions/2829/texture-packing-algorithm (several algorithms and data structures referenced)

If you are really motivated, you can also look at the articles on the subject!

http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.98.3502&rep=rep1&type=pdf

http://citeseerx.ist.psu.edu/search?q=texture+packing&submit=Search&sort=rel

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