Search code examples
matlaboctaveaffinetransformrotational-matrices

Rotation / Affine matric function using affine matrix in octave / matlab


I can create a plot shown in BLUE which is correct but when I try and rotate it around 90 degrees about point (0,0) the plot in RED is created. It should just be rotated around 90 degrees about point (0,0). Anyone know what part of my function / code is causing the problem?

See function along with example code below:

Plot

    %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) 
    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
end


%radial arms
t = linspace(0,2*pi,500);
r=e^0.3063489*t;
x = r.*cos(t);
y = r.*sin(t);
plot(x,y)

hold on

%rotation
theta=90;
z = ones(size(y));
siga=[t;y;z];


rotsig=rtaffine(theta,0,0,siga(1,:),siga(2,:),siga(3,:));

plot(t(1,:),rotsig(1,:),'r-')

Solution

  • You are passing in t and trying to plot against t instead of x in both cases:

    siga=[t;y;z];
    

    should be

    siga=[x;y;z];
    

    And

    plot(t(1,:),rotsig(1,:),'r-')
    

    should be

    plot(rotsig(1,:),rotsig(2,:),'r-')