コード例 #1
0
 public Double calculateDistance(double longitude, double latitude) {
   if (hasCoordinates()) {
     Bearing bearing = calculateBearing(getLongitude(), getLatitude(), longitude, latitude);
     double distance = bearing.getDistance();
     if (!isNaN(distance)) return distance;
   }
   return null;
 }
コード例 #2
0
 public Double calculateOrthogonalDistance(NavigationPosition pointA, NavigationPosition pointB) {
   if (hasCoordinates() && pointA.hasCoordinates() && pointB.hasCoordinates()) {
     Bearing bearingAD =
         calculateBearing(
             pointA.getLongitude(), pointA.getLatitude(), getLongitude(), getLatitude());
     Double distanceAtoD = bearingAD.getDistance();
     if (distanceAtoD != null) {
       double courseAtoD = toRadians(bearingAD.getAngle());
       double courseAtoB = toRadians(pointA.calculateAngle(pointB));
       return asin(sin(distanceAtoD / EARTH_RADIUS) * sin(courseAtoD - courseAtoB)) * EARTH_RADIUS;
     }
   }
   return null;
 }