How do I calculate the volume between two 3D-surfaces?

8 views (last 30 days)
Dear users,
I am having trouble with calculating the volume between two 3D-surfaces in Matlab.
I have two surfaces, which both consists of 5 cross-sections which are linearly interpolated to retrieve the surface. The second surface is an adaptation to the first, in which in this case only the 'bottom' two values of the three middle cross-sections are raised by 0.5. I would like to calculate the volume between the two surfaces, to estimate the volume I need to get from one surface to another. How do I get this volume? I am preferably looking for a solution which is also able to produce the volume if points to the side of the currently adjusted points are adjusted (i.e. if for example the bottom 3 points on either side of x=0 are raised).
I have made the lower surface transparent in the plot below, such that you can see the volume that is in between.
I tried using the trapz-function, but that does not let me use a matrix as an input for X.
Can anyone help me out how to properly calculate this? I imagine it must be fairly simple, but it has got my mind twisted at this point.
x = load('x.mat');
x = x.x;
y = load('y.mat');
y = y.y;
z = load('z.mat');
z = z.z;
z_upd = load('z_upd.mat');
z_upd = z_upd.z_upd;
% Note: all values are symmetrical around x = 0
figure
hold on
surf(x,y,z)
alpha 0.5
surf(x,y,z_upd)
hold off
xlabel('x')
ylabel('y')
zlabel('z')
view(-60,0)
  2 Comments
Jeffrey Clark
Jeffrey Clark on 24 Jun 2022
Edited: Jeffrey Clark on 24 Jun 2022
@Birgit, since you seem to only refer to surfaces but then ask for volumn between them, are you just asking for the volumn contained by the two surfaces that are slightly offset but joined for the rest of the much larger surface? Like the more luminous red here?

Sign in to comment.

Answers (1)

William Rose
William Rose on 25 Jun 2022
See attached script. It approximates the volume between the surfaces.
I notice that the x-coordinates of the points in the surface are somewhat irregularly spaced. As a result, the surface grid, when viewed from directly above, is composed of many trapezoids. It would have been a lot easier if the points were on a regular grid. If the points are on a regular grid, the approximation used in this script will be exactly correct.
The surface is 5x40. Therefore there are 4x39 six-sided volume elements between the surfaces. The script computes the area perpendicular to the z-axis of each volume element (i.e. the area of a trapezoid, which varies across the surface, due to the irregular x coordinates). Then it computes the average difference between the top surface height and bottom surface height. The volume of hte enclosed element is approximately the area times the average height difference. These volumes are added up to get the total volume between the surfaces.
I did two tests of the routine, which you can see as commented-out lines in the code: 1. Make the top surface equal to the bottom, in which case the total enclosed volume should be zero. 2. Make the top surface everywhere one unit higher than the bottom surface, in which case the volume should equal the area of the total surface in the x-y plane, times one. Both tests passed.
See comments in the code for more details.

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by