如何知道矩形和菱形的中心C# [英] how to know center of rectangle and rhombus C#
本文介绍了如何知道矩形和菱形的中心C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
if (shapeChecker.IsCircle(edgePoints, out center, out radius))
{
g.DrawEllipse(yellowPen, (float)(center.X - radius), (float) (center.Y - radius),
(float)(radius * 2), (float)(radius * 2));
circleCount++;
label2.Text = String.Format("Centre Location X:{0}, Y:{1} ",
center.X, center.Y);
label3.Text = String.Format("Radius : {0} ", radius);
x = (int)center.X;
y = (int)center.Y;
timer2.Enabled = true;
}
//is Rhombus
else if (shapeChecker.IsConvexPolygon(edgePoints, out corners))
{
if (shapeChecker.CheckPolygonSubType(corners) == PolygonSubType.Rhombus)
{
rhombusCount++;
g.DrawPolygon(bluePen, ToPointsArray(corners));
//How to know center rhombus??
}
}
//is rectangle
if (shapeChecker.IsQuadrilateral(edgePoints, out corners))
{
if (shapeChecker.CheckPolygonSubType(corners) == PolygonSubType.Rectangle)
{
rectangularCount++;
g.DrawPolygon(redPen, ToPointsArray(corners));
//How to know center rectangle
}
}
推荐答案
菱形的中心是边界矩形的中心:
The centre of a rhombus is the centre of the bounding rectangle:
_ _______
| / /
| / /
/ / |
/______/ __|
这是微不足道的:
And that's trivial:
/// <summary>
/// Returns the center point of the rectangle
/// </summary>
/// <param name="r"></param>
/// <returns>Center point of the rectangle</returns>
public static Point Center(this Rectangle r)
{
return new Point((r.Left + r.Right) / 2, (r.Top + r.Bottom) / 2);
}
(来自NaibedyaKar在上面的评论中提供的链接 - 自从我写了小费以来,我可以将它复制到我想要的所有内容!:笑:):
计算边界矩形也不困难:( smallestX,smallestY),(maximumX,largestY)分别是TLHC和BRHC。
(From the link supplied by NaibedyaKar in the comments above - since I wrote the tip, I can copy it all I want! :laugh: )
Working out the bounding rectangle isn't difficult either: (smallestX, smallestY), (largestX, largestY) are the TLHC and BRHC respectively.
这篇关于如何知道矩形和菱形的中心C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文