How to measure surface area layer by layer using Matlab

5 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

KSSV
KSSV il 22 Ago 2020
Modificato: KSSV il 23 Ago 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 Commenti
M.S. Khan
M.S. Khan il 23 Ago 2020
Modificato: M.S. Khan il 23 Ago 2020
Dear KSSV, the code is giving some erros as following. i am trying to remove errors.
Error using cat
Dimensions of arrays being concatenated are not consistent.
Error in cell2mat (line 75)
m{n} = cat(2,c{n,:});
Error in untitled4 (line 20)
Boundary = cell2mat(Boundary) ;
The used of braces in Boundary{i} = [xl(id) yl(id) zl(id)] is making problem.

Accedi per commentare.

Più risposte (1)

M.S. Khan
M.S. Khan il 24 Ago 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 Commenti
KSSV
KSSV il 24 Ago 2020
That's good... hope the present answer and your formula obtained value are close. You can mail me through my author page or send me linkedin request, we can keep in touch.
M.S. Khan
M.S. Khan il 24 Ago 2020
This area is in pixels, right. Do you have any idea how to convert them into mm^2.

Accedi per commentare.

Categorie

Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by