function essential_distMinAnglePair_test
resetRands(3)
flagDegenerateCase=true;
k=2;

e3=[0;0;1];
Q1=rot_randn([],[],2);
if flagDegenerateCase
    Q1b=[Q1(:,:,1);Q1(:,:,2)];
    Q2b=essential_randomVerticalMotion(Q1b);
    Q2=cat(3,Q2b(1:3,:),Q2b(4:6,:));
else
    Q2=rot_randn([],[],2);
end
Rzt=@(t) rot(t*e3);

Q21tk=@(t,k) Rzt(t)*essential_flipAmbiguity_R1(Q2(:,:,1),k);
Q22tk=@(t,k) Rzt(t)*essential_flipAmbiguity_R2(Q2(:,:,2),k);

figure(1)
[tMin,fMin,tBreak1,tBreak2,Q2Flip]=essential_distMinAnglePair([Q1(:,:,1);Q1(:,:,2)],[Q2(:,:,1);Q2(:,:,2)],k);
tMin=modAngle(tMin);
ft=@(t) (rot_dist(Q1(:,:,1),Q21tk(t,k))^2+rot_dist(Q1(:,:,2),Q22tk(t,k))^2);
dft=@(t) 2*e3'*(Q1(:,:,1)*logrot(Q1(:,:,1)'*Q21tk(t,k))+Q1(:,:,2)*logrot(Q1(:,:,2)'*Q22tk(t,k)));
check_der(ft,dft,'angle')
hold on
plot(tBreak1,ft(tBreak1),'r+')
plot(tBreak2,ft(tBreak2),'g+')

plot(tMin,fMin,'kx','MarkerSize',20)

hold off
