• Remix
  • Share
  • New Entry

on 22 Nov 2023
  • 17
  • 33
  • 0
  • 0
  • 1327
drawframe(1)
function drawframe(f)
t = interp1([0 48],[0 2*pi],f);
r = 15;
x = r*cos(t);
y = r*sin(t);
ro = -30*pi/180;
yw = -t;
cla
draw_plane(x,y,ro,yw)
% Draw the earth
ks = 15;
[xs,ys,zs] = sphere(30);
hs = surface(ks*xs,ks*ys,ks*zs-20,EdgeColor="none");
% Draw the south pole
kc = 20;
[xc,yc,zc] = cylinder(1,30);
hc = surface(xc,yc,kc*zc-10,EdgeColor="none");
light('Position', [-31.0216 148.2043 204.5982])
axis equal
axis(20*[-1 1 -1 1 -1 1])
axis off
set(gca,Units="normalized",Position=[0 0 1 1])
set(gcf,Color='white')
colormap(flipud(cool))
drawnow
end
%% Auxiliary functions
function draw_plane(x,y,phi,psi)
% This function draws the airplane sketch given its position and attitude
% angles
% CG
R = [3;0;0];
% Wing
wx = 0:0.01:1;
k = numel(wx);
wx = [wx wx(end:-1:1)];
wz = (sqrt(wx) - wx)*0.5; % Airfoil like shape
wy = wx*0;
wy(1:k) = 5;
wy(k+1:end) = -5;
% Shift origin
wx = wx*1.5 - R(1) + 3; % Scale the chord and shift the wing backwards
wy = wy - R(2);
wz = wz - R(3) + .3; % Shift the wing upwards
% Fuselage
fx = 0:.1:11;
fz = (sqrt(fx)*2 - fx*0.6)*0.8 + .1.^((fx-11).^2)*1.2;
fx(end+1) = fx(end);
fz(end+1) = 0;
fy = fx*0;
% Shift origin
fx = fx - R(1);
fy = fy - R(2);
fz = fz - R(3);
% Rotate
zrot = z_rot(-psi-pi/2);
xrot = x_rot(-phi);
W = [wx; wy; wz];
F = [fx; fy; fz];
W = zrot'*xrot'*W;
F = zrot'*xrot'*F;
fill3(W(1,:)+x,W(2,:)+y,W(3,:),'red')
hold on
fill3(F(1,:)+x,F(2,:)+y,F(3,:),'red')
end
function z = z_rot(psi_rad)
% Outputs rotation matrix about z-axis
z = [cos(psi_rad), sin(psi_rad), 0
-sin(psi_rad), cos(psi_rad), 0
0 , 0 , 1];
end
function x = x_rot(phi_rad)
% Outputs rotation matrix about x-axis
x = [ 1, 0, 0
0, cos(phi_rad), sin(phi_rad)
0, -sin(phi_rad), cos(phi_rad)];
end
function [x,y] = inf_shape(a,s)
% Outputs the x-y coordinates of a infinity shape
x = a*cos(s)./(1 + sin(s).^2);
y = a*cos(s).*sin(s)./(1 + sin(s).^2);
end
Animation
Remix Tree