How to draw 2d compass in 3d UIAxes

5 ビュー (過去 30 日間)
Kurt
Kurt 2023 年 4 月 7 日
コメント済み: Kurt 2023 年 4 月 11 日
Is it possible to use the compass() function to draw a compass rose in a UIAxes object? I don't care about the function depicted by the compass, I just want the circles and degree text for other purposes. Here is my code:
function draw_compass(em)
th = linspace(0,.001,1000);
r = linspace(5000,384400,1000);
[u,v] = pol2cart(th,r);
pax = compass(em.UIAxes,u,v);
for i = 1:1000 % hide the arrows
pax(i).LineStyle = 'none';
end
end
If I run draw_compass() as a standalone function, it works just fine.
When I try to display this in my UIAxes, I get a "bowtie" effect from the hidden arrows, but no range circles or compass angle text. What gives?
I also tried polarplot(), but it doesn't like my Cartesian coordinate system. Also tried a flattened ellipse, but the range circles are uneven, and I would still have to add text for the angles.
If none of this works, I will have to hand-jam all the circles and radial lines and text the hard way.

採用された回答

Kevin Holly
Kevin Holly 2023 年 4 月 7 日
編集済み: Kevin Holly 2023 年 4 月 7 日
It is possible to place the compass rose in a 3D uiaxes. Did you want to plot something in addition to this? If so, you may have difficulties if you try plotting a 3D scatter on top with scatter3.
ax = uiaxes;
th = linspace(0,.001,1000);
r = linspace(5000,384400,1000);
[u,v] = pol2cart(th,r);
compass(ax,u,v)
for ii = 1:length(ax.Children)
delete(ax.Children(1))
end
view(3)
  8 件のコメント
Kurt
Kurt 2023 年 4 月 10 日
I found the problem. "hold" was set. If I call
hold(em.UIAxes,'off')
the compass appears.
I dug into the compass() code and found that it really just calls polar(), so I can probably use that instead.
This also explains why running the compass function standalone worked: hold was off by default.
Kurt
Kurt 2023 年 4 月 11 日
Kevin made an important point earlier. If you plot underneath this compass, you won't be able to see your data. compass(), which is really based around plot(), is opaque and does not respond to alpha transparancy settings either. So, if you want a compass you can see through, you will need to create it yourself from scratch.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePolar Plots についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by