Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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]

    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

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
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));
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
for theta=0:1:360
    axis([-10 15 -10 10])
    axis([-10 15 -10 10])
    title(['Phase Shift is ',num2str(theta),' deg']);
    grid on
fprintf('- Complete re-import test in %4.4fsec or %4.4fmins\n',toc,toc/60);

Any suggestions?

share|cite|improve this question
First suggestion: Remove all those "tia sal22" from your questions. They are only annoying. ;) – Hans Lundmark Mar 18 '11 at 11:28
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 code – yoyo Mar 18 '11 at 15:38
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 – Rick T Mar 26 '11 at 0:10

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

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.