Fill below the 3D terrain data

조회 수: 6 (최근 30일)
burak ergocmen
burak ergocmen 2024년 2월 22일
댓글: burak ergocmen 2024년 9월 26일
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