MATLAB: Can any body find the mistake here? I am rotating the coordinates of the arc and then bringing it to its original position. but it is not coming back to its original position ????!!!!

MATLAB

clear, clc
% the arc coordinates
a=2:0.001:3;
b=sqrt((16-a.^2));
plot(a,b,'k')
axis equal
grid on
hold on
% the new coordinate axis origin and rotating angle from the first
% coordinate
x_origin= 1;
y_origin= 1;
rot_angle= -45;
% 1- calculating the coordinate of the arc according to the new coordinates
% translating

a11=a-x_origin;
b11=b-y_origin;
% rotating

a1=a.*cosd(-1*rot_angle)-b.*sind(-1*rot_angle);
b1=a.*sind(-1*rot_angle)+b.*cosd(-1*rot_angle);
plot(a1,b1,'r')
% 2- re_transformating the axis to the first one
% rotating
a22=a1.*cosd(rot_angle)-b1.*sind(rot_angle);
b22=a1.*sind(rot_angle)+b1.*cosd(rot_angle);
% translating
a2=a22+x_origin;
b2=b22+y_origin;
plot(a2,b2,'--g')
Capture.PNG

Best Answer

  • Some observations,
    1. You never use a11,b11 anywhere.
    2. After rotating back, you perform a translation by x_origin, y_origin. In other words, it did come back to its original position, but then you shifted it.