Meshgrid lighning and how to use contour around the plot

4 visualizaciones (últimos 30 días)
Apo
Apo el 4 de Oct. de 2022
Editada: Cris LaPierre el 4 de Oct. de 2022
I've been trying to make a meshgrid with a certain lighting and two contours around the plot. But I'm stuck and help would be appreciated.
To make it easier to understand I'm trying to do this:
But my result is:
And below is the code I'm using for said result:
x=linspace(-2,2,1000);
y=x';
[X,Y]=meshgrid(x,y);
z=exp(-(X.^2+Y.^2));
surf(x,y,z);
shading interp
colormap summer
lighting gouraud
contour3(X,Y,Z,[0.8 0.8], 'g', 'LineWidth',1)
contour3(X,Y,Z,[0.2 0.2], 'r', 'LineWidth',1)
So the problem is how do I get the lighting right and how do I get the lines around.

Respuesta aceptada

Cris LaPierre
Cris LaPierre el 4 de Oct. de 2022
Editada: Cris LaPierre el 4 de Oct. de 2022
You might find the settings in this example helpful. Not a perfect match, but here's what I came up with
x=linspace(-2,2,1000);
y=x';
[X,Y]=meshgrid(x,y);
z=exp(-(X.^2+Y.^2));
h=surf(x,y,z);
shading interp
colormap summer
lightangle(0,88)
h.FaceLighting= 'gouraud';
h.AmbientStrength = 0.3;
h.DiffuseStrength = 0.5;
h.SpecularStrength = 0.8;
h.SpecularExponent = 10;
h.BackFaceLighting = 'unlit';
hold on
contour3(X,Y,z,[0.8 0.8], 'g', 'LineWidth',1)
contour3(X,Y,z,[0.2 0.2], 'r', 'LineWidth',1)
hold off

Más respuestas (1)

Simon Chan
Simon Chan el 4 de Oct. de 2022
For the accurate solution, you need to find those x and y where z=0.2 and 0.8.
If an estimated solution is accepted, the positions on the grid close to this value can be selected by selecting a proper threshold.
However, if the threshold is too low, you will see a broken circle. On the other hand, if the threshold is too large, multiple circles will appear. So you need to choose the threshold carefully.
x=linspace(-2,2,1000);
y=x';
[X,Y]=meshgrid(x,y);
z=exp(-(X.^2+Y.^2));
s=surf(x,y,z);
shading interp
colormap summer
lighting gouraud
Th = 0.0015; % Threshold to find those positions close to the specific value
idx1 = abs(z-0.8)<Th;
xp = X(:);
yp = Y(:);
idxp = idx1(:);
hold on
c1 = scatter3(xp(idxp),yp(idxp),repelem(0.8,sum(idxp),1), 'g','SizeData',1);
idx2 = abs(z-0.2)<Th;
idxq = idx2(:);
c2 = scatter3(xp(idxq),yp(idxq),repelem(0.2,sum(idxq),1), 'r','SizeData',1);
hold off

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by