How to find volume under 2D data?

18 次查看(过去 30 天)
Stefan Carson
Stefan Carson 2020-7-16
I have a set of 2D (x and y) data, that has an irregular shape and it's not axisymmetric. I want to find the volume under this surface (due to rotation around y-axis or if there is a better way). I am not sure how to do it and I thought about using solid of revolution but I don't think it is suitable for this case. Any idea how I can find the volume?

回答(2 个)

Walter Roberson
Walter Roberson 2020-7-16
[idx, volume] = boundary(x(:), y(:), 1);
plot(x(idx), y(idx), 'y-*')
The plot() will illustrate the boundary that is found, and the variable volume will be the area contained within the boundary.
The area might not be the most accurate possible, but it is not clear what area would be accurate considering the gap.
A different calculation method would be to separate it into segments without gaps and use trapz() on each of those. You would then have to figure out area was implied by the gaps.
  6 个评论
Stefan Carson
Stefan Carson 2020-7-16
The location of the peak is already known, and I am trying to figure out how to calculate the volume either by slicing and assuming it's a circular disk or rotation about the y-axis. Thank you for your help and have a good night sleep.
Walter Roberson
Walter Roberson 2020-7-16
To rotate around the axes x = location_of_peak:
Let x at the location of the peak be and y at peak be
For any one y in the range to , find the x before the peak at which that y occurs, and the x after the peak at which that y occurs, . Then rotating around at that y will occupy a circle of radius contributing an area of and the volume would be like
trapz(Y, pi*max(xplus(Y,xp)-xp, xp-xminus(Y,xp)).^2)
for a vector of Y from 0 to yp, and functions xplus and xminus .
I show xplus and xminus as having xp as a parameter because in practice they would be search or interpolation routines that are going to need to know the position of the peak so that they can extract the correct value. In practice it might be the index of xp rather than the value of xp that is more useful.
It looks to me as if your y values are monotonic on each side of the peak, so I guess
xminus = @(Y, xpindex) interp1(y(1:xpindex), x(1:xpindex), Y)
and if so then it should work for vector Y rather than having to loop. xplus would be similar,
xplus = @(Y, xpindex) interp1(y(xpindex:end), x(xpindex:end), Y)

请先登录,再进行评论。


Bruno Luong
Bruno Luong 2020-7-16
编辑:Bruno Luong 2020-7-16
% Generate some fake data, replace r with your X and y with your Y vector
% you need to peak either side r >= 0 or r <= 0 NOT both
r=linspace(0,150);
s=r/r(end);
y=polyval([-50 -100 160],s)
plot(r,y)
V = 2*pi*trapz(r,y.*abs(r)) % <- Volume formula
  6 个评论
Stefan Carson
Stefan Carson 2020-7-17
Sorry for not being clear and filling in the gaps in my question. I was trying to explain that if I assume the shape is a semisphere, the value of the integral or trapz() will be overestimated and it does not correspond to the correct value. This is mainly because the left and the right sides about the x-axis are not symmetric and it becomes complex trying to rotate or assume it's a disk to perform the calculation by slicing. Thank you.
Bruno Luong
Bruno Luong 2020-7-17
编辑:Bruno Luong 2020-7-17
Why reinvent the wheel?
The integration schemes are studied in long and large in the history, and people derive scheme such as trapezoidal rule for generic discrete data. If you know your function is smooth, then Simson has derive more accurate rules (for such function) without the need of doing explicit interpolation.
So just change the trapz rule by simpson
But look at your data on left/right side; I think your data has more error than any scheme effect. Might be it's wrong to assume the solid is a revolution about y-axis/ You might be better doing some fitting and not interpolation, since those oscillation looks to me like measurement artefact than real.
But only you know the quality of your data. No numerical scheme can recover bad measurements.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Numerical Integration and Differentiation 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by