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,
댓글 수: 0
채택된 답변
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
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:
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Spline Postprocessing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!