%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% PURPOSE: Compute waypoints for a box run.  
% AUTHOR:  Initial; rsm
% DATE:    06/3/11
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  oboxNW 7-------6 oboxNE
%         |       |
%         |       |
% \       8       |                          ^
%  \      |\      |                         / \
%   \     | \     |                          |
%    \    |  \    |                          |
%     \   |   \   |                        boxPsi (bearing)
%      \  |    \  |
%       \ |     \ |
%        \|      \|
%  iboxNW 2-------1     --
%         |       |     /\
%         |       |     
% \       3       |
%  \      |\      |    width
%   \     | \     |
%    \    |  \    |
%     \   |   \   |
%      \  |    \  |   
%       \ |     \ |   
%        \|      \|     \/
%  iboxSW 4-------5 SE  --
%         |
%         |             offset
%         |             
%         x anchor point.       
%
% The entire figure rotates about the point x by the angle boxPsi
%
% The offset location is point 4, which is where the transponder is located.
%
format compact
units;
%
% Miso Coordinates:
boxPsi  =  334;
boxLat =  36  + 36.3970/60;
boxLon = -121 - 52.4668/60;
offset = 25;
boxHeight = 50;
boxWidth  = 300;
%
% 500 m box coords.  Start at Miso ibox2 (NW) and run a 500 m square, 
% parallel to the Miso channel axis.
boxLat =   36.609244;
boxLon = -121.876043;
%
% 500 m box coords.  Start just offshore and north of the Moss Landing harbor.
boxPsi =  245.5
boxLat =  36+48.7542/60
boxLon = -121-47.9615/60
offset = 0;
boxHeight = 500;
boxWidth  = 500;
fprintf('#Anchor     = [%.6f %.6f]\n', boxLat, boxLon);

%
% Compute the offset location at a heading of boxPsi:

fprintf('#ibox4 (SW) = ');
ibox4 = hdg2ll(boxPsi,               offset,    boxLat,    boxLon, rE);
fprintf('#ibox2 (NW) = ');
ibox2 = hdg2ll(boxPsi,      boxWidth+offset,    boxLat,    boxLon, rE);
fprintf('#ibox3      = ');
ibox3=  hdg2ll(boxPsi,  boxWidth+offset-100,    boxLat,    boxLon, rE);
fprintf('#ibox5 (SE) = ');
ibox5 = hdg2ll(boxPsi+90,         boxHeight, ibox4(1), ibox4(2), rE);
fprintf('#ibox1 (NE) = ');
ibox1 = hdg2ll(boxPsi+90,         boxHeight, ibox2(1), ibox2(2), rE);
%
fprintf('#obox7 (NW) = ');
obox7 = hdg2ll(boxPsi,    2*boxWidth+offset, boxLat,   boxLon, rE);
fprintf('#obox8      = ');
obox8= hdg2ll(boxPsi, 2*boxWidth+offset-100, boxLat,   boxLon, rE);
fprintf('#obox6 (NE) = ');
obox6 = hdg2ll(boxPsi+90,  boxHeight, obox7(1), obox7(2), rE);
%
fprintf('#esc1       = ');
esc1 = hdg2ll(boxPsi+90,  offset, ibox4(1), ibox4(2), rE);
fprintf('#esc2 (100) = ');
esc2 = hdg2ll(boxPsi,    100,   esc1(1),   esc1(2), rE);
fprintf('#esc3 (200) = ');
esc3 = hdg2ll(boxPsi,    200,   esc1(1),   esc1(2), rE);
fprintf('#esc4 (400) = ');
esc4 = hdg2ll(boxPsi,    400,   esc1(1),   esc1(2), rE);



