Meshgrid lighning and how to use contour around the plot
조회 수: 3 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
채택된 답변
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
댓글 수: 0
추가 답변 (1개)
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!