• Remix
  • Share
  • New Entry

  • Lucas

  • /
  • Airplane Flying Infinity Shape

on 11 Nov 2023
  • 24
  • 104
  • 1
  • 1
  • 1212
drawframe(1);
Write your drawframe function below
function drawframe(f)
% Number of frames
frames = 48;
% Pseudo-time vector
t = (f-1)/(frames-1)*2*pi;
% Get the curve equation parametric variable
s = t - 1/8*sin(2*t);
% Get current x-y position
a = 25; % Shape parameter
[x,y] = inf_shape(a,s);
% Heading and bank angle of the aircraft
psi = cos(s+pi/2) *135*pi/180;
phi = -cos(s) *40 *pi/180;
% Draw aircraft
draw_plane(x,y,phi,psi)
% Get full trajectory
s = linspace(0, 2*pi, 400);
[x,y] = inf_shape(a, s);
% Draw full trajectory
plot3(x, y, x*0, '--k')
% Equal axis scaling
daspect([1 1 1])
% Set axes limits
xlim([-30 30])
ylim([-15 15])
zlim([-10 10])
% Set camera point of view
view(-77,15)
grid on
hold off
end
%% Auxiliar 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,:),'r')
hold on
fill3(F(1,:)+x,F(2,:)+y,F(3,:),'r')
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