Why does using "ginput" on 3D surfaces not return the correct point of contact?

16 views (last 30 days)
Why does using "ginput" on 3D surfaces not return the correct point of contact?
If I use "ginput" on a 3D 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?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 8 Nov 2023
Edited: MathWorks Support Team on 22 Nov 2023
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 data cursor to get data from a 3-D plot.
After clicking on a point in the graph, you can right-click on the data tip that appears and select "Export Cursor Data to Workspace"; the position information will then be accessible in the exported variable. Additionally, if you wish to do this programmatically, you can use the following code with 'getCursorInfo':
dcm = datacursormode(gcf)
% Click on the figure (hold the 'Alt' key and click to select multiple points)
data = getCursorInfo(dcm)
% This will return an array of data point info (if multiple points selected); the coordinates can be accessed via 'data.Position'

More Answers (0)

Categories

Find more on Visual Exploration in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!