Specifying 3D points with the mouse

조회 수: 12 (최근 30일)
Lindley French
Lindley French 2011년 11월 22일
댓글: MUTHUKUMAR SETHURAM 2016년 5월 6일
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 CenterFile Exchange에서 Data Exploration에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by