computeGimbalAngle method Null safety

double computeGimbalAngle(
  1. FlightLocation pointOfInterest,
  2. FlightLocation droneLocation
)

Implementation

static double computeGimbalAngle(
    FlightLocation pointOfInterest, FlightLocation droneLocation) {
  // Calculating the distance between the drone and the point-of-interest (inclduing height)
  final double latitudeDeltaInMeters =
      (droneLocation.latitude / meterToDecimalDegree) -
          (pointOfInterest.latitude / meterToDecimalDegree);

  final double longitudeDeltaInMeters =
      (droneLocation.longitude / meterToDecimalDegree) -
          (pointOfInterest.longitude / meterToDecimalDegree);

  final double altitudeDeltaInMeters =
      droneLocation.altitude - pointOfInterest.altitude;

  // The ground distance (in meters) between the drone and the point-of-interest (without altitude)
  final double groundDistanceInMeters =
      sqrt(pow(longitudeDeltaInMeters, 2) + pow(latitudeDeltaInMeters, 2));

  // The distance between the drone and the point-of-interest (with altitude)
  //final double distance = sqrt(pow(groundDistanceInMeters, 2) + pow(altitudeDeltaInMeters, 2));

  final double gimbalAngleInDegrees =
      atan(groundDistanceInMeters / altitudeDeltaInMeters) * 180 / pi;

  // We return the gimbal angle as a "minus" to match the DJI SDK gimbalPitch definition.
  return gimbalAngleInDegrees.abs() * -1;
}