• Remix
  • Share
  • New Entry

on 6 Nov 2023
  • 8
  • 78
  • 0
  • 2
  • 1030
drawframe(48);
function ax = drawframe(frame, varargin)
% Visualize the irrationality of pi
%
% Additional Args:
% * points (float): number of tiles to advance
% * radius0 (float): radius of the inner curve
% * radius1 (float): radius of the outer curve
% * ax (axes): axes of the plot
%
% Returns:
% * ax (axes): axes of the plot
%
% Examples:
% ax = drawframe(1);
% ax = drawframe(1, 'points', 20);
% ax = drawframe(1, 'points', 20, 'radius0', 0.5);
% ax = drawframe(1, 'points', 20, 'radius0', 0.5, 'radius1', 2, 'ax', ax);
%
% @author: Alberto Cuadra Lara
% Postdoctoral researcher - Group Fluid Mechanics
% Universidad Carlos III de Madrid
%
% Last update Nov 06 2023
% Default
points = 50; % Number of points to advance
radius0 = 1; % Radius for the inner curve
radius1 = 1; % Radius for the outer curve
% Miscellaneous
color_draw = [0, 0, 0];
color_arm = [1, 0.5961, 0.0902];
ax = [];
% Get inputs
for i = 1:2:nargin-1
switch lower(varargin{i})
case 'points'
points = varargin{i + 1};
case 'radius0'
radius0 = varargin{i + 1};
case 'radius1'
radius1 = varargin{i + 1};
case {'ax', 'axes'}
ax = varargin{i + 1};
end
end
% Define the complex function
z0 = @(theta) radius0 * exp(1i * theta);
z1 = @(theta) radius0 * exp(1i * theta) + radius1 * exp(1i * pi * theta);
% Initialize plot
if isempty(ax)
figure();
ax = gca;
end
% Plot settings
cla
hold on;
axis equal;
axis off;
xlim([-1, 1] * (radius0 + radius1));
ylim([-1, 1] * (radius0 + radius1));
% Define the range of values to plot
if frame == 1
range = [0, 0];
else
range = (1 : frame * points) / 180 * pi;
end
% Get values
real_part = real(z1(range));
imaginary_part = imag(z1(range));
real_part0 = real(z0(range(end)));
imaginary_part0 = imag(z0(range(end)));
% Plot
plot(ax, real_part, imaginary_part, '-', 'Color', color_draw);
% Plot arms
plot(ax, [0, real_part0], [0, imaginary_part0], '-', 'Color', color_arm, 'LineWidth', 1.5);
plot(ax, [real_part0, real_part(end)], [imaginary_part0, imaginary_part(end)], '-o', 'Color', color_arm, 'LineWidth', 1.5);
end
Animation
Remix Tree