Fill below the 3D terrain data

6 views (last 30 days)
burak ergocmen
burak ergocmen on 22 Feb 2024
Commented: burak ergocmen on 26 Sep 2024
A=imread('appRasterNEDAPIService1708354512850-756880040.tif');
X=1:324;
Y=1:194;
[X,Y]=meshgrid(X,Y);
surf(X,Y,A)
Hello. I have this terrain data. The size of A matrix is 194x324 and contain elevation data. I want to fill below the terrain from the elevation of the data to the 0 (mean sea level). I use fill code
hFill = fill3(X, Y, A, patchColor, 'LineWidth', 1, 'EdgeColor', patchColor, ...
'FaceAlpha', 0.5);
However, it only fill below the surface with thin layer. I try to fill from the elevation to the 0 (mean sea level).
Thank you,

Accepted Answer

Tejas
Tejas on 17 Sep 2024
Hello Burak,
To fill the terrain from the elevation data down to mean sea level, you can create polygons that act like vertical planes or walls. These polygons start at the terrain surface and extend down to the z-plane at 0, which represents sea level.
Here is a code snippet demonstrating how this can be achieved:
patchColor = [0.5, 0.5, 0.5]; % Gray color
for i = 1:size(A, 2)
x = [X(:, i); flipud(X(:, i))]; % x cordinates for ith polygon
y = [Y(:, i); flipud(Y(:, i))]; % y cordinates for ith polygon
z = [zeros(size(A, 1), 1); flipud(A(:, i))];
fill3(x, y, z, patchColor, 'EdgeColor', 'none', 'FaceAlpha', 0.5);
end
Below is a screenshot of the output using sample data, showing how the terrain will appear:
For a better understanding of this solution, refer to the documentations below:
  5 Comments
Tejas
Tejas on 24 Sep 2024
Hi Burak,
The issue arises because the 'hold' function has not been used. This causes the polygon plot for a column of matrix A to overwrite the existing plot. For more details on the 'hold' function, refer to this documentation: https://www.mathworks.com/help/releases/R2023b/matlab/ref/hold.html
Try this code snippet:
load("terrain.mat");
% Plot the terrain surface
figure;
surf(X, Y, A);
hold on;
patchColor = [0.5, 0.5, 0.5]; % Gray color
for i = 1:size(A, 2)
x = [X(:, i); flipud(X(:, i))]; % x cordinates for ith polygon
y = [Y(:, i); flipud(Y(:, i))]; % y cordinates for ith polygon
z = [zeros(size(A, 1), 1); flipud(A(:, i))];
fill3(x, y, z, patchColor, 'EdgeColor', 'none', 'FaceAlpha', 0.5);
end
% Adjust plot settings
xlabel('X');
ylabel('Y');
zlabel('Elevation');
title('3D Terrain with Filled Base');
view(3);
axis tight;
hold off;
Here is a screenshot of the output:
burak ergocmen
burak ergocmen on 26 Sep 2024
thank you it is really helpful
Best wishes

Sign in to comment.

More Answers (0)

Categories

Find more on Spline Postprocessing in Help Center and File Exchange

Products


Release

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!