Greetings all,
I have written some Matlab code that calculates a 45 degree
rotation matrix for any given dimension. Whilst the code is
definately correct for 2 and 3 dimensions (see the example in the
help ) I am unsure whether the code works for dimensions greater
than three.
To the first person that can either verify that the code is
correct or suggest how it could be fixed I shall send a postcard
from sunny Wollongong Australia.
Thanks,
Ted
-----------------------------------------------------------------
[sample output]
ans =Quote:>> rot45(2)
0.7071 0.7071
-0.7071 0.7071 [correct]
ans =Quote:>> rot45(3)
0.5000 0.5000 -0.7071
-0.7071 0.7071 0
0.5000 0.5000 0.7071 [correct]
ans =Quote:>> rot45(4)
0.3536 0.3536 0.5000 -0.7071
-0.7071 0.7071 0 0
1.0000 0 1.0000 0
0.3536 0.3536 0.5000 0.7071 [unknown ?]
-----------------------------------------------------------------
[file rot45.m]
% Create 45 degree rotation matrix for any dimension
%
% Usage : R45Mat=Rot45(dim)
%
% dim is the desired dimension of the rotation matrix
%
% for example :
%
% [x y z]=sphere(20);
% c=[x(:) y(:) z(:)];
% R=rot45(3); %create 3 dimensional matrix
% s=c;
% for i=1:length(c);
% s(i,:)=c(i,:)*R;
% end;
% plot3(s(:,1),s(:,2),s(:,3));
% view([135 45]);
function R45Mat=Rot45(dim)
if dim<2,
disp('dimension must be larger that 1')
return;
end
k=sin(pi/4);
rotate_45=[k k -k k]; % generic 45 degree rotation matrix
R45Mat=eye(dim);
R45Mat(1:2,1:2)=reshape(rotate_45,[2,2])'; % rotate 45 about axis 1
for t=3:dim,
CMat=eye(dim);
CMat([1 t t*(t-1)+1 t*t])=rotate_45; % rotate 45 about axis number 't'
R45Mat=CMat*R45Mat;
end