Matlab:移动光源

时间:2016-08-31 08:21:56

标签: matlab matlab-figure

我有一个阴影三维物体的三维图。当用户旋转绘图时,如何使光源不断更新为从用户看的方向?

1 个答案:

答案 0 :(得分:0)

查看MATLAB的camlight命令(online documentation)。

这是一个可以帮助您入门的最小演示:

function camlight_demo
    % some example data to plot
    surf(peaks);
    h = rotate3d;
    set(h,'Enable','on');

    % add a light
    LightSource = camlight('headlight');

    % add a callback which will be executed after each rotation
    set(h,'ActionPostCallback',{@move_light_source, LightSource});
end

% This function will move the light after each rotation
function move_light_source(src, evt, LightSource)
    camlight(LightSource, 'headlight');
end