日期:2014-05-17 浏览次数:20933 次
/// <summary>
/// 获取中心点坐标
/// </summary>
/// <param name="p"></param>
/// <returns></returns>
public Point GetCenterPoint(Point[] p)
{
Point ptCenter = new Point(0, 0);
int i, j;
double ai, atmp = 0, xtmp = 0, ytmp = 0;
if (p == null)
throw new ArgumentNullException("获取多边形中心点坐标时传入的参数为空。");
if(p.Length == 1)
return p[0];
if ((p.Length == 2)
------解决方案--------------------
(p.Length == 3 && p[0] == p[2]))
return new PointDD((p[1].X + p[0].X) / 2, (p[1].Y + p[0].Y) / 2);
int n = p.Length;
for (i = n - 1, j = 0; j < n; i = j, j++)
{
ai = p[i].X * p[j].Y - p[j].X * p[i].Y;
atmp += ai;
xtmp += (p[j].X + p[i].X) * ai;
ytmp += (p[j].Y + p[i].Y) * ai;
}
if (atmp != 0)
{
ptCenter.X = Convert.ToInt32(xtmp / (3 * atmp));