How do I plot several polyshape objects on different levels of a 3D plot?

조회 수: 9 (최근 30일)
"polyshape" objects can be plotted very easily with something like the following:
plot ( this_polyshape )
However, in order to have an easy comparison, I would like to put more than one "polyshape" object into the same plot but with each object on a different X-Y plane.
How can I achieve this?

채택된 답변

MathWorks Support Team
MathWorks Support Team 2019년 4월 15일

You could use "polyshape" to create the initial 2D shape. Afterwards, you can use the function "alphaShape" to add the Z dimension and, lastly, you can plot them using a standard "plot3" function.

Please find below a simple example that you might want to use as a starting point to develop your own solution.

% Generate the initial polyshape object
p1 = polyshape([0 0 1 1],[1 0 0 1]);
p2 = polyshape([0 0 1 1],[1 0 0 1]);
% Extract the vertices of the objects
v1 = p1.Vertices;
v2 = p2.Vertices;
% Use alphaShape to add the Z dimension
a1 = alphaShape( v1(:,1), v1(:,2), 0.1*ones(size(v1,1), 1));
a2 = alphaShape( v2(:,1), v2(:,2), 0.2*ones(size(v2,1), 1));
% Plot the three objects in the same 3D plot
plot3(a1.Points(:,1),a1.Points(:,2),a1.Points(:,3),'b')
hold on
plot3(a2.Points(:,1),a2.Points(:,2),a2.Points(:,3),'r')

Please note that the plots generated with the code above will not be closed as there could not be repeated vertices in the same "alphaShape" object If you want the shape to be closed, a simple way to do it is to add the initial points in the "plot3" instances, such as in the following example:

plot3([a1.Points(:,1); a1.Points(1,1)],[a1.Points(:,2); a1.Points(1,2)],[a1.Points(:,3); a1.Points(1,3)],'b')

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Elementary Polygons에 대해 자세히 알아보기

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by