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

24 visualizaciones (últimos 30 días)
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 comentarios
Dyuman Joshi
Dyuman Joshi el 22 de Dic. de 2023
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 el 22 de Dic. de 2023
Already implemented this solution also automatically saving in the workspace the points selected.

Iniciar sesión para comentar.

Respuestas (1)

Shubham
Shubham el 28 de Dic. de 2023
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!!

Categorías

Más información sobre Graphics Object Programming en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by