js 获取不规则图形的重心

let list = [
  [464.1, 884.4],
  [1.1, 884.4],
  [1.1, 23.4],
  [204.1, 23.4],
  [464.1, 23.4],
];

function a(list) {
  let area = 0.0;
  let Gx = 0.0;
  let Gy = 0.0;
  for (let i = 1; i <= list.length; i++) {
    let iLat = list[i % list.length][0];
    let iLng = list[i % list.length][1];
    let nextLat = list[i - 1][0];
    let nextLng = list[i - 1][1];
    let temp = (iLat * nextLng - iLng * nextLat) / 2.0;
    area += temp;
    Gx += (temp * (iLat + nextLat)) / 3.0;
    Gy += (temp * (iLng + nextLng)) / 3.0;
  }
  Gx = Gx / area;
  Gy = Gy / area;
  return [Gx, Gy];
}
console.log(a(list));
posted @   7c89  阅读(272)  评论(0编辑  收藏  举报
(评论功能已被禁用)
相关博文:
阅读排行:
· DeepSeek 解答了困扰我五年的技术问题。时代确实变了!
· PPT革命!DeepSeek+Kimi=N小时工作5分钟完成?
· What?废柴, 还在本地部署DeepSeek吗?Are you kidding?
· DeepSeek企业级部署实战指南:从服务器选型到Dify私有化落地
· 程序员转型AI:行业分析
点击右上角即可分享
微信分享提示