crossTrackDistance method
double
crossTrackDistance({
- required Coordinate currentPoint,
- required Coordinate startPoint,
- required Coordinate endPoint,
This function returns distance from currentPoint to great circle between startPoint and endPoint
currentPoint
The point whose distance is wondering to great circle
startPoint
Start of the great circle
endPoint
End of the great circle
Returns Distance to the great circle. If returns positive this means right of the path, otherwise it means left of the path.
final istCoordinates = Coordinate(41.28111111, 28.75333333); // The coordinates of Istanbul Airport
final jfkCoordinates = Coordinate(40.63980103, -73.77890015); // The coordinates of New York JFK Airport
final fcoCoordinates = Coordinate(41.8002778,12.2388889); // The coordinates of Roma Fiumicino Airport
final crossTrackDistanceInKm = greatCircle.crossTrackDistance(fcoCoordinates, istCoordinates, jfkCoordinates);
Implementation
double crossTrackDistance(
{required Coordinate currentPoint,
required Coordinate startPoint,
required Coordinate endPoint}) {
if (currentPoint == startPoint) return 0;
final double delta13 = distance(startPoint, currentPoint) / earthRadiusKm;
final double teta13 = bearing(startPoint, currentPoint).toRadians();
final double teta12 = bearing(startPoint, endPoint).toRadians();
final double deltaCrossTrack = asin(sin(delta13) * sin(teta13 - teta12));
return deltaCrossTrack * earthRadiusKm;
}