Puzzle challenge - distance to horizon
Image Analyst
on 23 Mar 2024
Latest activity Reply by Image Analyst
on 17 May 2024
In one line of MATLAB code, compute how far you can see at the seashore. In otherwords, how far away is the horizon from your eyes? You can assume you know your height and the diameter or radius of the earth.
8 Comments
This is ai answer:
radius = 6371; % radius of the Earth in kilometers
height = 1.7; % height of the observer in meters
distance = sqrt(2 * radius * height + height^2);
distance = distance / 1000; % convert distance to kilometers
disp(['The distance to the horizon is approximately ', num2str(distance), ' kilometers.']);
%The distance to the horizon is approximately 0.14719 kilometers.
Looks like no one else is going to post a response. This is the answer I got. Approximately 3 miles or 4.8 km.
D = 12742000; % Earth's diameter in meters.
R = D / 2; % Earth's radius in meters.
h = 1.8; % Your height in meters
% (R+h)^2 = d^2 + R^2
% d^2 = (R+h)^2 - R^2
distanceInMeters = sqrt((R+h)^2 - R^2)
dInMiles = distanceInMeters / 1609.34
distanceInMeters =
4789.1
dInMiles =
2.9758
Plug the numbers in directly to get the whole answer in one line of code.
Assuming Earth is a perfect sphere, it should be (h*(h + d))^(1/2) unless I'm completely mistaken.