Task: Find the latitude and longitude of Long Beach, California, Yokohama, Japan and Punta Arenas, Chile (use a web search to find this information). Calculate the distances between these ports and estimate the time required for a cargo ship (at 10 knots, or nautical miles per hour) to cover each leg of the triangular course. Where do you end up if you travel due east from Punta Arenas for 8 days by the same freighter?
The first consideration is to calculate distances between two locations on the earth indicated by latitude and longitude. These commands are part of the Mapping Toolbox.
There are two forms of the command indicated below. One needs 4 arguments indicating the latitude and longitude (in that order) of the two points. An alternative form passes two vectors of length 2 that contain the latitude and longitude of the start and end points.
Two numbers are returned by distance: Arc length and azimuth. The arc length is the angular distance (in degrees) between the two points on the surface of a sphere (actually, the reference ellipsoid). The azimuth is the true direction (in degrees) to follow from the first to the second point.
[ARC, AZ]=distance(lat1, lon1, lat2, lon2) [ARC, AZ]=distance([lat1 lon1], [lat2 lon2])
The arc length can be converted to distance in kilometers with KM=deg2km(ARC) or in nautical miles with NM=deg2nm(ARC). Furthermore, it is possible to convert distances with NM=km2nm(KM) or KM=nm2km(NM)
The default calculation by distance is by a great circle route, which is the shortest distance along the surface of a sphere. Following a great circle requires steering a changing coarse which points a little poleward of the average direction at the beginning of the path and a little equatorward at the end of the path.
By contrast, it is possible to calculate the distance on a sphere by following a constant compass direction (or following a rhumb line). This gives a slightly longer path but it is easier to steer a constant heading. The choice of the path to calculate is indicated by a character string as the first argument indicating great circle ('gc') or rhumb line ('rh').
[ARC, AZ]=distance('gc',[lat1 lon1], [lat2 lon2]) [ARC, AZ]=distance('rh',[lat1 lon1], [lat2 lon2])
In some cases, you might want to know a location (lat, lon) some distance and bearing from a given location. The function reckon provides this information. Specifically, if the first location is (Lat1,Lon1) and AZ is the true direction (degrees) to follow for a distance ARC (arc length in degrees over the earth), then the resulting location is (Lat2,Lon2) provided by
[Lat2 Lon2]=reckon(Lat1,Lon1,ARC,AZ)You may not know the ARC length to travel, so there are convenient converters for nautical miles (ARC=nm2deg(NM)) or kilometers (ARC=km2deg(KM)), where the angle is in degrees.
As with distance, reckon can calculate along great circle (gc) or rhumb lines (rh) as indicated by the character string as the first argument.
[Lat2 Lon2]=reckon('gc',Lat1,Lon1,ARC,AZ) [Lat2 Lon2]=reckon('rh',Lat1,Lon1,ARC,AZ)Great circle calculations are the default.
Flow chart for task.
%%% get locations for LongBeach CA, Yokohama Japan, Punta Arenas Chile %%% calculate distances between pairs of cities %%% Calculate time to travel between cities at 11 kt %%% calculate total time for trip %%% estimate distance traveled in 8 days %%% find location east of Punta Arenas for that distance
Script for task.
%%% get locations for LongBeach CA, Yokohama Japan, Punta Arenas Chile Name={'Long Beach';'Yokohama';'Punta Arenas'}; Loc=[33.7701 -118.1937;34.4437 139.6380 ;-53.1638 -70.9171]; %%% calculate distances between pairs of cities ARC=zeros(3,1);ANG=zeros(3,1); [ARC(1) ANG(1)]=distance(Loc(1,:),Loc(2,:)); [ARC(2) ANG(2)]=distance(Loc(2,:),Loc(3,:)); [ARC(3) ANG(3)]=distance(Loc(3,:),Loc(1,:)); Dis=deg2nm(ARC); % distances in nautical miles %%% Calculate time to travel between cities at 11 kt speed=11; % knots Time=Dis/(speed*24); % time in days disp(['time: ' char(Name(1)) ' to ' char(Name(2)) ' is ' num2str(Time(1))]) disp(['time: ' char(Name(2)) ' to ' char(Name(3)) ' is ' num2str(Time(2))]) disp(['time: ' char(Name(3)) ' to ' char(Name(1)) ' is ' num2str(Time(3))]) %%% calculate total time for trip disp(['total time: is ' num2str(sum(Time))]) %%% estimate distance traveled in 8 days NewDis=8*24*speed; % distance (nm) traveled in 8 days NewARC=nm2deg(NewDis); %%% find location east of Punta Arenas for that distance [NewLat NewLon]=reckon('rh',Loc(3,1),Loc(3,2),NewARC,90); disp([' new location: ' num2str(NewLat) ' ' num2str(NewLon)])