1、二维情况下,计算多边形面积
internal static float GetArea(List<Vector2> points)
{
float area2 = 0;
for (int numPoint = 0; numPoint < points.Count - 1; numPoint++)
{
MyPoint point = points[numPoint];
MyPoint nextPoint = points[numPoint + 1];
area2 += point.x * nextPoint.y - point.y * nextPoint.x;
}
return area2 / 2f;
}
2、三维情况下,计算多边形面积
internal static float GetArea3D(List<Vector3> points, Vector3 normal)
{
Vector3 vector = Vector3.zero;
for (int numPoint = 0; numPoint < points.Count - 1; numPoint++)
{
var point = points[numPoint];
var nextPoint = points[numPoint + 1];
vector += Vector3.Cross(point, nextPoint);
}
return (1f / 2f) * Math.Abs(Vector3.Dot(vector, normal));
}
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://zhzhx.blog.csdn.net/article/details/125169859
内容来源于网络,如有侵权,请联系作者删除!