function letsroll(option) %LETSROLL Plots a cycloid in the making... % Just type letsroll at the MATLAB prompt to see the movie. % Written for MATLAB v5. %Peter Dunn (dunn@romulus.sci.usq.edu.au) %17 March 1999 if nargin==0, %Plot the `ground' LRFig=figure('tag','tagMain','Name','Cycloids'); hold on; plot([-1 9],[0 0],'g-'); %the `ground' axis('equal'); axis('off'); %plot circle rad = 1.0; [xpt, ypt, hc, hp, hl] = plotcirc(0,rad); set(hc,'tag','tagCircle'); set(hp,'tag','tagPoint'); set(hl,'tag','tagLine'); set(LRFig,'Visible','on'); uicontrol('Style','Frame','Units','normalized',... 'Position',[0.05,0.1,0.9,0.2]); %GO button uicontrol('Style','Pushbutton','Units','normalized',... 'Position',[0.1 0.15 0.3 0.1],... 'String','LET''S ROLL...','Callback','letsroll(1);'); %QUIT Button uicontrol('Style','Pushbutton','Units','normalized',... 'Position',[0.6 0.15 0.3 0.1],... 'String','QUIT...','Callback','delete(gcf);'); else %delete current path if it's there if ~isempty(findobj('tag','tagPath') ), delete(findobj('tag','tagPath')); end %preparation maxtheta = 1.25*pi; mintheta = 0; numcirc=25; theta = linspace(mintheta, maxtheta, numcirc); theta = [theta, -sort(-theta)]; rad = 1.0; xpt=rad; ypt=rad; %ilist = [ 1:numcirc, numcirc-1:-1:1]; firsti1 = 1; % for i=ilist, for i = theta, l = i; %NOTE: This circle has radius 0.5, and so theta=2l; %Keep old points for joining path xold=xpt; yold=ypt; [xpt, ypt, hc, hp, hl] = plotcirc(l, rad); set(hc,'tag','tagCircle'); set(hp,'tag','tagPoint'); set(hl,'tag','tagLine'); hpath=plot([xpt,xold],[ypt,yold],'r:'); %cycloid path set(hpath,'tag','tagPath'); drawnow end; end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % SUBFUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [xpt, ypt, hc, hp, hl] = plotcirc(l, rad) %PLOTCIRC Plots the circle %USE: [xp, yp, hc, hp, hl] = plotcirc(l, rad) where l is the distance % travelled, rad is the radius, hc is the handle for the circle, % hp is the handle for the point and hl is the handle for the line. t = linspace(0, 2*pi); xt = 2*l + rad*cos(t); yt = rad + rad*sin(t); xpt = 2*l + rad*cos(-2*l); ypt = rad + rad*sin(-2*l); [handles] = plot( xt, yt, 'b-', xpt, ypt, 'ro', [2*l xpt],[rad, ypt], 'b-'); hc = handles(1); hp = handles(2); hl = handles(3); set(hp, 'MarkerFaceColor', 'r'); set(hc,'EraseMode','xor'); set(hp,'EraseMode','xor'); set(hl,'EraseMode','xor'); %delete old stuff that we don't want. delete( findobj('tag','tagCircle') ); delete( findobj('tag','tagPoint') ); delete( findobj('tag','tagLine') ); return;