Specifying 3D points with the mouse

10 ビュー (過去 30 日間)
Lindley French
Lindley French 2011 年 11 月 22 日
I would like to be able to specify points on the X-Y plane with the mouse, but do so on a 3D plot. For any give point clicked, there should be a unique position on the X-Y plane (except in the degenerate case when the camera is on the X-Y plane).
The math is fairly simple if I can get the figure coordinates clicked by the mouse on a 3D plot. If I recover the projection matrix with T = view;, I think I should be able to back out the transformation by T if I hold z=0.
However, ginput is not returning sensible values when I try this. I am not able to determine what it is trying to return but it is not useful.
Any suggestions?
  1 件のコメント
MUTHUKUMAR SETHURAM
MUTHUKUMAR SETHURAM 2016 年 5 月 6 日
how to lattitude and longitude value from world Globe(3d) for when you click mouse in matlab ???
Thanks in Advance

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

採用された回答

Sven
Sven 2011 年 11 月 23 日
In short, don't use ginput(), use get(ax,'CurrentPoint') instead.
Basically the current position of the mouse, combined with the view matrix defines a stabbing vector. It will be up to you to interpret which plane that stabbing vector should intersect. Here is an example which prints out a coordinate in the view axes whenever the mouse moves. You could instead assign it to a 'onButtonPress' callback if you like. I'll be honest and say I can't quite remember which plane the view matrix uses by default, but it sounds from your question like you're on top of interpreting the result of the matrix transformation and are more interested in the replacement of ginput() with something more useful:
function example
figure('WindowButtonMotionFcn',@(src,evnt)printPos())
plot3(rand(5,1),rand(5,1)*20,rand(5,1)*5,'.'), view(3)
function printPos
clickedPt = get(gca,'CurrentPoint');
VMtx = view(gca);
point2d = VMtx * [clickedPt(1,:) 1]';
disp(point2d(1:3)')
end
end
  1 件のコメント
Puneeth Meruva
Puneeth Meruva 2013 年 6 月 20 日
2 Questions:
1. The three values returned by the example are x,y,z coordinates, right?
2. If so, what location within the figure is considered the origin?

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Exploration についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by