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

24 ビュー (過去 30 日間)
Luca Tropeano
Luca Tropeano 2023 年 12 月 22 日
回答済み: Shubham 2023 年 12 月 28 日
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.
Luca Tropeano
Luca Tropeano 2023 年 12 月 22 日
Already implemented this solution also automatically saving in the workspace the points selected.

サインインしてコメントする。

回答 (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 Center および File ExchangeGraphics Object Programming についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by