我正在开展一个项目,我们有一个设定区域(1000 x 1300)区域。 我需要一个数学方程式,我可以输入一个整数并将它分成相同的形状。
因此,如果我需要将这个区域分解为170个“砖块”,那么等式应该告诉我每块砖需要100px x 60 px(这只是示例)
答案 0 :(得分:0)
您正在寻找的术语称为tesselation;像往常一样wikipedia有一篇很好的文章。
答案 1 :(得分: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);