how to select patch surface in gui

11 views (last 30 days)
Xiwen
Xiwen on 8 Apr 2024
Commented: Xiwen on 16 Apr 2024
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!

Answers (1)

Ramtej
Ramtej on 16 Apr 2024
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 Comment
Xiwen
Xiwen on 16 Apr 2024
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.

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!