function getPolygonAreaCenter(points) {
var sum_x = 0;
var sum_y = 0;
var sum_area = 0;
var p1 = points[1];
for (var i = 2; i < points.length; i++) {
p2 = points[i];
area = Area(points[0], p1, p2);
sum_area += area;
sum_x += (points[0].x + p1.x + p2.x) * area;
sum_y += (points[0].y + p1.y + p2.y) * area;
p1 = p2;
}
var xx = sum_x / sum_area / 3;
var yy = sum_y / sum_area / 3;
return { xx, yy };
}
function Area(p0, p1, p2) {
var area = 0.0;
area =
p0.x * p1.y +
p1.x * p2.y +
p2.x * p0.y -
p1.x * p0.y -
p2.x * p1.y -
p0.x * p2.y;
return area / 2;
}
本文来自博客园,作者:雨到了这里缠成线,转载请注明原文链接:https://www.cnblogs.com/ZhaoMingYuan/p/16174490.html
浙公网安备 33010602011771号