calculateCentralAngle function

double calculateCentralAngle(
  1. GlobeCoordinates start,
  2. GlobeCoordinates end
)

Calculates the central angle between two points on a sphere.

The start and end parameters represent the start and end points.

Returns the central angle as a double value in radians.

Implementation

double calculateCentralAngle(GlobeCoordinates start, GlobeCoordinates end) {
  // Convert latitude and longitude from degrees to radians
  double lat1 = degreesToRadians(start.latitude);
  double lon1 = degreesToRadians(start.longitude);
  double lat2 = degreesToRadians(end.latitude);
  double lon2 = degreesToRadians(end.longitude);

  // Apply the spherical law of cosines
  double deltaLon = lon2 - lon1;
  double centralAngle =
      acos(sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(deltaLon));

  return centralAngle; // Angle in radians
}