function [F,G] = LonLatDir(Fmodel,Gmodel,V,betar,alphar,SBA,LON,DIM) % Longitudinal and Lateral-Directional Models % Body or Stability Axes % Original State and Control Vectors % x = [u v w x y z pb qb rb phi theta psi]' % u = [dE dA dR dT dAS dF dS]' % Selection Matrices for Longitudinal and Lateral-Directional Sets ReOrderS = [1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0]; ReOrderC = [1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0]; if SBA >= 1 % Stability-Axis Set % x = [V alphar qb theta x z betar pb rb phi psi y]' % u = [dE dT dF dS dA dR dAS]' 'Stability Axes' uo = V * cos(alphar) * cos(betar); vo = V * sin(betar); wo = V * sin(alphar) * cos(betar); rVv = sqrt(V^2 - vo^2); uowo = uo^2 + wo^2; uvwVba = [uo/V vo/V wo/V -uo*vo/(rVv*V^2) (1 - (vo^2)/(V^2))/rVv -vo*wo/(rVv*V^2) -wo/uowo 0 uo/uowo]; H3S = [cos(betar) sin(betar) 0 -sin(betar) cos(betar) 0 0 0 1]; HB3 = [cos(alphar) 0 sin(alphar) 0 1 0 -sin(alphar) 0 cos(alphar)]; HBS = H3S * HB3; HBoStab = [uvwVba zeros(3) zeros(3) zeros(3) zeros(3) eye(3) zeros(3) zeros(3) zeros(3) zeros(3) HBS zeros(3) zeros(3) zeros(3) zeros(3) HBS]; % Conversion: [u v w xi yi zi pb qb rb phi theta psi] to % [V beta alpha xi yi zi ps qs rs phis thetas psis] F12 = HBoStab * Fmodel * inv(HBoStab); G12 = HBoStab * Gmodel; % Separation into Longitudinal and Lateral-Directional Sets F12 = ReOrderS * F12 * inv(ReOrderS); G12 = ReOrderS * G12 * inv(ReOrderC); else % Body-Axis Set % x = [u w qb theta x z v pb rb phi psi y]' % u = [dE dT dF dS dA dR dAS]' 'Body Axes' % Separation into Longitudinal and Lateral-Directional Sets F12 = ReOrderS * Fmodel * inv(ReOrderS); G12 = ReOrderS * Gmodel * inv(ReOrderC); end if DIM < 6 % Fourth-Order Models 'Fourth Order' Flon = F12(1:4,1:4); Glon = G12(1:4,1:4); Flat = F12(7:10,7:10); Glat = G12(7:10,5:7); if SBA >= 1 % Hybrid Axes % xlon = [V gamma qs alpha]' % ulon = [dE dT dF dS]' % xlat = [rs beta ps phis]' % ulat = [dA dR dAS]' Tlon = [1 0 0 0 0 -1 0 1 0 0 1 0 0 1 0 0]; Tlat = [0 0 1 0 1 0 0 0 0 1 0 0 0 0 0 1]; Flon = Tlon * Flon * inv(Tlon); Glon = Tlon * Glon; Flat = Tlat * Flat * inv(Tlat); Glat = Tlat * Glat; end else % Sixth-Order Models 'Sixth Order' % Stability Axea % xlon = [V alpha qs thetas x z]' % ulon = [dE dT dF dS]' % xlat = [beta ps rs phis psis y]' % ulat = [dA dR dAS]' % Body Axes % xlon = [u w qb theta x z]' % ulon = [dE dT dF dS]' % xlat = [v pb rb phi psi,y]' % ulat = [dA dR dAS]' Flon = F12(1:6,1:6); Flat = F12(7:12,7:12); Glon = G12(1:6,1:4); Glat = G12(7:12,5:7); end if LON >= 1 % Longitudinal Model 'Longitudinal' F = Flon; G = Glon; else % Lateral-Directional Model 'Lateral-Directional' F = Flat; G = Glat; end