3D Polygon with varying z height does not fill correctly

2 views (last 30 days)
Hello!
I am really sorry as this seems such a silly question but I just don't seem to be able to get my 3D polygon right - the filling of the polygon cuts weirdly across an area where the z values vary a lot.
I attach the variable "M" where the first, second and third column correspond to x, y and z coordinates of 34 points (34 rows). This first 17 and the last 17 rows are vaguely parallel to each other (plotted in red and green in figure 1). I would like to fill the space between the parallel lines in such a way that the result contains panes like illustrated by the black connecting lines in figure 1. However, the result I get cuts strangely across the areas where the z values go up and down (see figure 2).
I know I could achieve this by just plotting 16 small polygons with 4 corners but it would much better if it could be achieved with a single shape as I will need a few hundred of these shapes and thousands of small polygons seem to make the 3D plot hard to rotate...
It would be fantastic if someone could help me with this problem!
Best,
Julia
This is the code I have used for the figures:
figure(1)
hold on
plot3(M(1:17,1),M(1:17,2),M(1:17,3),'r')
plot3(M(18:34,1),M(18:34,2),M(18:34,3),'g')
% Add connecting lines to illustrate desired shape
M2 = M(1:17,:);
M3 = flipud(M(18:34,:));
for i = 1:17
plot3([M2(i,1) M3(i,1)],[M2(i,2) M3(i,2)],[M2(i,3) M3(i,3)],'k')
end
figure(2)
polygon = patch(M(:,1),M(:,2),M(:,3),'b')

Answers (0)

Categories

Find more on Surfaces, Volumes, and Polygons in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!