Meshgrid lighning and how to use contour around the plot
2 ビュー (過去 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!