// 鞋带公式 计算面积 https://www.zhihu.com/question/58639959/answer/159924222
getArea(points){
if(points.length<3) return 0;
let a =points[points.length-1].x*points[0].y;
let b =points[0].x*points[points.length-1].y;
for (let i = 0; i < (points.length-1); i++){
a+=points[i].x*points[i+1].y;
b+=points[i+1].x*points[i].y;
}
return Math.abs(a-b)/2;
}
网友评论