%% Initial test and plot of the model %% model - structure describing the 2D rectangular model. %% The structure should contain the following fields: %% model.xz0 - array of (x,z) coordinates of the upper-left corner %% model.dxz - array of (dx,dz) increments in the grid (cell dimensions) %% model.nx and model.nz - numbers of grid cells model.xz0 = [0.0, 0.0]; model.dxz = [20.0, 20.0]; model.nx = 10; model.nz = 10; model.ncells = model.nx*model.nz; % total number if model parameters src = [ 0, 70 ]; %src = [ 0, 100 ]; src = [ 0, 80 ]; src = [ 30, 10 ]; % test source position rec = [ 200, 20 ]; %rec = [ 200, 100 ]; rec = [ 200, 40 ]; rec = [ 200, 150 ]; % test receiver % The following shows how you can trace an arbitarry ray. % Note that by dropping the semicolon ';' at the end of this line, you can view % the contents of matrix 'ray' As any other Matlab variable). % Each column contains information about a cell crossed by this ray, % as explained in the description of function 'trace_ray()' ray = trace_ray(model,src,rec); % Note that in matrix L, the ray is represented by a row containing the ray-segment lengths % within each model cell. This row can be easily obtained like this: rowL = zeros(1,model.ncells); % first, initialize with zeros rowL(1,ray(1,:)) = ray(2,:); % put segment lengths into columns corresponding to cells % plot the model and ray % =================================================================== figure(1) clf set(gca,'Ydir','reverse') plot_model(model) plot([src(1),rec(1)],[src(2),rec(2)],'g-') % original ray plot(ray(3,:),ray(4,:),'bo') % entry points into cells plot(ray(5,:),ray(6,:),'r+') % exit points from cells ray % print the expected ray length and the sum of its segments ray_length = distance(src,rec) sum_segments = sum(ray(2,:),2)