Is there a MATLAB function that can compute the area of my patch?

38 ビュー (過去 30 日間)
MathWorks Support Team
MathWorks Support Team 2012 年 2 月 8 日
編集済み: MathWorks Support Team 2019 年 8 月 29 日
I use the ISOSURFACE function to generate a patch object:
[x,y,z,v] = flow;
p = patch(isosurface(x,y,z,v,-3));
isonormals(x,y,z,v,p)
set(p,'FaceColor','red','EdgeColor','none');
daspect([1 1 1])
view(3);
camlight
lighting gouraud
I would like to find the area of the patch "p".

採用された回答

MathWorks Support Team
MathWorks Support Team 2019 年 8 月 29 日
編集済み: MathWorks Support Team 2019 年 8 月 29 日
There is no function which directly calculates the surface area of a patch object in MATLAB, however the calculations can be done in a fairly straightforward way using the 'Faces' and 'Vertices' properties of the patch object.
The surface area of the entire patch is then the sum of the areas of all the patch faces. The area of each triangular face can be computed with a cross product. Here is an example:
[x,y,z,v] = flow;
p = patch(isosurface(x,y,z,v,-3));
isonormals(x,y,z,v,p)
set(p,'FaceColor','red','EdgeColor','none');
daspect([1 1 1])
view(3);
camlight
lighting gouraud
verts = get(p, 'Vertices');
faces = get(p, 'Faces');
a = verts(faces(:, 2), :) - verts(faces(:, 1), :);
b = verts(faces(:, 3), :) - verts(faces(:, 1), :);
c = cross(a, b, 2);
area = 1/2 * sum(sqrt(sum(c.^2, 2)));
fprintf('\nThe surface area is %f\n\n', area);
If the patch object is constructed with faces that are not triangular (for example, they are rectangular), then each face can be broken down into triangular pieces (a rectangular face can be thought of as two triangular faces).
  1 件のコメント
Rik
Rik 2016 年 11 月 3 日
You should rescale your coordinates from voxels to millimeter. As only the 'verts' vector contains coordinates, you only have to change that one.
So in your case the code below should give you the area in square mm (area will never be in cubic mm, if you are looking for volume, try meshVolume by David Legland):
conversionMatrix=repmat([0.42 0.42 0.25],[length(verts) 1]);
verts_mm=verts.*conversionMatrix;
a = verts(faces(:, 2), :) - verts(faces(:, 1), :);
b = verts(faces(:, 3), :) - verts(faces(:, 1), :);
c = cross(a, b, 2);
area = 1/2 * sum(sqrt(sum(c.^2, 2)));
fprintf('\nThe surface area is %f\n\n', area);

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLighting, Transparency, and Shading についてさらに検索

製品


リリース

R14SP2

Community Treasure Hunt

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

Start Hunting!

Translated by