Skip to content
TheChatArchiveThe Chat Archive
Geminigemini-2.5-flash-lite-preview-06-17-thinking· GoogleHugging Face LMArena Human Preference 140K

find point B coordinates in degrees knowing: 1. coordinates of another point E in…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Claudeclaude-sonnet-4-20250514’s answer.
  1. User

    find point B coordinates in degrees knowing:

    1. coordinates of another point E in degrees
    2. azimuth from another point E to point B
    3. distance in km (for example 1000)

    take into account curvature of the earth write it as code in matlab

  2. Gemini Assistant

    Okay, this is a classic problem in geodesy known as the geodetic direct problem (or forward problem). You have a starting point, a direction (azimuth), and a distance, and you want to find the ending point. We need to use formulas that account for the Earth's shape, typically approximated by an ellipsoid (like WGS84).

    MATLAB's Navigation Toolbox provides functions specifically for this. The most accurate function for this task on an ellipsoid is calculateGeodetic. If you don't have the Navigation Toolbox, a simpler spherical approximation can be made using the reckon function, but it's less accurate, especially over long distances.

    Here's the code using the more accurate calculateGeodetic function, assuming you have the Navigation Toolbox installed.

    function [latB_deg, lonB_deg] = calculateEndPointCoordinates(latE_deg, lonE_deg, aziE_deg, dist_km)
    % Calculates the coordinates of point B given point E, azimuth, and distance,
    % accounting for Earth's curvature using the WGS84 ellipsoid.
    %
    % Syntax:
    %   [latB_deg, lonB_deg] = calculateEndPointCoordinates(latE_deg, lonE_deg, aziE_deg, dist_km)
    %
    % Inputs:
    %   latE_deg : Latitude of the starting point E (in degrees, -90 to 90)
    %   lonE_deg : Longitude of the starting point E (in degrees, -180 to 180)
    %   aziE_deg : Azimuth from E to B (in degrees, 0=North, 90=East, 180=South, 270=West)
    %   dist_km  : Distance from E to B (in kilometers)
    %
    % Outputs:
    %   latB_deg : Latitude of the destination point B (in degrees)
    %   lonB_deg : Longitude of the destination point B (in degrees)
    %
    % Requires: Navigation Toolbox
    %
    % Example:
    %   % Starting point near London
    %   latE = 51.5074; % degrees
    %   lonE = -0.1278; % degrees
    %   % Azimuth towards North-East
    %   azimuth = 45;   % degrees
    %   % Distance
    %   distance = 1000; % km
    %   [latB, lonB] = calculateEndPointCoordinates(latE, lonE, azimuth, distance);
    %   fprintf('Point E: Lat %.4f, Lon %.4f\n', latE, lonE);
    %   fprintf('Point B: Lat %.4f, Lon %.4f\n', latB, lonB);
    
    % --- Input Validation (Basic) ---
    if ~isnumeric(latE_deg) || ~isscalar(latE_deg) || latE_deg < -90 || latE_deg > 90
        error('Latitude of point E must be a scalar numeric value between -90 and 90 degrees.');
    end
    if ~isnumeric(lonE_deg) || ~isscalar(lonE_deg) || lonE_deg < -180 || lonE_deg > 180
        error('Longitude of point E must be a scalar numeric value between -180 and 180 degrees.');
    end
    if ~isnumeric(aziE_deg) || ~isscalar(aziE_deg) || aziE_deg < 0 || aziE_deg >= 360
        warning('Azimuth is typically expected between 0 and 360 degrees. Normalizing if necessary.');
        aziE_deg = mod(aziE_deg, 360); % Normalize azimuth to [0, 360)
    end
    if ~isnumeric(dist_km) || ~isscalar(dist_km) || dist_km < 0
        error('Distance must be a non-negative scalar numeric value in kilometers.');
    end
    
    % --- Geodetic Calculation ---
    
    % 1. Define the reference ellipsoid model. WGS84 is the standard for GPS.
    earth = referenceEllipsoid('wgs84');
    
    % 2. Convert distance from kilometers to meters (required by calculateGeodetic)
    dist_m = dist_km * 1000;
    
    % 3. Use calculateGeodetic to find the destination point
    %    Inputs: Ellipsoid, Latitude, Longitude, Azimuth, Distance, AngleUnit
    %    Outputs: Latitude, Longitude, Reverse Azimuth
    %    Note: This function inherently handles the Earth's curvature.
    [latB_deg, lonB_deg, ~] = calculateGeodetic(earth, latE_deg, lonE_deg, aziE_deg, dist_m, 'degrees');
    
    % --- Output ---
    % The calculated latitudes and longitudes are already in degrees.
    
    end % function calculateEndPointCoordinates
    
    % --- Example Usage ---
    % Define coordinates for point E (e.g., London)
    latE = 51.5074; % Latitude in degrees
    lonE = -0.1278; % Longitude in degrees
    
    % Define azimuth from E to B (e.g., 45 degrees, North-East)
    azimuth_E_to_B = 45; % Azimuth in degrees
    
    % Define distance in kilometers
    distance_km = 1000; % Distance in km
    
    % Calculate coordinates of point B
    [latB, lonB] = calculateEndPointCoordinates(latE, lonE, azimuth_E_to_B, distance_km);
    
    % Display the results
    fprintf('Starting Point E:\n');
    fprintf('  Latitude: %.6f degrees\n', latE);
    fprintf('  Longitude: %.6f degrees\n', lonE);
    fprintf('\n');
    fprintf('Azimuth E to B: %.2f degrees\n', azimuth_E_to_B);
    fprintf('Distance E to B: %.2f km\n', distance_km);
    fprintf('\n');
    fprintf('Calculated Destination Point B:\n');
    fprintf('  Latitude: %.6f degrees\n', latB);
    fprintf('  Longitude: %.6f degrees\n', lonB);
    
    % Example 2: Going South-West from a point in the US
    latE_US = 39.7392; % Denver, CO Latitude
    lonE_US = -104.9903; % Denver, CO Longitude
    azimuth_US = 225; % South-West
    distance_US = 500; % km
    
    [latB_US, lonB_US] = calculateEndPointCoordinates(latE_US, lonE_US, azimuth_US, distance_US);
    
    fprintf('\n---\n');
    fprintf('Starting Point E (US):\n');
    fprintf('  Latitude: %.6f degrees\n', latE_US);
    fprintf('  Longitude: %.6f degrees\n', lonE_US);
    fprintf('\n');
    fprintf('Azimuth E to B: %.2f degrees\n', azimuth_US);
    fprintf('Distance E to B: %.2f km\n', distance_US);
    fprintf('\n');
    fprintf('Calculated Destination Point B (US):\n');
    fprintf('  Latitude: %.6f degrees\n', latB_US);
    fprintf('  Longitude: %.6f degrees\n', lonB_US);
    

    Explanation:

    1. Function Definition: The code defines a function calculateEndPointCoordinates that takes the latitude and longitude of point E, the azimuth from E to B, and the distance as inputs.
    2. Input Validation: Basic checks are included to ensure the inputs are reasonable scalar numbers. The azimuth is normalized to be within the 0-360 degree range.
    3. Ellipsoid Model: referenceEllipsoid('wgs84') creates a standard object representing the WGS84 ellipsoid, which approximates the Earth's shape.
    4. Unit Conversion: The calculateGeodetic function expects the distance in meters, so the input distance in kilometers (dist_km) is multiplied by 1000.
    5. calculateGeodetic Function: This is the core of the calculation.
      • It takes the ellipsoid model, starting latitude (latE_deg), starting longitude (lonE_deg), azimuth (aziE_deg), and distance in meters (dist_m).
      • The 'degrees' flag tells the function that the input latitude, longitude, and azimuth are in degrees.
      • It returns the destination latitude (latB_deg) and longitude (lonB_deg) in degrees, along with the azimuth calculated in the reverse direction (from B back to E), which we ignore here (~).
    6. Output: The function returns the calculated latitude and longitude of point B in degrees.
    7. Example Usage: The script includes example values and calls the function, printing the results clearly.

    Before Running:

    • Make sure you have MATLAB installed.
    • Ensure you have the Navigation Toolbox add-on installed. If not, you might need to purchase and install it, or look for alternative implementations (though they often involve more complex manual calculations or external libraries).

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.