UNPKG

xiaohejs

Version:

🎈 小何同学的JavaScript工具箱

2 lines (1 loc) 753 B
import{DegreeMetres as t,DegreeRadians as n,PlaneAreaThreshold as r,EarthRadiusMetres as e}from"./config.js";import{points2array as o}from"./point2array.js";import{angle as c}from"./angle.js";function s(r){if(r.length<3)return 0;const e=o(r);return Math.abs(e.reduce(((r,o,c)=>{const s=(c+1)%e.length,u=e[c][0]*t*Math.cos(e[c][1]*n),h=e[c][1]*t,i=e[s][0]*t*Math.cos(e[s][1]*n);return r+=u*(e[s][1]*t)-i*h}),0))}function u(t){if(t.length<3)return 0;const r=o(t),s=r.reduce(((t,n,e)=>{const o=(e+1)%r.length,s=(e+2)%r.length;return t+=c(r[e],r[o],r[s])}),0),u=180*(r.length-2),h=s-u,i=n*e*e;return h>420?(360*r.length-s-u)*i:h>300&&h<420?Math.abs(360-h)*i:h*i}function h(t){const n=s(t);return n>r?u(t):n}export{h as area,s as planeArea,u as sphereArea};