% EXTRA DEMO:   POSITION OF A BICYCLE STEM VS TIME
%
% Program:      maypole.m
% Written by:   
% For:          EE 311
%               Extra Demo Computer Lab 2
% Date:         5-31-2001
% Purpose:      This program plots a maypole with a tether ball
%               attached to it. The path that the tether ball will
%               take as it unwinds from the maypole is then plotted.
%               All of the parameters are for this are entered by 
%               the user.

clear all, hold off, clf reset, close all

% Get information from user
r=input('radius of maypole =                  ');
thdeg=input('initial angle in degrees =           ');
init_len=input('initial length of tether =           ');
s=input('display range(in multiple of 2*pi) = ');

% Define constants
j=sqrt(-1);
th=thdeg*pi/180;
theta=[0:2*pi*s/250:2*pi*s]+th;
z=r*exp(j*theta)+(init_len+r*theta).*exp(j*(theta-pi/2));

% PLOT RESULTS
% Cartesian plot
figure
hold on
set(gcf,'DoubleBuffer','on');
axis('square')
maxz=ceil(abs(max(z)));         % Used to format current figure, so
axis([-maxz maxz -maxz maxz])   % the entire output is seen on the graph
grid
title('Cartesian Plot as the Tether Unwinds From the Maypole')
cir=r*exp(j*theta);
plot(cir)                       % Plot maypole
plot([r*exp(j*th),z(1)])        % Plot the string connecting tether ball to the maypole
plot(z(1),'o')                  % Plot the tether ball at the end of the string
plot(z, '--')                   % Plot the path of the tether as it unwinds 
                                % from the maypole

% Polar plot
figure
polar(angle(z),abs(z),'--')     % Plot the path of the tether as it unwinds first
hold on                         % to correctly format current figure
title('Polar Plot as the Tether Unwinds From the Maypole')
plot(cir)                       % Plot maypole
plot([r*exp(j*th),z(1)])        % Plot the string connecting tether ball to the maypole
plot(z(1),'o')                  % Plot the tether ball at the end of the string
                                % NB: Regular plot commands can be used, because the 
                                % polar background is already set.





