• /
• The Empty Boat

on 14 Nov 2023
• 46
• 167
• 0
• 2
• 1346
drawframe(20);
function drawframe(f)
% Number of frames
nframes = 48;
% Compute the trajectory "phase" based on the current frame
% Draw the sea
% Draw boat
% Set axes limits
xlim([-1 1])
ylim([ 0 2])
% Equal axes scaling
daspect([1, 1, 1])
set(gca,'XTick',[], 'YTick', [])
hold off
end
% Use [-1 +1] to fill entire plot
x = linspace(-1, 1, 50);
% Evaluate sea equation with the phase to create the moving illusion
[y, ~] = eval_sea_eq(x + phase_rad);
% Plot area under curve
area(x,y)
hold on
end
% Define some boat size parameters
body_height = 0.1;
body_span = 0.4;
sail_height = 0.2;
% Boat "body"
b_xy(1,:) = [-body_span/2 -body_span/2*1.2 body_span/2*1.2 body_span/2 ];
b_xy(2,:) = [ 0 body_height body_height 0 ];
% Boat "body" fold
f_xy(1,:) = [b_xy(1,1) 0 b_xy(1,end)];
f_xy(2,:) = [b_xy(2,1) body_height b_xy(2,end)];
% Sail
s_xy(1,:) = [ -0.1 0 0.1 ];
s_xy(2,:) = [body_height (body_height + sail_height) body_height ];
% Get the boat y position and inclination angle
% Get rotation matrix
% Rotate boat parts
b_xy = z_rot'*b_xy;
f_xy = z_rot'*f_xy;
s_xy = z_rot'*s_xy;
% Move boat parts
b_xy(2,:) = b_xy(2,:) + y;
f_xy(2,:) = f_xy(2,:) + y;
s_xy(2,:) = s_xy(2,:) + y;
% Plot the boat
fill(b_xy(1,:), b_xy(2,:), 'r')
fill(f_xy(1,:), f_xy(2,:), 'r')
fill(s_xy(1,:), s_xy(2,:), 'r')
end
function [y, dydx] = eval_sea_eq(x)
% Outputs sea coordinates and slope
% Scale factor
c = 0.5;
% Use only harmonics (x, 2*x, 3*x, etc.) to create the infinity loop illusion
y = (sin(x)*0.5 + 0.4*sin(2*x + pi/6) + 0.3*sin(3*x + pi/3) + 0.1*sin(5*x) + 2) * c;
dydx = (cos(x)*0.5 + 2*0.4*cos(2*x + pi/6) + 3*0.3*cos(3*x + pi/3) + 5*0.1*cos(5*x) + 0) * c; % Derivative
end