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!

