use the 'patch' function with different results (using different matrices)

3 ビュー (過去 30 日間)
Alberto Acri
Alberto Acri 2023 年 9 月 26 日
コメント済み: Walter Roberson 2023 年 9 月 26 日
Hi! I have two matrices: 'V' and 'trace'.
Using patches with V generates a completely black surface on the figure and I'm fine with it.
When I use the 'trace' matrix the result is different. How come? Is there a way to display 'trace' in the image in the same way as 'V'?
load V
axes1 = axes('Parent',figure);
patch(V(:,1), V(:,2),V(:,3),'k');
view(axes1,[45.7625707544407 8.27114462456761]);
axis equal
%%
load trace
axes2 = axes('Parent',figure);
patch(trace(:,1), trace(:,2),trace(:,3),'r');
view(axes2,[31.7625655339418 23.9174311926605]);
axis equal
  3 件のコメント
Alberto Acri
Alberto Acri 2023 年 9 月 26 日
The matrices are different. I expected that using the 'trace' matrix I would get a black geometry display similar to the one I got with the V matrix!
Walter Roberson
Walter Roberson 2023 年 9 月 26 日
Why would you expect that?
Remember that for patch(), points are considered to be ordered
If you sort the original points by angle, and plot the sort order:
load trace
axes3 = axes('Parent', figure);
tc = mean(trace,1);
ang = atan2(trace(:,2) - tc(2), trace(:,1) - tc(1));
[~, order1] = sort(ang);
[~, order2] = sort(order1);
plot(order2)
adjacent points on input bounce back and forth in angle order -- and not even alternately.
figure();
plot(order2(1:50))

サインインしてコメントする。

採用された回答

Matt J
Matt J 2023 年 9 月 26 日
編集済み: Matt J 2023 年 9 月 26 日
If you are trying to recover the boundary from a surface triangulation, then,
load trace
[~,P]=freeBoundary(delaunayTriangulation(trace(:,1:2)));
Warning: Duplicate data points have been detected and removed.
The Triangulation indices are defined with respect to the unique set of points in delaunayTriangulation.
[~,loc]=ismember(P,trace(:,1:2),'rows');
V=num2cell([P,trace(loc,3)],1);
patch(V{:},'k');
view([31.7625655339418 23.9174311926605]);
axis equal

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2023 年 9 月 26 日
In your first patch() call you ask for 'k' -- black -- for the faces. The edge colors default to black as well.
In the second patch() call you ask for 'r' -- red -- for the faces. The edge colors default to black.
The V matrix has coordinates for a simple circle. The trace matrix has much more complex coordinates, going back and forth.
If you were to sort the coordinates then you could get a circle as well. But remember that the coordinates for patch() are ordered so those represent completely different graphing tasks.
load V
axes1 = axes('Parent',figure);
patch(axes1, V(:,1), V(:,2), V(:,3), 'facecolor', 'r', 'facealpha', 0.5, 'edgecolor', 'k');
view(axes1,[45.7625707544407 8.27114462456761]);
axis(axes1, 'equal');
%%
load trace
axes2 = axes('Parent',figure);
patch(axes2, trace(:,1), trace(:,2), trace(:,3), 'facecolor', 'r', 'facealpha', 0.5, 'edgecolor', 'k');
view(axes2,[31.7625655339418 23.9174311926605]);
axis(axes2, 'equal');
axes3 = axes('Parent', figure);
tc = mean(trace,1);
ang = atan2(trace(:,2) - tc(2), trace(:,1) - tc(1));
[~, order] = sort(ang);
patch(axes3, trace(order,1), trace(order,2), trace(order,3), 'facecolor', 'r', 'facealpha', 0.5, 'edgecolor', 'k');
view(axes3,[31.7625655339418 23.9174311926605]);
axis(axes3, 'equal')
  1 件のコメント
Walter Roberson
Walter Roberson 2023 年 9 月 26 日
Note that if you know you have scattered coordinates, then see also boundary instead of the sorting method I used.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGraphics Object Programming についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by