How to get the mouse coordinates in a 3D spherical plot?

3 ビュー (過去 30 日間)
Heba El-Fiqi
Heba El-Fiqi 2019 年 5 月 5 日
コメント済み: Heba El-Fiqi 2019 年 5 月 7 日
I plot the globe in 3D, and would like to get the latitude and longtitude of the current mouse position.
I tried to use get(gca,'CurrentPoint'), and I don't know how to map those coordinates to the equivalent latitude and longtitude on the map. I think the camera view has some effect as well.
figure('units','normalized','outerposition',[0 0 1 1]);
h=axesm ('globe','Grid', 'on');
axis off;
base = zeros(180,360); baseref = [1 90 0];
geoshow(base,baseref,'FaceColor','white')
load coast; % load all the map lines
plotm(lat, long); % plot the world maps
view([90 0 0])

採用された回答

darova
darova 2019 年 5 月 5 日
If you have x,y,z coordinates use spherical system coordinate:
theta is longitude (from equator), phi - latitude
Latitude:
lat1 = asind(z); % asin() [0 .. 90]degree
Longitude
t = asind(y/cosd(lat1));
Choose angle for longitude (0 .. 360)
t = [t, 180-t, 180+t, 360-t];
x1 = cosd(t)*cosd(lat1);
y1 = sind(t)*cosd(lat1);
long1 = t( abs(x-x1+y-y1) < 1e-3 );
  3 件のコメント
darova
darova 2019 年 5 月 5 日
I picked some points with Data Cursor and export them to workspace
Heba El-Fiqi
Heba El-Fiqi 2019 年 5 月 7 日
Thank you Darova, I understand now why it works compared to what I was testing.
I think the issue now is only about finding a continues way of mapping the current mouse location to its equivalent data cursor values. The globe projection makes it very different.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMap Display についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by