How do I graph and calculate the volume between two surfaces?
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Ayush Gupta
am 27 Aug. 2020
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 Kommentare
Siehe auch
Kategorien
Mehr zu Polygons finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!