How can I calculate the area of my surface plot in MATLAB 7.9 (R2009b)?
조회 수: 12 (최근 30일)
이전 댓글 표시
I am visualizing a surface with the SURF command, and I would like to know the surface area of the surface.
채택된 답변
MathWorks Support Team
2009년 11월 16일
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;
end
end
fprintf('\nTotal area is: %f\n\n', area);
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!