function [psi1, theta1, phi1] = derotate(top,bottom,psi1,theta1,phi1)
%UNTITLED5 Summary of this function goes here
%   Detailed explanation goes here

psi1temp=psi1;
theta1temp=theta1;
phi1temp=phi1;

%First Derotate Psi
Infr=top;
Supr=bottom;
%vectorplotter3(Infr,Supr)
R=rotmat(0,0,-phi1temp);
Supr=Supr'*R;
%vectorplotter3(Infr,Supr)
%[psi1, theta1, phi1] = getAngle(Infr,Supr);
R=rotmat(0,-theta1temp,0);
Supr=Supr'*R;
%vectorplotter3(Infr,Supr)
[psi1, ~, ~] = getAngle(Infr,Supr);

%Second Derotate Theta
Infr=top;
Supr=bottom;
%vectorplotter3(Infr,Supr)
R=rotmat(0,0,-phi1temp);
Supr=Supr'*R;
%vectorplotter3(Infr,Supr)
%[psi1, theta1, phi1] = getAngle(Infr,Supr);
R=rotmat(-psi1temp,0,0);
Supr=Supr'*R;
%vectorplotter3(Infr,Supr)
[~, theta1, ~] = getAngle(Infr,Supr);

%First Derotate Phi
Infr=top;
Supr=bottom;
%vectorplotter3(Infr,Supr)
R=rotmat(-psi1temp,0,0);
Supr=Supr'*R;
%vectorplotter3(Infr,Supr)
%[psi1, theta1, phi1] = getAngle(Infr,Supr);
R=rotmat(0,-theta1temp,0);
Supr=Supr'*R;
%vectorplotter3(Infr,Supr)
[~, ~, phi1] = getAngle(Infr,Supr);

end

