computeSignedAreaTest static method
Returns the signed area of a closed path on a sphere of given radius. The computed area uses the same units as the radius squared. Used by SphericalUtilTest.
Implementation
static double computeSignedAreaTest(List<Point> path, double radius) {
int size = path.length;
if (size < 3) {
return 0;
}
double total = 0;
Point prev = path[size - 1];
double prevTanLat = tan((pi / 2 - toRadians(prev.x)) / 2);
double prevLng = toRadians(prev.y);
// For each edge, accumulate the signed area of the triangle formed by the North Pole
// and that edge ('polar triangle').
for (final point in path) {
double tanLat = tan((pi / 2 - toRadians(point.x)) / 2);
double lng = toRadians(point.y);
total += polarTriangleArea(tanLat, lng, prevTanLat, prevLng);
prevTanLat = tanLat;
prevLng = lng;
}
return total * (radius * radius);
}