Here's a MATLAB function that calculates point B coordinates given point E, azimuth, and distance, accounting for Earth's curvature:
function [lat_B, lon_B] = findPointB(lat_E, lon_E, azimuth_deg, distance_km)
% Calculate coordinates of point B given point E, azimuth, and distance
% Inputs:
% lat_E, lon_E: coordinates of point E in degrees
% azimuth_deg: azimuth from E to B in degrees (0-360, where 0 is North)
% distance_km: distance from E to B in kilometers
% Outputs:
% lat_B, lon_B: coordinates of point B in degrees
% Earth's radius in kilometers
R = 6371.0;
% Convert inputs to radians
lat_E_rad = deg2rad(lat_E);
lon_E_rad = deg2rad(lon_E);
azimuth_rad = deg2rad(azimuth_deg);
% Angular distance
delta = distance_km / R;
% Calculate latitude of point B using spherical trigonometry
lat_B_rad = asin(sin(lat_E_rad) * cos(delta) + ...
cos(lat_E_rad) * sin(delta) * cos(azimuth_rad));
% Calculate longitude of point B
lon_B_rad = lon_E_rad + atan2(sin(azimuth_rad) * sin(delta) * cos(lat_E_rad), ...
cos(delta) - sin(lat_E_rad) * sin(lat_B_rad));
% Convert back to degrees
lat_B = rad2deg(lat_B_rad);
lon_B = rad2deg(lon_B_rad);
% Normalize longitude to [-180, 180] range
lon_B = mod(lon_B + 180, 360) - 180;
end
% Example usage:
% Point E coordinates (e.g., New York City)
lat_E = 40.7128;
lon_E = -74.0060;
% Azimuth and distance
azimuth = 45; % 45 degrees (Northeast)
distance = 1000; % 1000 km
% Calculate point B
[lat_B, lon_B] = findPointB(lat_E, lon_E, azimuth, distance);
fprintf('Point E: %.4f°, %.4f°\n', lat_E, lon_E);
fprintf('Point B: %.4f°, %.4f°\n', lat_B, lon_B);
fprintf('Azimuth: %.1f°, Distance: %.1f km\n', azimuth, distance);
This implementation uses the spherical Earth model and applies the haversine formulas for great circle navigation. The key formulas used are:
- Latitude calculation: Uses the spherical law of cosines to find the destination latitude
- Longitude calculation: Uses atan2 to handle the spherical geometry properly
- Angular distance: Converts linear distance to angular distance using Earth's radius
The function handles edge cases like crossing the international date line by normalizing the longitude to the standard [-180°, 180°] range. For most applications, this spherical model provides accuracy within a few meters, which is sufficient unless you need millimeter precision for very long distances.