Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


make_dist_matrix is a function to ..........

Useage:



d_matrix = make_dist_matrix(lon_rho,lat_rho,poly_p1,poly_p2,debug)

Input Arguments:

lon_rho – 
lat_rho – 
poly_p1  

poly_p2 

Output Arguments:

d_matrix – 

Comments:




asd
asd
asd
asd


Code:


 

function d_matrix = make_dist_matrix(lon_rho,lat_rho,poly_p1,poly_p2,debug)
 
% r : matrix that describes whether the point can be projected onto the face (0<r<1), would fall before the face (r<0) or after (r>0)
% lat_rho : matrix of latitudes
% lon_rho : matrix of longitudes
% poly_p1 : first point of face (lon,lat)
% poly_p2 : second point of face (lon,lat)
% debug : if == 1, output plots of r, r_1, r_2, r_3, d_matrix
 
 
%DG 01/02/12
 
%&%&%&%%&%&%&%&%&%%&%&%&%&%&%&%&%&%&%%&%&%&%&%&%%&%&%&%&%&%&%&%&%&%%&%&%&%&%&%%&%&%&%&%&%&%
 
LONS = lon_rho.';
LATS = lat_rho.';
 
r_num = (LONS-poly_p1(1)).*(poly_p2(1)-poly_p1(1)) + (LATS-poly_p1(2)).*(poly_p2(2)-poly_p1(2));
r_denom (poly_p2(1)-poly_p1(1)).^2 + (poly_p2(2)-poly_p1(2)).^2;
 
r = r_num./r_denom;
 
% r<0, compute dist to poly_p1
% 0<r<1, compute perp distance to face
% r>0, compute dist to poly_p2
 
if r<=0
        [d1,dump] = distance(lat_rho,lon_rho,poly_p1(1),poly_p1(2));
elseif 0<r & r<1
        d2 = abs(det([poly_p2-poly_p1;P-poly_p1]))/norm(poly_p2-poly_p2);
elseif r>=1
        [d3,dump] = distance(lat_rho,lon_rho,poly_p2(1),poly_p2(2));
end
 
% Now combine d1,2,3 into d_matrix
 
r_1 = r;r_1(r_1>0)=0;r_1(r_1~=0)=1;
r_2 = r;r_2(r_2<=0 | r_2>=1 )=0;r_2(r_2~=0)=1;
r_3 = r;r_3(r_3<1)=0;r_3(r_3~=0)=1;
 
 
d_matrix = r_1.*d1 + r_2.*d2 + r_3.*d3;
 
if debug == 1
 
figure('renderer','zbuffer'), flat_pcolor(r),colorbar
figure('renderer','zbuffer'), flat_pcolor(r_1),colorbar
figure('renderer','zbuffer'), flat_pcolor(r_2),colorbar
figure('renderer','zbuffer'), flat_pcolor(r_3),colorbar
figure('renderer','zbuffer'), flat_pcolor(d_matrix),colorbar
 
end