Hi Shreya,
As per my understanding of the above question, you would like to find the space coordinates for the upper surface of your 3D model. Assuming you currently have the mesh matrix as ‘p’.
For finding the coordinates of the upper surface in the ‘p’ matrix, you will need to find the indices where the z-coordinates has the maximum value. Then we can extract the space coordinates of the maximum z-coordinates using the ‘find’ function in MATLAB. You can refer to the below code for extracrting the coordinates.
Find the maximum z-coordinate value
max_z = max(p(3,:));
% Find indices of points with maximum z-coordinate
upper_boundary_indices = find(p(3,:) == max_z)
% Extract upper boundary points
upper_boundary_points = p(:,upper_boundary_indices);
Here is an illustration code which highlights the upper surface of a 3D model.
model = femodel(Geometry="BracketTwoHoles.stl");
model= generateMesh(model);
mesh=model.Geometry.Mesh;
pdeplot3D(mesh);
hold on
[p,y,z]= meshToPet(mesh);
% Find the maximum z-coordinate value
max_z = max(p(3,:));
% Find indices of points with maximum z-coordinate
upper_boundary_indices = find(p(3,:) == max_z);
% Extract upper boundary points
upper_boundary_points = p(:,upper_boundary_indices)
% Plotting the upper surface points with red color
scatter3(upper_boundary_points(1,:), upper_boundary_points(2, :), upper_boundary_points(3, :), 'MarkerEdgeColor', [1 0 0]);
hold off;
Feel free to explore more functionalities of 'find' function by using the documentation link below:
I hope this helps in resolving the query.