How can I assign a light source that only shines on one specific 3D object in a figure in MATLAB 7.9 (R2009b)?

7 views (last 30 days)

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 21 Sep 2009
To assign a light source directly to a single 3D object, use different axes objects and assign the light source to the axes containing the object that should be lighted as shown in the following example:
close all
ax(1)=axes;
h = surf(peaks);
set(h,'FaceLighting','phong','FaceColor','interp',...
'AmbientStrength',0.5)
light('Position',[1 0 0],'Style','infinite');
ax(2)=axes;
[X,Y,Z] = sphere(20);
surf(ax(2),3*X+10,3*Y+40,3*Z+5)
set(ax(2),'color','none', ...
'Position',get(ax(1),'Position'), ...
'Xlim',get(ax(1),'Xlim'), ...
'Ylim',get(ax(1),'Ylim'), ...
'Zlim',get(ax(1),'Zlim'), ...
'XTick',[], ...
'YTick',[], ...
'ZTick',[] );
linkprop(ax,'view')

More Answers (0)

Products


Release

R2009a

Community Treasure Hunt

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

Start Hunting!