6

Matlab で回転する球体をアニメーション化しようとしていますが、球体の照明も一緒に回転します。代わりに、照明が座標系に固定されたまま、球体を回転させたいと思います。私のコードが現在生成しているもののgifは次のとおりです: Animation。そして、ここに私のコードがあります:

% 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
4

1 に答える 1

1

コメントですでに述べたように:

サーフェスVertexNormalsが更新されないという問題があるようです。

解決策は、 rotate.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 関数のバグによるものです。サーフ オブジェクトの「VertexNormals」プロパティは、「xdata」、「ydata」、および「zdata」プロパティと同様に更新されません。

これは、rotate.m のサブミットされたバージョンで修正されています。

于 2014-09-02T08:59:57.217 に答える