File: ef230-2023-08/www/examples/rotate_image.m Download
% Purpose: Example of how to rotate an image on a 2D plot
% Method: map the image to a simple plane and then rotate the plane
% EF 230 W. Schleter 4/26/2014

close all;
img = imread('http://ef.engr.utk.edu/efd/pix/jbrisby.jpg'); % get an ugly image
[x,y] = meshgrid([0 0.8],[1,0]); % create x and y values for a surface - these numbers can be change to control size and aspect ratio
plane = surf(x,y,zeros(2,2)); % create the surface - a plane with z=0
set(plane,'CData',img,'FaceColor','texturemap'); % map the image to the surface
hold on
rotpt = [0.2 0.2 0]; % coordinates of a rotation point
rotax = [0 0 1]; % rotation axis vector (z axis is coming out of the screen)
plot(rotpt(1),rotpt(2),'ro'); % show the rotation point for reference
axis equal; % force matlab to keep x and y axis scaled the same
xlim([-2,2]); % set x axis limits
ylim([-2,2]); % set y axis limits
view(2); % make sure we are in a 2d view
% infinite loop for simple animation
while 1
    % rotate the plane object 6 deg CW 20 times a second
    rotate(plane,rotax,-6,rotpt); 
    pause(1/20);
end