1 function XX=add_terrain_to_mesh(X, kind, how, val)
2 % XX=add_terrain_to_mesh(X, kind, how, val)
3 % Modify 3D mesh vertically to follow terrain
6 % numeric uniform shift up
7 % how 'shift' move up each column the same
8 % 'squash' keep top flat
9 % val relative height of the hill
15 x = X{1}(:,:,1); y=X{2}(:,:,1);z=X{3};
22 hz = max(z(:))-min(z(:));
23 rx = mean(abs((x(:)-cx)));
24 ry = mean(abs((y(:)-cy)));
25 a = ((x-cx)./rx).^2 + ((y-cy)./ry).^2 ;
30 hz = max(z(:))-min(z(:));
31 rx = mean(abs((x(:)-cx)));
35 error('add_terrain_to_mesh: unknown kind')
37 elseif isnumeric(kind),
40 error('kind must be string or numeric')
44 disp('shifting mesh by terrain vertically')
47 XX{3}(:,:,k)=X{3}(:,:,k)+t;
49 case {'compress','c','squash'}
50 if any(any(t > X{3}(:,:,end))),
51 error('shift values are too large to be compressed')
53 disp('compressing mesh keeping top unchanged')
56 XX{3}(:,:,k)=X{3}(:,:,k)+t*(XX{3}(1,1,kmax) - XX{3}(1,1,k)) / XX{3}(1,1,kmax);
59 error('add_terrain_to_mesh: unknown how')