rotate a matrix by a certain angle

Viewed 377

One afternoon wasted on the following problem:

I have a matrix of depth values in a certain spatial domain. I define a line in the domain and I erase the valued below this line.

The code uses the findnearest function to find the index of the element of an array that is closest to a certain value.

clear all
close all

dx = 5;
dz = 1;

%angle between line and ground
a=atan(0.05);

%%%define domain
xi = 0:dx:20e3;
zi = 0:dz:1000;
m=length(zi);
n=length(xi);

%create grid
[x,z] = meshgrid(xi,zi);

%z where line starts
zs = 700;
%set line
 for i = 1:findnearest(xi,zi(zs)*1/a)
  xind(i) = i;
  zind(i) = findnearest(zi, fix(-xi(i)*a +zi(zs))); 
 end


depth = repmat(zi',1,n); %simply the coordinate zi repeated for all xi

 %calculate distance from the line
 for ii=1:n %for every x

    zslope = -a*xi(ii)+zi(zs);%equation of the line

    zz(ii)=zslope;
   if zslope>=0 %if the line is still in the domain (z>0)
     for jj=1:m %for every z

       if zi(jj)>=zslope %above the line

         Zs(jj,ii) = zi(jj)-zslope; %height above the line

        elseif zi(jj)<zslope %below the line (ground)
%            
          Zs(jj,ii)=NaN; 

       end
     end%for on z

   elseif zslope<0 %the line is no longer in the domain

       for jj=1:m %for every z

          Zs(jj,ii) = zi(jj)-zslope; %height above the line

       end
   end
end%for on x 

figure
imagesc(Zs)
colorbar
title('distance from the line')

%zone above the line
maskINT=zeros(m,n);
inds = find(Zs>=0); %erase values under the line
maskINT(inds)=1;


figure
imagesc(depth);colorbar
title('depth')

figure
imagesc(depth.*maskINT);colorbar
title('depth  above the line')

figure
contour(depth.*maskINT);colorbar
set(gca,'YDir','Reverse')
title('depth')

The resulting depth matrix is the following:

depth

that represented with contour looks like this:

depth_c

I want to rotate the depth matrix by an angle (-pi/2-a?) or apply some transformation to it, such that the depth contours would become perpendicular to a line parallel to the first line:

idea

I simply various rotation matrices but with no good results...

1 Answers
Related