0
$\begingroup$

Greetings All I have a function that creates an affine matrix that works for 2D rotation around an arbitrary point but now I would like it to work for 3D rotations also. The working function example is below with it's example function:

%affine matrix rotation about a point rtaffine[theta,rpx,rpy,sigx,sigy,sigz]
%crx cry rpx rpy represent center of rotation
function [rotsig,theta,crpx,crpy,sigx,sigy,sigz] = rtaffine(theta,rpx,rpy,sigx,sigy,sigz) %format in rrtaffine[theta,rpx,rpy,sigx,sigy,sigz]
    rotsig=[];
    %affinematrix=[];
    siga=[sigx;sigy;sigz];

    r00 = cosd(theta); r01 = -sind(theta); r10 = sind(theta); r11 = cosd(theta);
    affinematrix = [r00, r01, rpx(1,1) - r00*rpx(1,1) - r01*rpy(1,1);...
    r10, r11, rpy(1,1) - r10*rpx(1,1) - r11*rpy(1,1);...
    0, 0, 1];   
    rotsig=affinematrix*siga; %new affine matrix
endfunction

Example code to use with function below:

clear all, clc,clf,tic
t= linspace(0,2*pi,1000); %from 0 to 1 with 100 equal spaces between
freq=1;
y=sin(freq*(t)); %pi will change phase of angle (t+pi)
y2=sin(freq*(t)); %pi will change phase of angle (t+pi)
z = ones(size(y));
siga=[t;y;z];
siga2=[t;y2;z];
rpcalc=[t(1,size(t,2)/2),0]; %size(b,2) %will count all the rows with a 1, count all colmns with 2
rp=[t(1,size(t,2)/2),0]; %rotation point half way on x/t axis
rotsigt=[];
for theta=0:1:360
    rotsig=rtaffine(theta,rp(1,1),rp(1,2),siga(1,:),siga(2,:),siga(3,:));
    rotsig2=rtaffine((theta*2),rp(1,1),rp(1,2),siga(1,:),siga(2,:),siga(3,:)); 
    rotsigcomb=rotsig+rotsig2;
    axis([-10 15 -10 10])
    plot(0,0,'g*',rp(1,1),rp(1,2),'r*',rotsig(1,:),rotsig(2,:),'b-',rotsig2(1,:),rotsig2(2,:),'r',rotsigcomb(1,:),rotsigcomb(2,:),'g')
    %plot(0,0,'g*',rp(1,1),rp(1,2),'r*',rotsigcomb(1,:),rotsigcomb(2,:),rotsig2(1,:),rotsig2(2,:))
    axis([-10 15 -10 10])
    title(['Phase Shift is ',num2str(theta),' deg']);
    grid on
    pause(.001)
    %rotsigt=[rotsigt(:,:),rotsig(:,:)];
end
fprintf('- Complete re-import test in %4.4fsec or %4.4fmins\n',toc,toc/60);

Any suggestions?

  • 3
    First suggestion: Remove all those "tia sal22" from your questions. They are only annoying. ;)2011-03-18
  • 1
    pick an axis, a point, and an angle. translate to origin, rotate by angle around axis, move back. the rotation matrix looks like (in the basis of the axis of rotation and the plance perpendicular to it) $$ \left( \begin{array}{ccc} 1 & 0 & 0 \\ 0 & \cos\theta & -\sin\theta \\ 0 & \sin\theta & \cos\theta \end{array} \right)$$ sorry I can't wade through your code2011-03-18
  • 0
    the way to do this is 1) Translate point you want to rotate about to origin (0,0) 2) Rotate signal 3) Translate signal back to original position2011-03-26

1 Answers 1

1

the way to do this is: 1) Translate point you want to rotate about to origin (0,0) 2) Rotate signal 3) Translate signal back to original position