function [e]=fitgeom(d,l,r,lo,D,td,tol)
%
%  For a given set of geometric parameters and the driving angle theta_d,
%  find the other two angles theta_l and theta_r that come closest to
%  closing the geometry loop.
%
%
%  Some useful constants
%
cd=cos(td);
sd=sin(td);
i=0;
for tl=0:tol:pi
    i=i+1;
    j=0;
    for tr=0:tol:2*pi
        j=j+1;        
        ex=d*cd+l*cos(tl)+r*cos(tr)+lo*sin(td)+D;
        ey=d*sd+l*sin(tl)+r*sin(tr)-lo*cos(td);
        e(i,j)=ex^2+ey^2;
    end
end

        


