Meshgrid lighning and how to use contour around the plot

조회 수: 3 (최근 30일)
Apo
Apo 2022년 10월 4일
편집: Cris LaPierre 2022년 10월 4일
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.

채택된 답변

Cris LaPierre
Cris LaPierre 2022년 10월 4일
편집: Cris LaPierre 2022년 10월 4일
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

추가 답변 (1개)

Simon Chan
Simon Chan 2022년 10월 4일
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

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by