How can I calculate the area of my surface plot in MATLAB 7.9 (R2009b)?

53 views (last 30 days)
I am visualizing a surface with the SURF command, and I would like to know the surface area of the surface.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 16 Nov 2009
There is no function in MATLAB which directly calculates the surface area of a surface, however the necessary calculations can be done in a fairly straightforward way.
To compute the area of a surface, it is necessary to compute the area of each rectangular face of the surface and then add them together. To compute the area of each rectangular face, it is convenient to imagine the face as being split into two triangular pieces. To compute the area of a triangle in a three-dimensional space, the cross product can be used. If the coordinates of the vertices are given by the vi=(xi, yi, zi), then the area, A, can be calculated as:
A = 1/2 * |(v2 - v1) x (v3 - v1)|
With that in mind, the following code will loop over each rectangular face in the patch, compute the area of the face, and add it to the total area:
[x,y,z] = peaks;
[m,n] = size(z);
area = 0;
for i = 1:m-1
for j = 1:n-1
v0 = [x(i,j) y(i,j) z(i,j) ];
v1 = [x(i,j+1) y(i,j+1) z(i,j+1) ];
v2 = [x(i+1,j) y(i+1,j) z(i+1,j) ];
v3 = [x(i+1,j+1) y(i+1,j+1) z(i+1,j+1)];
a = v1 - v0;
b = v2 - v0;
c = v3 - v0;
A = 1/2*(norm(cross(a, c)) + norm(cross(b, c)));
area = area + A;
fprintf('\nTotal area is: %f\n\n', area);

More Answers (0)

MathWorks Support


No tags entered yet.




Community Treasure Hunt

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

Start Hunting!