2011-10-03 21 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); 
相關問題