How do I graph and calculate the volume between two surfaces?
55 次查看(过去 30 天)
显示 更早的评论
I have 3d coordinates in the minus region (known x,y,z) a flat surface in the +ve matching the x,y coordinates and I want to make a volume between these 2 surfaces and calculate it as well.
Thanks! I can plot both surfaces just fine I need help connecting them:
Here is part of my code:
xv = linspace(min(x), max(x), nx);
yv = linspace(min(y), max(y), ny);
[X,Y] = meshgrid(xv, yv);
Z1 = griddata(x,y,z1,X,Y);
Z2 = griddata(x,y,z2,X,Y);
surf(X, Y, Z1);
hold on;
surf(X, Y, Z2);
0 个评论
回答(1 个)
Ayush Gupta
2020-8-27
The issue is to locate the boundary. Once you have it, it's easy: here is an example continuing your code assuming that the boundary is known (cylinder with octagonal base)
% Getting boundary.
bw = ~(isnan(z1) | isnan(z2));
bw_flled = imfill(bw,'holes');
boundaries = bwboundaries(bw_flled) ;
boundary = boundaries{1} ;
% - Define x,y,z1,z2 values on the boundary.
Xbnd = x(sub2ind(size(x), boundary(:,1), boundary(:,2))) ;
Ybnd = y(sub2ind(size(y), boundary(:,1), boundary(:,2))) ;
Z1bnd = z1(sub2ind(size(z1), boundary(:,1), boundary(:,2))) ;
Z2bnd = z2(sub2ind(size(z2), boundary(:,1), boundary(:,2))) ;
% - Define patches nodes.
Xdata = [Xbnd(1:end-1), Xbnd(2:end), Xbnd(2:end), Xbnd(1:end-1)].' ;
Ydata = [Ybnd(1:end-1), Ybnd(2:end), Ybnd(2:end), Ybnd(1:end-1)].' ;
Zdata = [Z1bnd(1:end-1), Z1bnd(2:end), Z2bnd(2:end), Z2bnd(1:end-1)].' ;
% - Plot patches.
patch(Xdata, Ydata, Zdata, 'm') ;
%Enable 3D rotations with the mouse in the figure.
rotate3d ;
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 3-D Volumetric Image Processing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!