Scatter3 and surf yields a bug?

1 回表示 (過去 30 日間)
Jon Vegard
Jon Vegard 2014 年 8 月 21 日
回答済み: Jon Vegard 2014 年 8 月 24 日
The following code yields a bug:
close all
colors = colormap('summer');
color = colors(end,:);
surf([0 0; 1 1],[0 1; 0 1],[1 1; 1 1],'faceColor',color);
hold on
surf([0 0; 1 1],[0 1; 0 1],[0 0; 0 0],'faceColor',color);
surf([0 1; 0 1],[1 1; 1 1],[0 0; 1 1],'faceColor',color);
surf([0 1; 0 1],[0 0; 0 0],[0 0; 1 1],'faceColor',color);
surf([1 1; 1 1],[0 0; 1 1],[0 1; 0 1],'faceColor',color);
surf([0 0; 0 0],[0 0; 1 1],[0 1; 0 1],'faceColor',color);
lineArr = 0:0.1:1;
daspect([1 1 1]);
view(3)
camlight;
lighting phong;
set(gca, 'Color', 'none');
camlight('left')
axis equal
scatter3(-0.1*ones(1,length(lineArr)),lineArr,lineArr,'fill','MarkerFaceColor', 'red')
xlabel('xaxis')
Namely that some areas around the red markers turns into green. Can this be fixed?
  2 件のコメント
Matz Johansson Bergström
Matz Johansson Bergström 2014 年 8 月 21 日
I don't see anything wrong with this render. Where are these "green areas" exactly? If you mean the yellow/green sides, this is due to the camera light.
Matz Johansson Bergström
Matz Johansson Bergström 2014 年 8 月 21 日
Now I see what you mean, check out my answer below.

サインインしてコメントする。

回答 (5 件)

Youssef  Khmou
Youssef Khmou 2014 年 8 月 21 日
To get uniform color, delete the light commands :
colors = colormap('summer');
color = colors(end,:);
surf([0 0; 1 1],[0 1; 0 1],[1 1; 1 1],'faceColor',color);
hold on
surf([0 0; 1 1],[0 1; 0 1],[0 0; 0 0],'faceColor',color);
surf([0 1; 0 1],[1 1; 1 1],[0 0; 1 1],'faceColor',color);
surf([0 1; 0 1],[0 0; 0 0],[0 0; 1 1],'faceColor',color);
surf([1 1; 1 1],[0 0; 1 1],[0 1; 0 1],'faceColor',color);
surf([0 0; 0 0],[0 0; 1 1],[0 1; 0 1],'faceColor',color);
lineArr = 0:0.1:1;
daspect([.5 .5 .5]);
view(3)
%camlight;
lighting phong;
set(gca, 'Color', 'none');
%camlight('right')
axis equal
scatter3(-0.1*ones(1,length(lineArr)),lineArr,lineArr,'fill','MarkerFaceColor', 'red')
xlabel('xaxis')

José-Luis
José-Luis 2014 年 8 月 21 日
Making the patches transparent will show the points that are missing from your plot:
colors = colormap('summer');
color = colors(end,:);
surf([0 0; 1 1],[0 1; 0 1],[1 1; 1 1],'faceColor',color,'facealpha',0.5);
hold on
surf([0 0; 1 1],[0 1; 0 1],[0 0; 0 0],'faceColor',color,'facealpha',0.5);
surf([0 1; 0 1],[1 1; 1 1],[0 0; 1 1],'faceColor',color,'facealpha',0.5);
surf([0 1; 0 1],[0 0; 0 0],[0 0; 1 1],'faceColor',color,'facealpha',0.5);
surf([1 1; 1 1],[0 0; 1 1],[0 1; 0 1],'faceColor',color,'facealpha',0.5);
surf([0 0; 0 0],[0 0; 1 1],[0 1; 0 1],'faceColor',color,'facealpha',0.5);
lineArr = 0:0.1:1;
daspect([1 1 1]);
view(3)
camlight;
lighting phong;
set(gca, 'Color', 'none');
camlight('left')
axis equal
scatter3(-0.1*ones(1,length(lineArr)),lineArr,lineArr,'fill','MarkerFaceColor', 'red')
xlabel('xaxis')

Matz Johansson Bergström
Matz Johansson Bergström 2014 年 8 月 21 日
編集済み: Matz Johansson Bergström 2014 年 8 月 21 日
The reason the points disappear when you move the eye's position is because of axis clipping planes used by Matlab. When the points are outside of these clipping planes, they are cut out of the view. Try by moving the camera, you will see what I mean.
You can modify the axis by calling axis([xmin, xmax, ymin, ymax, zmin, zmax]) so you can set it for yourself or simply remove axis equal. See http://www.mathworks.se/help/matlab/ref/axis.html for more information.
  1 件のコメント
Matz Johansson Bergström
Matz Johansson Bergström 2014 年 8 月 22 日
編集済み: Matz Johansson Bergström 2014 年 8 月 22 日
The "green areas" is another issue connected with the camera light. Because you have the lighting turned on, the planes or parts of a more complex 3d object facing away from the light will be shaded (using Phong in this example). You can change the light source position
light('Position', [-1 0 0], 'Style', 'infinite');
Now the nearest cube plane will be brighter than the others, which is maybe what you want.

サインインしてコメントする。


Jon Vegard
Jon Vegard 2014 年 8 月 22 日
My question seems to be badly asked. The green areas I'm talking about is the smal green areas around the red markers. Sure these areas will disappear when lighting is turn off, but I want the lighting to be turn on (this is a constructed example, and the geometry is much more complex such that lighting is needed).
  2 件のコメント
José-Luis
José-Luis 2014 年 8 月 22 日
編集済み: José-Luis 2014 年 8 月 22 日
I don't see any green areas. Are you talking about aliasing? Also, if you use a format such a .jpg you are bound to get some blur, as it is a compressed format.
Star Strider
Star Strider 2014 年 8 月 22 日
@Jon — You may also need to set the 'MarkerEdgeColor' to 'r' in the scatter3 call, if I understand your Answer here correctly.

サインインしてコメントする。


Jon Vegard
Jon Vegard 2014 年 8 月 24 日
I'm sorry guys! The 'bug' seems to be a result of poor quality of my screen. Using an other screen, I am also not able to spot any green areas.

カテゴリ

Help Center および File ExchangeLighting, Transparency, and Shading についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by