瓷砖(可扩展)叠加算法 [英] Tile (scalable) stacking algorithm

查看:255
本文介绍了瓷砖(可扩展)叠加算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是问题所在。我有有1大小的矩形画布因此,有坐标(0.0 ... 1.0 - x和0.0 ... 1.0 - Y)SISTEM

Here is the problem. I have rectangular canvas that have size of 1. So it have coordinate sistem of (0.0 ... 1.0 - x and 0.0 ... 1.0 - y).

我也有一些瓦片。瓷砖也是矩形。它们具有不同势大小与瓦片的量是变量

I also have some tiles. Tiles are also rectangles. They have diffrent size and amount of tiles is a variable.

我想堆栈瓷砖长方形帆布,从0.0到1.0(从左至右,从上到下):

I want to stack tiles in rectangular canvas, from 0.0 to 1.0 (from left to right, from top to bottom):

1)瓷砖必须适应在画布上(但填充尽可能多的空间,因为他们可以)

1) tiles have to fit in canvas (but fill as much space as they could)

2)瓦块已被缩放(如果他们不适合),每一瓦片应该按相同的量缩放(它们必须保持相同的比例)。

2) tiles have to be scaled (if they don't fit), each tile should be scaled by the same amount (they have to remain same proportions).

3)假设你有你的手这个'砖',而你将它们放置在这个画布陆续

3) imagine that you have this 'tiles' in your hand, and you placing them into this canvas one after another

4)它几乎像TreeMap的算法但是 - 瓷砖形状必须是相同的(矩形)和我不需要填写帆布的所有空间

4) it almost like "TreeMap algorithm" but - shape of tiles have to be the same (rectangles) and i don't need to fill all space of canvas

是否有任何人谁可以告诉我一个algoritm在任何C语言一样(C,C ++,Java和C#)?

*我想这一点。

1)我计算出瓷砖的面积,然后我计算出瓷砖的面积之和(例如:我有两个砖,一是有面积2,其他1区,他们这是不是意味着我有3总和)

1) i calculated area of tile, then i calculate a sum of tile's areas (for example: i have two tiles, one have area of 2, other area of 1, them it's mean i have total sum of 3)

2),那么我算什么比每瓦有总面积之和(例如:2/3和1/3)

2) then i calculate what "proportion" each tile have in "total sum of areas" (for example: 2/3 and 1/3)

3)然后计算长方形砖大小的Math.sqrt(x)的(例如:的Math.sqrt(2/3))

3) then calculate size of rectangle tile by Math.sqrt(x) (for example: Math.sqrt(2/3))

4),然后由一个画瓷砖之一... ...

4) then draw tile one by one...

但是,这忽略了最低工作始终。有时我的瓷砖要出帆布.. *

But this dosen't work always. Sometimes i get tiles to be out of canvas..*

推荐答案

正如有人指出 - 问题描述不是很清楚。但我假设,因为你需要,你可以扩展每个tile(至少你的例子表明,瓷砖比例是可能的)。所以我的解决方案将是简单的(但也许不是你想要的,也不最佳):

As others pointed - problem description is not very clear. But i'm assuming that you can scale each tile as you need (at least your examples shows that tile scaling is possible). So my solution will be simple (but maybe not what you want nor optimal):

  • 在缩放每个平铺系数:
  • Scale each tile by factor :
EDGEspace / (EDGEtile * N ½)

  • 将在当前行每瓦,如果瓷砖失控的空间限制 - 前进到下一行
  • 下面 N 是最近完美的广场大于或等于瓦片的总数

    Here N is nearest perfect square greater or equal to the total number of tiles.

    P.S。如果你需要的瓷砖之间有间距 - 只是使上述比例系数稍微小了一点。

    p.s. If you need some spacing between tiles - just make above scale factor a little bit smaller.

    希望有所帮助。

    这篇关于瓷砖(可扩展)叠加算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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