Cutting area plot matlab
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I have a given 3D surface plot My problem is drawing an area, f and cutting out exactly this area from the given plot.Please help!
3 Commenti
Risposta accettata
darova
il 13 Apr 2020
What about this?
clc,clear
% generate surface
r = 0:0.1:5;
t = linspace(0,2*pi,30);
[T,R] = meshgrid(t,r);
Z = 5*sin(R)./R;
[X,Y] = pol2cart(T,R);
% data for cutting
x = [1 3 0.7];
y = [0.2 0.3 3];
z = [1 1.2 1];
ix = convhull(X(:),Y(:)); % boundary of surface
x1 = X(ix(1:end-2)); % vertices of boundary
y1 = Y(ix(1:end-2));
gd1 = [2; length(x1); x1(:); y1(:)]; % surface boundary geometry
gd2 = gd1;
gd2(1:2+2*length(x)) = [2; length(x); x(:); y(:)]; % cutting plane boundary geometry
dl = decsg([gd1 gd2],'P1-P2',char('P1','P2')'); % decomposite geometry
[p,e,t] = initmesh(dl,'hmax',0.5); % create mesh
F = scatteredInterpolant(X(:),Y(:),Z(:));
zz = F(p(1,:),p(2,:)); % calculate Z coordinate for each mesh point
fv.vertices = [p;zz]'; % x y z data
fv.faces = t(1:3,:)'; % connection list of faces
cla
patch(fv,'facecolor','r') % surface
patch(x,y,z,'g') % cutting plane
view(150,45)
axis vis3d
ix = convhull(X(:),Y(:)); % boundary of surface
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/284203/image.png)
9 Commenti
darova
il 16 Apr 2020
I choosed XZ plane to detect if points inside triangle (i used inpolygon)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/285156/image.png)
Since there are another vertices inside i added Y axis condition:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/285157/image.png)
where y1 - triangle verices, y2 - surface vertices
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/285158/image.png)
Result
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/285159/image.png)
Was not that easy! See attached script
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Surface and Mesh Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!