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

9 views (last 30 days)
"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?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 15 Apr 2019

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')

More Answers (0)

Categories

Find more on Elementary Polygons in Help Center and File Exchange

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!