Implementation
static FlightLocation? vectorToLocation(
{required FlightLocation droneLocation,
required FlightLocation pointOfInterest,
required FlightVector vector}) {
final double azimuthToDestination;
final double destinationLatitude;
final double destinationLongitude;
if (droneLocation.latitude == pointOfInterest.latitude &&
droneLocation.longitude == pointOfInterest.longitude) {
developer.log(
'vectorToLocation - Waypoint Mission Point of Interest cannot be identical to the drone (home) location',
name: kLogKindDjiFlutterPlugin,
);
return null;
}
azimuthToDestination = 180 -
vector.headingRelativeToPointOfInterest -
(atan((droneLocation.latitude - pointOfInterest.latitude).abs() /
(droneLocation.longitude - pointOfInterest.longitude).abs()) *
180 /
pi);
// Latitude = North/South
destinationLatitude = pointOfInterest.latitude +
(vector.distanceFromPointOfInterest *
sin(azimuthToDestination * pi / 180) *
meterToDecimalDegree);
// Longitude = East/West
destinationLongitude = pointOfInterest.longitude +
(vector.distanceFromPointOfInterest *
cos(azimuthToDestination * pi / 180) *
meterToDecimalDegree);
return FlightLocation(
latitude: destinationLatitude,
longitude: destinationLongitude,
altitude: vector.destinationAltitude);
}