# How to measure the volume of a cone using surface area of triangles in matlab

조회 수: 4 (최근 30일)
M.S. Khan 2020년 8월 26일
댓글: M.S. Khan 2020년 8월 27일
i am using this code (Mr. David), How to measure volume of whole cone. Please guide. Regards in advance.
x = Coords(:,1);
y = Coords(:,2);
z = Coords(:,3);
% move to origin
x = x-mean(x);
y = y-mean(y);
z = z-mean(z);
% convert to spherical system
[t,p,r] = cart2sph(x,y,z);
tri = delaunay(t,p);
trisurf(tri,x,y,z)
% indices of triangle
i1 = tri(:,1);
i2 = tri(:,2);
i3 = tri(:,3);
% vectors of triangle base
v1 = [x(i1)-x(i2) y(i1)-y(i2) z(i1)-z(i2)];
v2 = [x(i1)-x(i3) y(i1)-y(i3) z(i1)-z(i3)];
A = 1/2*cross(v1,v2,2); % surface of a triangle
V = 1/3*dot(A,[x(i1) y(i1) z(i1)],2); % volume of a triangle
format long
V = sum(abs(V))
##### 댓글 수: 3이전 댓글 1개 표시이전 댓글 1개 숨기기
Bruno Luong 2020년 8월 26일
편집: Bruno Luong 2020년 8월 26일
Sight, this is not the way anyone suppose to ask questions
• Where is the file 'Bruno_Cone_20000_points.txt'?
• What is "this code (Mr. David)"? Where is the reference?
• I suppose the code try to approximate the volume of the cone?
• Does the result match what you expect?
• If not please elaborate.
M.S. Khan 2020년 8월 26일
sorry for inconvenience.

댓글을 달려면 로그인하십시오.

### 채택된 답변

Bruno Luong 2020년 8월 26일
편집: Bruno Luong 2020년 8월 26일
Your post is not clear (see our comments). However I guess what you want is approximate the volume of the (cone) object from the point cloud.
% Cone parameters
R = 10;
h = 20;
N = 10000;
% Generate points in cone
dx = (pi*R^2*h/3/N)^(1/3);
rvec = linspace(-R,R,ceil(2*R/dx));
hvec = linspace(0,h,ceil(h/dx));
[X,Y,Z] = ndgrid(rvec,rvec,hvec);
is_in_cone = (X.^2+Y.^2) <= (R/h*(h-Z)).^2;
x = X(is_in_cone);
y = Y(is_in_cone);
z = Z(is_in_cone);
% Method1: Estimate the volume of the 3D object assuming the object is convex
tri = delaunay(x,y,z);
trisurf(tri,x,y,z)
% indices of triangle
i1 = tri(:,1);
i2 = tri(:,2);
i3 = tri(:,3);
i4 = tri(:,4);
% Method1: Volume by summing tetrahedron
v1 = [x(i1)-x(i2) y(i1)-y(i2) z(i1)-z(i2)];
v2 = [x(i1)-x(i3) y(i1)-y(i3) z(i1)-z(i3)];
v3 = [x(i1)-x(i4) y(i1)-y(i4) z(i1)-z(i4)];
A = 1/2*cross(v1,v2,2); % surface of a triangle
V = 1/3*dot(A,v3,2); % volume of a tetrahedron
format long
V = sum(abs(V))
% Method2: use CONVHULL
[~,V]=convhull(x,y,z)
% Method3: theoretical volume of a cone computed directly from base radius and heigh
V = pi*R^2*h/3
##### 댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
M.S. Khan 2020년 8월 27일
Thanks Bruno Luong. God bless you. Regards!

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!

Translated by