developer
developer

Reputation: 658

3D mouse input in matlab/simulink

I want to take input coordinates through mouse in Matlab oR Simulink, there is no built-in facility in Matlab of input of 3D coordinate through mouse device, however the buit-in function ginput can only store 2D coordinates of mouse, is there is any possibility in MATLAB/SIMULINK to input 3D coordinates through mouse device?

Upvotes: 0

Views: 2595

Answers (1)

user1004061
user1004061

Reputation: 103

If I understand you correctly, you want to get the coordinates (in data space) of the mouse click, when the plot is 3D. That is, you click somewhere in the plot and it returns your current position. I have actually tackled this exact problem before.

The main difficulty with this task--and the other posters have alluded to it--is that you are clicking on a 2D screen. Thus, you cannot specify 3 independent positions on a 2D screen uniquely. Rather, clicking on the screen defines a line segment, normal to the plane of the screen, and any of the 3D points along this line are equally valid. Do you understand why this is the case?

To demonstrate, try this short example in Matlab:

surf(peaks);  %draw a sample plot
keydown = 2;
while keydown ~= 0,
   disp('Click some where on the figure');
   keydown = waitforbuttonpress;   
end
currPt = get(gca,'CurrentPoint');
disp(currPt);

You'll observe that currPt is a 2x3 matrix. This defines the start and end points of this line. Let's plot this line now:

hold on;
plot3( currPt(:,1), currPt(:,2), currPt(:,3), 'k-', 'LineWidth', 2);
view(-19,46);  %rotate to view this line

So the question is: how to define which point along this line you want to select? Well the answer depends on what type of data you have in the first place. If you have point data, choosing one of your vertices exactly can be tricky, and you might need to do some post-processing of your data (for example, to calculate the closest point in your dataset to the currPt line). If you have patch or surface data (such as this example), this is just the intersection of a line and a plane.

There are some tools on the File Exchange to get 3D points for various datasets. One that I just found is: http://www.mathworks.com/matlabcentral/fileexchange/7594-click3dpoint

Upvotes: 1

Related Questions