照明保持与动画表面在Matlab中



我试图在Matlab中动画一个旋转的球体,但是球体上的照明与它一起旋转。相反,我想让球体旋转,而照明保持固定的坐标系统。这是我的代码目前正在生成的gif:动画。下面是我的代码:

% Simulation Time
dt = 0.05;
time = 0:dt:5;
% Prep Figure
figure('Color',[1 1 1],'Renderer','zbuffer','ColorMap', [1,0,0; 0,0,1])
% Generate Sphere
[X,Y,Z] = sphere(20);
r = 0.75*25.4;
h = surf(r*X,r*Y,r*Z,Z,'FaceColor','interp');
hold on
% Adjust Axes, Lighting, and Shading
axis equal
view([40 25]);
light('Position',[1 1 1])
set(findobj(gca,'type','surface'),...
            'FaceLighting','phong',...
            'AmbientStrength',.3,'DiffuseStrength',.8,...
            'SpecularStrength',.9,'SpecularExponent',25,...
            'BackFaceLighting','unlit','EdgeColor','k')
filename = 'Rotation.gif';
for n = 1:36
      rotate(h,[0 0 1],10,[0 0 0])
      im = frame2im(getframe(1));
      [imind,cm] = rgb2ind(im,256);
      if n == 1;
          imwrite(imind,cm,filename,'gif', 'Loopcount',inf,'DelayTime',dt);
      else
          imwrite(imind,cm,filename,'gif','WriteMode','append','DelayTime',dt);
      end
end

正如在评论中已经提到的:

似乎这可能是表面VertexNormals not的问题更新。

解决方案是下载旋转。m功能固定文件交换提交。

描述:

错误证据:

[x,y,z] = sphere(20); 
hs=surf(x,y,z,'facecolor','y'); 
view(2) 
axis equal 
hl=light; 
lightangle(hl,0,0) 
% light is on -Y axis, thus at the 
% bottom 
rotate(hs,[0 0 1],30) 
% rotate sphere to the right from 30°

看起来光已经移动了。这是由于rotate.m中的一个bug函数。冲浪对象的"VertexNormals"属性不是更新为"xdata", "ydata"one_answers"zdata"属性。

这个问题在提交的rotate.m版本中被修复了。

最新更新