ringAreaSquareMeters function
Diện tích (m²) của một ring [[lng,lat], …] theo công thức spherical excess.
Sai số < 0,1% ở quy mô đô thị — đủ cho câu trả lời của agent.
Implementation
double ringAreaSquareMeters(List<List<double>> ring) {
if (ring.length < 3) return 0;
const radiusM = kEarthRadiusKm * 1000;
var total = 0.0;
for (var i = 0; i < ring.length; i++) {
final p1 = ring[i];
final p2 = ring[(i + 1) % ring.length];
total +=
_toRad(p2[0] - p1[0]) *
(2 + math.sin(_toRad(p1[1])) + math.sin(_toRad(p2[1])));
}
return (total * radiusM * radiusM / 2).abs();
}