How to measure surface area layer by layer using Matlab

4 views (last 30 days)
M.S. Khan
M.S. Khan on 22 Aug 2020
Commented: M.S. Khan on 24 Aug 2020
i am using following code to find area of layers. I am trying but masking somewhere some mistake. Any help from community will be highly appreciated.
Attached file are the xyz-coordinates. I measure the surface area of one layer using bellow code. This coding is combining all layers. I want to find area of each layer individually. Regards to all for their cooperation and guidance.
vertices = load(' attached file ')
vertices = round(sortrows(vertices,2));
Vx = round(vertices(:,1));
Vy = round(vertices(:,2));
Vz = round(vertices(:,3));
G_surface_area =0
layer = []
surface_area = 0
for i = min(Vy):10:max(Vy) % This for loop, i am using to measure by 10 spacing.
minVy = i
for j = i:i + 9 % This measure is for layer to find its area.
layer_new = vertices(any(Vy== j,2),:);
layer = [layer; {layer_new}];
end
layer = cell2mat(layer)
Lx = layer(:,1);
Ly = layer(:,2);
Lz = layer(:,3);
surface_area = polyarea(Lx,Lz)
G_surface_area = G_surface_area + surface_area
end

Accepted Answer

KSSV
KSSV on 22 Aug 2020
Edited: KSSV on 23 Aug 2020
data = importdata("Cone_20000_points.txt") ;
data = round(data) ;
x = data(:,1) ; y = data(:,2) ; z = data(:,3) ;
zi = unique(z) ;
N = length(zi) ;
A = zeros(N,1) ;
tol = 10^-5 ;
for i = 1:N
idx = abs(z-zi(i))<=tol ;
% layer coordinates
xl = x(idx) ; yl = y(idx) ; zl = z(idx) ;
Layer = [x(idx) y(idx) z(idx)] ; % these are the Layer coordinates
% get boundary of layer
id = boundary(xl,yl) ;
Boundary = [xl(id) yl(id) zl(id)] ; % Boundary coordinates
A(i) = polyarea(xl(id),yl(id)) ;
end
  18 Comments

Sign in to comment.

More Answers (1)

M.S. Khan
M.S. Khan on 24 Aug 2020
Hi Dear KSSV, along with your code, i followed following procedure ( hints from Mr. Uday) to generate the traingulated mesh of the cone. Then i estimated the area of triangulated cone. could you please guide, am i correct??
bx = Boundary(:,1) ; by = Boundary(:,2) ; bz = Boundary(:,3) ;
T = delaunay(bx, by)
TO = triangulation(T, bx(:),by(:),bz(:)); %creates a 3-D triangulation representation with the point coordinates specified as column vectors X, Y, and Z
trimesh(TO) %plots the triangular mesh
%It will mesh the cone with triangles.
%Get the area of each triangle and sum them.
% This will give you surface area.
%% How to find area
area = 0; %initialize the area
%loop over all the desired small triangles and accumulate the areas
for i = 1:size(TO.ConnectivityList,1) %the number of rows gives the number of triangles produced
a = TO.Points(TO.ConnectivityList(i,:),:); %this gives the 3 vertices of the ith triangle
if any(a(:,3) > max(bz))
continue; %if the triangle has a vertex whose z - coordinate is > 0.4 ignore it
end
%extract the three vertices
p1 = a(1,:);
p2 = a(2,:);
p3 = a(3,:);
format compact
area = area + 0.5 * norm(cross(p2-p1,p3-p1)); %calculate the area of the small triangle and add with previous result
end
area
  4 Comments
M.S. Khan
M.S. Khan on 24 Aug 2020
This area is in pixels, right. Do you have any idea how to convert them into mm^2.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by