Vertices2Volume

This function computes the volume of a 3D objects given its vertices X, Y, Z.
ダウンロード: 14
更新 2023/11/9

ライセンスの表示

% Volume of a cylinder of radius 2, and height 3
r = 2; h = 3;
[X, Y, Z] = cylinder([0,r,r,0], 32);
Z([1,2],:) = 0; Z([3,4],:) = h;
figure(color = 'w')
% using matlab's convex hull function
[tri, vol1] = convhull(X, Y, Z);
subplot(1,2,1)
trisurf(tri, X, Y, Z, FaceColor='cyan')
title('Convex Hull')
axis equal
% new Vertices to volume function
vol2 = Vertices2Volume(X, Y, Z);
subplot(1,2,2)
surf(X, Y, Z, FaceColor='cyan');
title('Actual object')
axis equal;
% analytical solution
vol3 = pi*r^2*h;
error1 = 100*abs(vol1-vol3)/vol3;
error2 = 100*abs(vol2-vol3)/vol3;
% Volume of a sphere of radius 2,
r = 2;
[X, Y, Z] = sphere(32);
X = r*X; Y = r*Y; Z = r*Z;
figure(color = 'w')
% using matlab's convex hull function
[tri, vol1] = convhull(X, Y, Z);
subplot(1,2,1)
trisurf(tri, X, Y, Z, FaceColor='cyan')
title('Convex Hull')
axis equal
% new Vertices to volume function
vol2 = Vertices2Volume(X, Y, Z);
subplot(1,2,2)
surf(X, Y, Z, FaceColor='cyan');
title('Actual object')
axis equal;
% analytical solution
vol3 = 4*pi*r^3/3;
error1 = 100*abs(vol1-vol3)/vol3;
error2 = 100*abs(vol2-vol3)/vol3;
% Volume of a Torus with minor radius 1 and major radius 5
r = 1.5; R = 4; u = linspace(0, 2*pi, 33);
z = r*sin(u); x = R + r*cos(u);
v = linspace(0, 2*pi, 65)';
X = cos(v)*x; Y = sin(v)*x;
Z = ones(size(v))*z;
figure(color = 'w')
% using matlab's convex hull function
[tri, vol1] = convhull(X, Y, Z);
subplot(1,2,1)
trisurf(tri, X, Y, Z, FaceColor='cyan')
title('Convex Hull')
axis equal
% new Vertices to volume function
vol2 = Vertices2Volume(X, Y, Z);
subplot(1,2,2)
surf(X, Y, Z, FaceColor='cyan');
title('Actual object')
axis equal;
% analytical solution
vol3 = 2*pi^2*r^2*R;
error1 = 100*abs(vol1-vol3)/vol3;
error2 = 100*abs(vol2-vol3)/vol3;

引用

Lateef Adewale Kareem (2024). Vertices2Volume (https://www.mathworks.com/matlabcentral/fileexchange/154825-vertices2volume), MATLAB Central File Exchange. に取得済み.

MATLAB リリースの互換性
作成: R2023b
すべてのリリースと互換性あり
プラットフォームの互換性
Windows macOS Linux
タグ タグを追加

Community Treasure Hunt

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

Start Hunting!
バージョン 公開済み リリース ノート
1.0.0