MATLAB: Does using ginput on 3d surfaces not return the correct point of contact

3dginputMATLABselect3dsurfaces

Why does using ginput on 3d surfaces not return the correct point of contact?
If I use ginput on a 3-D plot, such as a surface, the coordinates returned are not the coordinates where the mouse touches the surface. In fact, the coordinates do not appear to make any sense at all. Why is this happening?

Best Answer

When you click on the figure window with the mouse, you are actually defining a line traveling into the screen along the line of sight. The 'CurrentPoint' property of the axis stores the endpoints of this
line, where the endpoints are defined by the axis limits in each dimension. The endpoints are defined in three dimensions (i.e., each endpoint is a 3-element vector); the first row of the 'CurrentPoint' value represents the endpoint farthest away from the viewer, while the second row represents the endpoint closest to the viewer.
Since the GINPUT function was intended for use with 2-D plots, it only returns two values, the x and y coordinates of the endpoint farthest from the viewer. That is, GINPUT returns the (1,1) and (1,2) elements of the 2-by-3 matrix returned by
get(gca, 'CurrentPoint')
Note: In two dimensional plots, since the line travels directly perpendicular to the X-Y plane, this accurately represents the (x,y) coordinates of the intersection of the line with the plane.
Instead of using the GINPUT function, you can use the SELECT3D function to select 3D points on surface and patch objects. This function can be found on MATLAB Central at: