plot a 3d function (with three independent variable)

 Respuesta aceptada

Star Strider
Star Strider el 24 de Abr. de 2021
The isosurface function would likely be most apprroppriate.
See the documentation section on Volume Visualization for more options.

6 comentarios

hi, thanks for your answer but i want it with shadows like this picture i tried this code but it wasn't like my picture
My pleasure!
I have no idea what you intend by ‘shadows’, since all that is necessary to produce them is to create a lighting effect.
Example —
N = 50;
xv = linspace(-10,10, N);
yv = linspace(-10,10, N);
zv = linspace(-10,10, N);
vfcn = @(x,y,z) 4*x.^2 + 9*y.^2 + 4*z.^2;
[Xm,Ym,Zm] = meshgrid(xv,yv,zv);
Vm = vfcn(Xm,Ym,Zm);
figure
p = patch(isosurface(Xm, Ym, Zm, Vm, 36));
isonormals(Xm,Ym,Zm,Vm,p)
p.FaceColor = 'red';
p.EdgeColor = 'none';
daspect([1 1 1])
view(3);
% axis tight
axis('equal')
camlight
lighting gouraud
grid on
hold on
plot3([-5 5], [0 0], [0 0], '-k')
plot3([0 0], [-5 5], [0 0], '-k')
plot3([0 0], [0 0], [-5 5], '-k')
hold off
text(-6, 0, 0, '$x$', 'Interpreter','latex', 'FontSize',20)
text(0, -6, 0, '$y$', 'Interpreter','latex', 'FontSize',20)
text(0, 0, 6, '$z$', 'Interpreter','latex', 'FontSize',20)
This is partially copied from the isosurface documentation.
thank you so much and how can i unfill the graph like picture?
My pleasure!
If by ‘unfill’ you mean to see inside it, add this assignment —
p.FaceAlpha = 0.75; % See Inside The Volume!
so the revised code is now —
N = 50;
xv = linspace(-10,10, N);
yv = linspace(-10,10, N);
zv = linspace(-10,10, N);
vfcn = @(x,y,z) 4*x.^2 + 9*y.^2 + 4*z.^2;
[Xm,Ym,Zm] = meshgrid(xv,yv,zv);
Vm = vfcn(Xm,Ym,Zm);
figure
p = patch(isosurface(Xm, Ym, Zm, Vm, 36));
isonormals(Xm,Ym,Zm,Vm,p)
p.FaceColor = 'red';
p.EdgeColor = 'none';
p.FaceAlpha = 0.75; % See Inside The Volume!
daspect([1 1 1])
view(3);
axis tight
camlight
lighting gouraud
grid on
hold on
plot3([-5 5], [0 0], [0 0], '-k')
plot3([0 0], [-5 5], [0 0], '-k')
plot3([0 0], [0 0], [-5 5], '-k')
hold off
text(-6, 0, 0, '$x$', 'Interpreter','latex', 'FontSize',20, 'Horiz','center', 'Vert','middle')
text(0, -6, 0, '$y$', 'Interpreter','latex', 'FontSize',20, 'Horiz','center', 'Vert','middle')
text(0, 0, 6, '$z$', 'Interpreter','latex', 'FontSize',20, 'Horiz','center', 'Vert','middle')
Change that value to something between 0 (fully transparent) and 1 (not at all transparent) to get the result you want.
.
thanks alot
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Productos

Versión

R2018a

Etiquetas

Preguntada:

el 24 de Abr. de 2021

Comentada:

el 25 de Abr. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by