Collection of mesh nodes with a mouse click

18 ビュー (過去 30 日間)
Antonio Gambardella
Antonio Gambardella 2023 年 3 月 29 日
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

採用された回答

Jack
Jack 2023 年 3 月 29 日
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.
  1 件のコメント
Antonio Gambardella
Antonio Gambardella 2023 年 3 月 30 日
Thank you very much @Jack! You have been a great help

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Performance についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by