function T = HHTorsion(H,V,phi)
% function T = HHTorsion(HL or HR,V,phi)
% Donder's law states that torsion T is a unique function of elevation V and horizontal azimuth H: T = T(H,V).
% Listing's law specifies that function T(H,V), and this is what is given you by this function. 
% More accurately, it gives you the extended version of Listing's law (what Tweed calls L2) taking convergence into account.
% D is the vergence angle.
% Primary position is H=0, V=0. 
% H must be that appropriate for this eye.
% L2 says: when you move from H=V=0 to fixate a general point (H,V), you do so by a rotation about an axis which lies in a plane 
% which is at an angle phi, ie the normal to the plane is ( sin(phi) , 0 , cos(phi) ).
% Experimentally, phi seems to be a linear function of vergence:
% phiR = -lambdaR - muR (HR-HL); phiL = -lambdaL - muL (HL-HR)
% lambda is often assumed to be zero, but I think Bruno's work shows actually lambdaR > 0, lambdaL < 0, lambda ~ 2 deg.
% Usually muL=muR ~ 0.2 or so.

tanphi = tan(phi);
tanhalfV = tan(V/2);
tanhalfH = tan(H/2);

T = -2 * atan( tanhalfV .* ( tanphi + tanhalfH ) ./ (1 + tanphi .* tanhalfH) );
