how to select patch surface in gui

7 次查看(过去 30 天)
Xiwen
Xiwen 2024-4-8
评论: Xiwen 2024-4-16
Hi all,
I am looking for a method to select the patch surface in a 3D plot. In figure GUI, I can only select the node and get nodal position information through updateFun. The datacursormode.target has the patch data stored in there. Is there a way to change the cursor selection method from node to surface in a 3D mesh? Thanks in advance!

回答(1 个)

Ramtej
Ramtej 2024-4-16
Hi,
MATLAB's data cursor mode primarily focuses on points (nodes) rather than entire surfaces. However, you can leverage "ButtonDownFcn"of the plotting function to extract and display information related to the surface (patch) under the clicked point, rather than just the nodal information.
Below code demonstrates how to identify when a patch object is selected when you left click anywhere on the surface and toggles the marker (of vertices) and linewidth property of patch to distinguish it visually.
You can extend the functionality within the "myCustomUpdateFcn" function to include more specific information about the patch.
x1 = [0 0 1 1];
y1 = [3 3 2 2];
z1 = [0 3 2 1];
c1 = [0 0.447 0.741];
x2 = [2 2 3 3];
y2 = [1 1 0 0];
z2 = [1 2 3 0];
c2 = [0.850 0.325 0.098];
fill3(x1,y1,z1,c1,x2,y2,z2,c2, "ButtonDownFcn",@myCustomFcn);
% Define the custom update function
function myCustomFcn(~,event_obj)
target = event_obj.Source;
% Check if the target is a patch
if isa(target, 'matlab.graphics.primitive.Patch')
if target.Marker == "none"
target.Marker = 'o';
target.LineWidth = 3;
else
target.Marker = "none";
target.LineWidth = 0.5
end
% Now target is your selected patch
% Add your own code to modify patch
end
end
If you are trying to modify patch properties, refer the below documentaton for changing patch appearance and behavior.
  1 个评论
Xiwen
Xiwen 2024-4-16
Hi using this method, I select the whole patch. My patch has many faces in it. I am more interested to select the individual face inside a patch.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Polygons 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by