computeGimbalAngle static method

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));

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

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