%% ANIMATED VERSION: RUN this in Matlab (rather than publish)

%% Moving around a circle with constant speed
% We move with speed V=2 around a circle of radius R=3 in clockwise direction, starting at point (3,0,0). Find the position function r(t), the velocity function v(t), the acceleration function a(t). Find the period T for one full circle. Plot the resulting curve together with the velocity and acceleration vectors for t=pi/3.

syms t real                   % declare t as real symbolic value
Pi = sym(pi);
R = sym(3); V = sym(2);
A = -V/R;                     % need "-" for clockwise
r = R*[cos(A*t),sin(A*t),0]
v = diff(r,t)                 % differentiate with respect to t
a = diff(v,t)
T = 2*Pi/abs(A)               % period T for one full circle

ezplot3(r(1),r(2),r(3),[0,double(T)],'animate'); hold on
r0 = subs(r,t,Pi/3)           % substitute t=pi/3 for r
v0 = subs(v,t,Pi/3)
a0 = subs(a,t,Pi/3)
arrow3(r0,v0,'r'); texts(r0+v0,'v')
arrow3(r0,a0,'g'); texts(r0+a0,'a')
hold off; 
view(0,90); axis equal        % look at x,y plane


