C#計算多邊形面積,判斷繪製多邊形的方向
阿新 • • 發佈:2019-02-20
public double area()
{
double area = 0;
for (int i = 0; i < _Points.Count - 1; i++)
{
area += ((double)_Points[i].X * (double)_Points[i + 1].Y - (double)_Points[i + 1].X * (double)_Points[i].Y) / 2;
}
area += 1.0f * (_Points[_Points.Count - 1].X *_Points[0].Y -_Points[0].X * _Points[_Points.Count - 1].Y) / 2;
area = Math.Abs(area);
return area;
}
public string direction()
{
string direction;
double minus = 0;
minus += (_Points[1].X - _Points[0].X) * (_Points[2].Y - _Points[1].Y) - (_Points[1].Y - _Points[0].Y) * (_Points[2].X - _Points[1].X);
if (minus > 0)
{
direction = "Clockwise";
}
else
{
direction= "Anti-clockwise";
}
return direction;
}