% Lab three Hints
% the sections below can be copied into separate files to accomplish the
% different steps of this lab

% here are three locations on a small circle with azimuths (:
%    longitude  latitude  azimuth
data=[  0       -38      -20
        -20       -38        -5
        -40       -38       8];
% so, the first column has longitudes, the second latitudes, the third azimuths
% each row is a different point on the small circle

% to get the great circle for the first point:
[lon1,lat1] = GreatCircle(data(1,1),data(1,2),data(1,3));
% in matlab, you index a matrix with the first # being the row number and
% the second is the column number
% to get the second great circle:
[lon2,lat2] = GreatCircle(data(2,1),data(2,2),data(2,3));
% I leave it to you to get the third great circle

% now the steps above could have been done in a loop:
[nr,nc]=size(data) ;  % this returns the number of rows and columns
for i=1:nr
  [lonGC(:,i),latGC(:,i)]=GreatCircle(data(i,1),data(i,2),data(i,3));
end
% The above would return variable lonGC and latGC with columns for the
% different data points.

% now to plot your great circles:
figure(1)
clf
m_proj('miller','lat',[-50 70 ],'long',[ -80  60]);
 set(gca,'color','r');    
 m_coast('patch','r','edgecolor','none');
 m_grid('box','fancy','linestyle','none');
% here is the plot of the great circles
m_line(lonGC(:,1),latGC(:,1),'color','g','linewi',2);
m_line(lonGC(:,2),latGC(:,2),'color','g','linewi',2);
m_line(lonGC(:,3),latGC(:,3),'color','g','linewi',2);
% this also could be done in a loop

% now here is a nifty new thing:  do the following steps and you need to
% click (mouse) on the point you want to identify as the rotation pole:
[longPOLE,latPole]=get_point_on_map
% with the data here I get: longPOLE=-19.99 and latPOLE=59.85

%OK now you need outlines of South America and Africa. First make a map to digitize.

% for the South American plot:
figure(3)
clf 
m_proj('miller','lat',[-60 15 ],'long',[-90 -25]);

set(gca,'color',[.9 .99 1]);     
m_coast('patch',[.2 1 .7],'edgecolor','k'); 
m_elev('contour',[-10000:500:8000])
m_grid('box','fancy','linestyle','none');

% you can digitize the continent now with this command:
[lonSA,latSA]=get_continent;

% recenter on Africa to get its outline.  You should now have vectors of
% lats and lons for both South America and Africa.  Leave Africa fixed and
% rotate SOuth America using your Euler Pole:

%[long_out,lat_out]=Euler_Rotation(long_pole,lat_pole,rotang,lonSA,latSA);
[lon_out,lat_out]=Euler_Rotation(-20,40,58,SA(:,1),SA(:,2));

% now plot your rotated continent on a map that zeros in on Africa - adjust
% the plotting coordinates to be able to examine the fit.  also - adjust
% the pole of rotation and the rotation angle to get the best fit - 

figure(1)
clf
m_proj('miller','lat',[-50 70 ],'long',[ -80  60]);
 set(gca,'color','r');    
 m_coast('patch','r','edgecolor','none');
 m_grid('box','fancy','linestyle','none');
 m_line(lon_out,lat_out,'color','g','linewi',2);
 % should also plot the African outline (at the edge of the continental
 % shelf.
 
 
 
 