help me plot 3D graph like these picture

1 view (last 30 days)

Accepted Answer

Ameer Hamza
Ameer Hamza on 28 Apr 2020
Edited: Ameer Hamza on 28 Apr 2020
Try this
x = linspace(0,1,500);
y = linspace(0,1,500);
[Xg, Yg] = meshgrid(x, y);
mask = Yg > sqrt(Xg);
Zg = 1 - Yg;
Zg(~mask) = nan;
surf(Xg, Yg, Zg, 'FaceColor', 'b', 'FaceAlpha', 0.4, 'EdgeColor', 'none')
hold on
y = linspace(0,1,500);
z = linspace(0,1,500);
[Yg, Zg] = meshgrid(y, z);
mask = Yg < 1 - Zg;
Xg = Yg.^2;
Xg(~mask) = nan;
surf(Xg, Yg, Zg, 'FaceColor', 'b', 'FaceAlpha', 0.4, 'EdgeColor', 'none')
view(gca,[115 45]);
  3 Comments
Ameer Hamza
Ameer Hamza on 28 Apr 2020
The is no direct way to draw such surfaces in MATLAB. If the surfaces are flat, then you can also use patch(). But if they are curved, then we need to deal with every surface individually
% surface x+2y+z=2
x = linspace(0, 1, 500); % range of x-values
y = linspace(0, 1, 500); % range of y-values
[Xg, Yg] = meshgrid(x, y); % mesh of x-y for this surface
mask = Yg < -1/2*Xg + 1; % equation of surface (x+2y+z=2) on the x-y plane is y = -x/2+1
mask = mask & (Yg > 1/2*Xg); % equation of surface (x=2y) on the x-y plane is y = x/2
Zg = 2 - Xg - 2*Yg;
Zg(~mask) = nan;
surf(Xg, Yg, Zg, 'FaceColor', 'b', 'FaceAlpha', 0.4, 'EdgeColor', 'none')
hold on
y = linspace(0, 0.5, 500);
z = linspace(0, 2, 500);
[Yg, Zg] = meshgrid(y, z);
mask = Zg < -4*Yg + 2;
Xg = 2*Yg;
Xg(~mask) = nan;
surf(Xg, Yg, Zg, 'FaceColor', 'b', 'FaceAlpha', 0.4, 'EdgeColor', 'none')
daspect([1 1 1]);
view(gca,[70 30]);

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!