Collection of mesh nodes with a mouse click
18 views (last 30 days)
Show older comments
Antonio Gambardella
on 29 Mar 2023
Commented: Antonio Gambardella
on 30 Mar 2023
Hello everyone.
I have a mold mesh on which I would like to select paths by selecting 2 or more points on the mesh plot by selecting them with mouse click.
So, I would like to select a number "n" of elements from a 3d plot of a mesh (n is not defined from the beginning) and save these points in an array.
Has anyone faced a similar problem before?
Does anyone have any suggestions?
Thanks in advance
0 Comments
Accepted Answer
Jack
on 29 Mar 2023
Hi,
Yes, it is possible to select points from a 3D plot using mouse clicks and save them in an array. One way to do this is to use the "datacursormode" and "getCursorInfo" functions in MATLAB.
Here's an example code that demonstrates how to do this:
% Load your mold mesh data and plot it
load('mold_mesh.mat')
trisurf(triangles,vertices(:,1),vertices(:,2),vertices(:,3))
% Enable data cursor mode
dcm_obj = datacursormode(gcf);
set(dcm_obj,'DisplayStyle','datatip','SnapToDataVertex','off','Enable','on')
% Initialize an empty array to store selected points
selected_points = [];
% Wait for user to select points and press enter to stop
disp('Select points on the mesh using mouse clicks. Press enter to stop.')
while true
% Wait for user to click on a point
pause
c_info = getCursorInfo(dcm_obj);
if isempty(c_info) % User pressed enter
break
end
% Get the coordinates of the selected point
point = c_info.Position;
% Add the point to the array
selected_points = [selected_points; point];
end
% Print the selected points
disp('Selected points:')
disp(selected_points)
In this code, the "datacursormode" function is used to enable data cursor mode, which allows the user to select points on the plot using mouse clicks. The "getCursorInfo" function is used to get the coordinates of the selected point, which is then added to the "selected_points" array. The loop continues until the user presses enter to stop selecting points.
Note that this code assumes that the mold mesh is stored in variables named "triangles" and "vertices". You may need to modify the code to match your specific mesh data format.
More Answers (0)
See Also
Categories
Find more on Graphics Performance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!