function C = triad(r, b) % Algorithm is written by % Markley, F. L., “Attitude Determination Using Two Vector Measurements,” 1998 r1 = r(:,1); %More accuarate measurement in reference frame r2 = r(:,2); %Less accuarate measurement in reference frame b1 = b(:,1); %More accuarate measurement in body frame b2 = b(:,2); %Less accuarate measurement in body frame v1 = r1; %1st component of TRIAD in reference frame v2 = cross(r1, r2) / norm(cross(r1 , r2)); v3 = cross(r1, v2); v = [v1 v2 v3]; %TRIAD frame in terms of reference vectors w1 = b1; %1st component of TRIAD in body frame w2 = cross(b1 , b2) / norm(cross(b1 , b2)); w3 = cross(b1, w2); w = [w1 w2 w3]; %TRIAD frame in terms of observation vectors in body C = w * v'; %Estimated Attitude Matrix with TRIAD