2011-10-03 30 views
2

我正在开发一个项目,其中有一个设置区域(1000 x 1300)的区域。 我需要一个数学公式,我可以输入一个整数并将其分解成相等的形状。如何计算给定数量的覆盖更大区域的矩形的大小

所以,如果我需要打破这种区域成170“砖头”的公式应该告诉我,每一块砖需要是100像素×60像素(这只是例子)

+0

“砖”......“撞墙”......:D –

回答

0

你正在寻找术语被称为tesselation;像往常一样wikipedia有一个很好的文章。

0

你可以保持它的简单(与语言无关):

overallHeight = 1300; 
overallWidth = 1000; 

numberOfBricks = 170; 
squareRootOfBrickCount = sqrt(numberOfBricks); 

brickHeight = int(overallHeight/squareRootOfBrickCount); 
brickWidth = int(overallWidth/squareRootOfBrickCount); 

对于最右边和最底层的砖,你必须在过程中被排斥在外,由于int操作,任何额外的像素增加计算:

extraHeight = overallHeight - (int(squareRootOfBrickCount) * brickHeight); 
extraWidth = overallWidth - (int(squareRootOfBrickCount) * brickWidth);