答案 0 :(得分:0)
我找到了办法:
// init left point
List<Point> boundariesCoords = new List<Point>();
boundariesCoords.Add(new Point(_leftPadding, _topPadding));
// final right point
boundariesCoords.Add(new Point(_leftPadding + leftInsertionBox.Width + leftCoverBox.Width + bottomGlueBox.Width, _topPadding + topRect.Height + frontRect.Height + bottomRect.Height + backRect.Height + bottomGlueBox.Height));
int totalX = 0, totalY = 0;
foreach (Point p in boundariesCoords)
{
totalX += p.X;
totalY += p.Y;
}
int centerX = totalX / boundariesCoords.Count;
int centerY = totalY / boundariesCoords.Count;
答案 1 :(得分:0)
获得边界的中心应该是微不足道的(宽度/ 2,高度/ 2)+(偏移X,偏移Y),所以我认为这不是你所指的。采取&#34;质量中心&#34;在您绘制的所有矩形中,只需松散地跟踪最外边缘:
for each rectangle
minLeft = min(currentLeft, minLeft)
maxRight = max(currentRight, maxRight)
minTop = ...
maxBottom = ...
centerX = (maxRight - minLeft) / 2 + minLeft
centerY = ...
这有助于回答您的问题吗?