MATLAB: Calculate area within mesh plot

areaconvex hullMATLABmeshsurface area

Hello all, i am looking to calculate the area of a section of mesh plot. I have attahced a photo of the mesh plot for your sake. You will see that the mesh plot is a bowl shape and i want to calcualte the area (or volume, but ideally area) of the dark blue region at the bottom of the bowl. I am looking to calaculte the area of the plot when Z < 0.01 (for example).
Any ideas on how to do this?
Adam

Best Answer

Hi Adam,
According to my understanding, you want to calculate the surface area of a certain portion of your graph. I have made an assumption that you will be identifying this portion by limiting the z - values of the plot as you have stated taking Z < 0.01 as an example. In that case, we can divide the plot into triangles and then sum the areas of the smaller triangles to find the area of the plot.
To do this, I would suggest plotting your data in the form of a 3 - D triangular mesh and create a triangulation object to plot. This is because we can leverage some properties of the triangulation object to calculate the areas of the triangles that form the plot. I am sharing a simple example to demonstrate my point.
[X,Y] = meshgrid(-8:.05:8);
R = sqrt(X.^2 + Y.^2) + eps;
Z = sin(R)./R; %the function to be plotted
T = delaunay(X,Y); %creates a 2-D Delaunay triangulation from the points in X and Y
TO = triangulation(T,X(:),Y(:),Z(:)); %creates a 3-D triangulation representation with the point coordinates specified as column vectors X, Y, and Z
trimesh(TO) %plots the triangular mesh
The triangulation object TO has two properties TO.Points and TO.ConnectivityList.
Triangulation connectivity list, specified as an m-by-3 matrix, where m is the number of triangles in the plot. Each row of T contains the vertex IDs that define a triangle.
Points, specified as a matrix whose columns are the x-coordinates, y-coordinates, and z-coordinates of the triangulation points. The row numbers of P are the vertex IDs in the triangulation.
The code below calculates the surface area of the graph of the function defined above but ignores those where the functional value is greater than 0.4 (you can replace this with your threshold value and function).
area = 0; %initialize the area
%loop over all the desired small triangles and accumulate the areas
for i = 1:size(TO.ConnectivityList,1) %the number of rows gives the number of triangles produced
a = TO.Points(TO.ConnectivityList(i,:),:); %this gives the 3 vertices of the ith triangle
if any(a(:,3) > 0.4)
continue; %if the triangle has a vertex whose z - coordinate is > 0.4 ignore it
end
%extract the three vertices
p1 = a(1,:);
p2 = a(2,:);
p3 = a(3,:);
area = area + 0.5 * norm(cross(p2-p1,p3-p1)); %calculate the area of the small triangle and add with previous result
end
You may use these ideas to calculate the area of the graph that satisfies certain conditons on the function range.
See [1],[2] and [3] to learn more about the concepts used above.
Related Question