function B = rotate(A,degrees) % With a litle help of % http://www.mathworks.com/matlabcentral/ % fileexchange/loadFile.do?objectId=4071 % % bepaal dimentie B = A; degrees_rad = degrees * pi / 180; %rotatiematrix R = [ cos(degrees_rad), sin(degrees_rad), 0; sin(-degrees_rad), cos(degrees_rad), 0; 0, 0, 1]; %bepaal buitenzijden en midden [in_size_x, in_size_y] = size(A); in_mid_x = ( in_size_x-1) / 2; in_mid_y = ( in_size_y-1) / 2; %max grootte van het nieuwe plaatje is de helft de diameter % en dan 'rechtop' dia = int64(sqrt(in_size_x^2 + in_size_y^2 )); B = zeros([dia,dia]); %grootte van de nieuwe matrix [out_size_x, out_size_y] = size(B); out_mid_x = ( out_size_x-1) / 2; out_mid_y = ( out_size_y-1) / 2; % %translatiematrix Tout = [ 1, 0, out_mid_x; 0, 1, out_mid_y; 0, 0, 1;]; Tin = [ 1, 0, -in_mid_x; 0, 1, -in_mid_y; 0, 0, 1; ]; Trans = Tout * R * Tin; % Laten we maar gaan draaien ;-) for i=1:in_size_x for j=1:in_size_y out = round(Trans * [i;j;1;]); %gegevens overhevelen B(out(1),out(2)) = A(i,j); end end