T=6;
incid_angle=deg2rad(30);
Vp=120;
Hp=2000;
Ha=500:15:1800;
R=(Hp -Ha)* tan(incid_angle);
delta_t= 11.25/360;
delta_d_plane=delta_t*Vp;
N=T/delta_t;
az=(deg2rad(0:11.25:359))'*ones(1,T);
az=reshape(az,length(az)*T,1);
p_position_x=zeros(N,1);
p_position_y=((1:N)'.*delta_d_plane)-delta_d_plane;  

delta_x=500;
delta_y=500;
x_grid=-3000:delta_x:3000;
y_grid=-3000:delta_y:3000;
z_grid=0:30:1000;

[x_3dgrid,y_3dgrid,z_3dgrid]=meshgrid(x_grid,y_grid,z_grid);
[x_size,y_size,z_size]=size(x_3dgrid);
coverage=zeros(x_size,y_size,z_size);
es=[];
for r=1:20%length(R)
    for n=1:N
       
        [x,y]=pol2cart(az(n),R(r));
 
            
            data_x(n)=p_position_x(n)+x;
            data_y(n)=p_position_y(n)+y; 
            data_z(n)=Ha(r);
            % end
        u_grid=find(round(abs( data_x(n)-x_grid))==min(round (abs(data_x(n)-x_grid))));
        v_grid=find(round(abs( data_y(n)-y_grid))==min(round (abs(data_y(n)-y_grid))));
        w_grid=find(round(abs( data_z(n)-z_grid))==min(round (abs(data_z(n)-z_grid))));
        if length(u_grid)>1 | length(v_grid)>1 |length(w_grid)>1
            n
            length(u_grid)
            length(v_grid)
            u_grid=u_grid(1);
            v_grid=v_grid(1);
            w_grid=w_grid(1);
        end
        if coverage(u_grid,v_grid,w_grid)>=1  
            coverage(u_grid,v_grid,w_grid)=coverage(u_grid,v_grid,w_grid)+1;
            %look(u_grid,v_grid,n)=az(n);
        elseif (coverage(u_grid,v_grid,w_grid))==0
            coverage(u_grid,v_grid)=1;
            %look(u_grid,v_grid,n)=az(n);
        end
    end
    level(r).dx=data_x;
    level(r).dy=data_y;
%     u_zero=find(coverage==0);
%     coverage(u_zero)=NaN;
%     level(r).coverage=coverage;
%     %level(r).look=look;
%     coverage=zeros(x_size,y_size,z_size);
    %look=zeros(x_size,y_size,N);
end
keep coverage



