Specifying 3D points with the mouse

12 vues (au cours des 30 derniers jours)
Lindley French
Lindley French le 22 Nov 2011
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 commentaire
MUTHUKUMAR SETHURAM
MUTHUKUMAR SETHURAM le 6 Mai 2016
how to lattitude and longitude value from world Globe(3d) for when you click mouse in matlab ???
Thanks in Advance

Connectez-vous pour commenter.

Réponse acceptée

Sven
Sven le 23 Nov 2011
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 commentaire
Puneeth Meruva
Puneeth Meruva le 20 Juin 2013
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?

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Data Exploration dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by