How to extract coordinates of a point in a 3d plot by zooming and changing orientation?

22 次查看(过去 30 天)
Suppose I have created a figure in which the anatomy of the heart has been reconstructed using the patch command by using the vertices and faces of the anatomy itself.
On top of this I have superimposed some points (3d coordinates) using the plot3 command.
I would like to extract the coordinates of one or more points by being able to zoom in to select the point more precisely and by changing the 3d orientation of the object.
I have already implemented a solution through the use of the datatips by automatically saving the selected points in the workspace.
I would like to use something similar to ginput but that should work for a 3d plot also by varying the orientation. Also other solution are accepted.
  2 个评论
Dyuman Joshi
Dyuman Joshi 2023-12-22
You should be able to click on the point and a data tip will come up. You can export the data tip.
Hold shift to collect multiple points at once.

请先登录,再进行评论。

回答(1 个)

Shubham
Shubham 2023-12-28
Hey Luca,
I understand that you want to extract coordinates of a point in a 3D plot while being able to change the zoom and orientation.
You can go through the following MATLAB answer which was recently added by MathWorks Support Team that suggests using data cursor for getting data from a 3D plot:
You can select multiple data points by enabling the "datacursormode" and clicking on the desired points. You can also mimic the functionality of "ginput" where you keep selecting points until "return" key is pressed. Refer to the following code snippet:
[X, Y, Z] = sphere(10);
X = X(:);
Y = Y(:);
Z = Z(:);
figure;
ax = axes;
scatter3(ax, X, Y, Z, 'filled');
% Call the function to select points in the 3D plot
selectedPoints = select3DPoints(ax);
disp('Selected Points:');
disp(selectedPoints);
function selectedPoints = select3DPoints(ax)
selectedPoints = [];
% Enable data cursor mode.
dcm_obj = datacursormode(gcf);
set(dcm_obj, 'UpdateFcn', @myupdatefcn, 'SnapToDataVertex', 'on');
datacursormode on;
disp('Select points in the 3D plot. Press "Return" when done.');
waitfor(gcf, 'CurrentCharacter', char(13));
% Nested function to update the data cursor text and store points.
function txt = myupdatefcn(~, event_obj)
pos = get(event_obj, 'Position');
txt = {['X: ', num2str(pos(1))], ...
['Y: ', num2str(pos(2))], ...
['Z: ', num2str(pos(3))]};
selectedPoints = [selectedPoints; pos];
end
end
You can precisely select the data points using the “datacursormode” while being able to pan, zoom or change the orientation.
You can have a look at this MATLAB answer by MathWorks Support Team for selecting points in 3D as analogous to “ginput” in 2D: https://www.mathworks.com/matlabcentral/answers/93089
Please also find “ginput3d” function available on file exchange as well:
Hope this helps!!

类别

Help CenterFile Exchange 中查找有关 Graphics Object Programming 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by