Adding a polyshape to a 3D plot (a la patch)
显示 更早的评论
In the attached .mat file is a polyshape object which, when plotted in 2D, looks like an annulus,
Hpgon = plot(pgon); axis equal

Now, however, I would like to add this shape to the xy-plane of a 3D plot axis, filled with the same color. My first thought was to use patch(), as follows
vertices3D=pgon.Vertices;
vertices3D(:,3)=0;
faces3D=1:size(vertices3D,1);
patch('Vertices',vertices3D,'Faces',faces3D,'FaceColor',Hpgon.FaceColor);
camva auto
axis vis3d
This fails however, resulting in the unfilled plot below. I can see that patch() is having trouble interpreting this as a closed shape, but am not sure what the most efficient remedy would be. What is the best way to give patch() the same smarts as polyshape.plot()? Might there be an altogether different alternative to patch? It seems a shame that I cannot somehow do this directly with the polyshape object

采纳的回答
更多回答(1 个)
load('example.mat')
Hpgon = plot(pgon); axis equal
vertices3D=pgon.Vertices;
vertices3D(:,3)=0;
faces3D=1:size(vertices3D,1);
vertices3D = [ NaN NaN NaN ;vertices3D ] ;
patch('Vertices',vertices3D,'Faces',faces3D,'FaceColor',Hpgon.FaceColor);
camva auto
axis vis3d

10 个评论
KSSV
2019-3-26
It is working for second case also...the logic is the first and last points are joining...you should stop joining them...I have used NaN for this. Try:
vertices3D = [ NaN NaN NaN ;vertices3D;NaN NaN NaN ] ;
Matt J
2019-3-26
KSSV
2019-3-26
I got this output:

Matt J
2019-3-26
KSSV
2019-3-26
What version you are on?
Matt J
2019-3-26
KSSV
2019-3-26
I am on 2017b. You can save and share only vertices3D as a mat file.....it can be checked I guess.
Matt J
2019-3-26
Matt J
2019-3-26
类别
在 帮助中心 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

