Fill below the 3D terrain data

6 次查看(过去 30 天)
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,

采纳的回答

Tejas
Tejas 2024-9-17
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 个评论
Tejas
Tejas 2024-9-24
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 2024-9-26
thank you it is really helpful
Best wishes

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Spline Postprocessing 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by