Calculating the Volume between two 3D surfaces/meshes

6 visualizzazioni (ultimi 30 giorni)
I have two sets of data for the same surface, each with X, Y and Z coordinates. One data set for before and one for after the surface undergoes deformation. I am trying to calculate the volume between the two surfaces to quantify the change. My code is as follows:
clear,clc,close all
Table = readtable ('Final Data','Sheet','Analysis Data', 'ReadRowNames', true,'PreserveVariableNames', true);
%Sample Before
xs1 = Table ('X-P1B',:);
ys1 = Table ('Y-P1B',:);
zs1 = Table ('Z-P1B',:);
xn1 = table2array(xs1);
yn1 = table2array(ys1);
zn1 = table2array(zs1);
X1 = linspace(min(xn1),max(xn1),250);
Y1 = linspace(min(yn1),max(yn1),250);
[xq1,yq1] = meshgrid(X1,Y1);
zq1 = griddata(xn1,yn1,zn1,xq1,yq1,'natural');
%Volume Calculation
dxn1 = (max(xn1)-min(xn1))/250;
dyn1 = (max(yn1)-min(yn1))/250;
volB= dxn1*dyn1*sum(zq1(~isnan(zq1)));
%volk = trapz(Y1,trapz(X1,zq1(~isnan(zq1)),2)); Does not work.
plot3(xn1,yn1,zn1,'mo')
hold on
mesh(xq1,yq1,zq1)
xlabel('x')
ylabel('y')
%Sample After
xs2 = Table ('X-P1A',:);
ys2 = Table ('Y-P1A',:);
zs2 = Table ('Z-P1A',:);
xn2 = table2array(xs2);
yn2 = table2array(ys2);
zn2 = table2array(zs2);
X2 = linspace(min(xn2),max(xn2),250);
Y2 = linspace(min(yn2),max(yn2),250);
[xq2,yq2] = meshgrid(X2,Y2);
zq2 = griddata(xn2,yn2,zn2,xq2,yq2,'natural');
%Volume Calculation
dxn2 = (max(xn2)-min(xn2))/250;
dyn2 = (max(yn2)-min(yn2))/250;
volA= dxn2*dyn2*sum(zq2(~isnan(zq2)));
%volk = trapz(Y2,trapz(X2,zq2(~isnan(zq2)),2)); Does not work.
plot3(xn2,yn2,zn2,'mo')
hold on
mesh(xq2,yq2,zq2)
xlabel('x')
ylabel('y')
The first method I have used to calculate volume, returs a value. However, I am unsure of which reference plane has been used to calculate the volume. I assume it would be the plane formed by min(yn1) (or min(yn2) in the second case) and the meshgrid. Is it possible to define a common reference plane for both the Before and After Surfaces, so that simply the difference between the two can give me the desired result.
I've tried using trapz but that returns "Point spacing must be a scalar specifying uniform spacing or a vector of x-coordinates for each data point."
Thanks.

Risposte (1)

KSSV
KSSV il 7 Feb 2022
  2 Commenti
Keith Hay
Keith Hay il 7 Feb 2022
I tried using trapz as:
volk = trapz(Y1,trapz(X1,zq1(~isnan(zq1)),2));
It returns the error "Point spacing must be a scalar specifying uniform spacing or a vector of x-coordinates for each data point.". The same happens when I try the method you linked.
KSSV
KSSV il 7 Feb 2022
When you consider only numbers and remove nans the grid and data dimension changes.

Accedi per commentare.

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by