MATLAB allows handling images by associating an image with a matrix (or matrices). In the following a truecolor (RGB -8 bit) image is read into MATLAB to serve as a background. The cube, cylinder and sphere are then drawn on this background. (to run the following you need an image)
MATLAB Code
% 3D Graphics: Cube
% Dr. P.Venkataraman
format compact
set(gcf,'Menubar','none','Name','Image', ...
'NumberTitle','off','Position',[10,350,300,200]);
% the image - jpeg file
h(4) = axes('Position',[0 0 1 1]); %-stretch to fill figure
A = imread('photomech_1.JPG','jpeg'); % read image filehi1 =image(A); % draw image on figure -
% cube
h(1) = axes('Position',[0.5 0.5 0.3 0.3]);
vert = [1 1 1; 1 2 1; 2 2 1; 2 1 1 ; ...
1 1 2;1 2 2; 2 2 2;2 1 2];
fac = [1 2 3 4; ...
2 6 7 3; ...
4 3 7 8; ...
1 5 8 4; ...
1 2 6 5; ...
5 6 7 8];patch('Faces',fac,'Vertices',vert,'FaceColor','r'); % draw cube
light('Position',[1 3 2]);
light('Position',[-3 -1 3]);
alpha(0.1) % set very trasparent
view(30,30); % rotate view% cylinder
h(2) = axes('Position',[0.1 0.1 0.5 0.5]);[Xs Ys Zs]=cylinder([1 0.5 1],20);
hs2 = surf(Xs, Ys, Zs);
set(hs2,'EdgeColor',[0.5 0.5 0.5], ...
'FaceColor','b', ...
'FaceAlpha','interp');
alpha('color');
alphamap('rampdown');
alpha(0.3);
camlight right;
lighting phong
hidden off
axis equal
rotate(hs2,[1 0 0],45); % cylinder is rotated% sphere
h(3)= axes('Position',[0.17 0.17 0.4 0.4]);[Xs Ys Zs]=sphere(30);
hs3 = surf(Xs, Ys, Zs);
set(hs3,'EdgeColor','none', ...
'FaceColor','y', ...
'FaceLighting','phong', ...
'AmbientStrength',0.3, ...
'DiffuseStrength',0.8, ...
'SpecularStrength',0.9, ...
'SpecularExponent',25, ...
'BackFaceLighting','lit');
camlight left;
hidden offset(h,'Visible','off')
axis square