Auxiliary Function Definition (execute -- but do not change!)

Execute these commands once. DO NOT MAKE ANY CHANGES!

> animatemotion := proc( x, y, p )

> local nframe, npoint, _e, _scene, t, lo, hi,

> _R, _V, _A, _T, _N, _kappa, _speed, _NN, _dir, _pt,

> pR, plot1, anim,

> vecR, vecV, vecA, vecT, vecN, cirK, ctrK;

> nframe := 10;

> _scene := [ R, V, A ];

> if nargs>3 then

> for _e in args[4..-1] do

> if not type(_e,symbol=anything) then

> error( `invalid optional parameter, symbol=numeric expected, received `, _e )

> end if;

> if lhs(_e)='scene' then

> if type(rhs(_e),list(symbol))

> and nops( convert(rhs(_e),set) minus {R,V,A,T,N,kappa} ) = 0 then

> _scene:=rhs(_e);

> else

> error( `invalid scene, list containing one or more of R, V, A, T, N, and kappa expected, received `, rhs(_e) );

> end if;

> end if;

> if lhs(_e)='frames' then nframe:=rhs(_e) end if;

> end do;

> end if;

> if type(lhs(p),symbol) and type(evalf(rhs(p)),numeric..numeric) then

> t := lhs(p);

> lo, hi := op(rhs(p));

> else

> error( `invalid third parameter, t = lo .. hi expected, received `, p );

> end if;

> _R := unapply( [x,y], t );

> _V := unapply( diff([x,y], t ), t );

> _A := unapply( diff([x,y], t,t ), t );

> _speed := simplify( linalg[norm](_V(t),2) ) assuming t::real;

> _T := unapply( simplify( expand( _V(t)/_speed) ), t );

> _kappa := unapply( simplify( abs(diff(x,t)*diff(y,t,t)-diff(x,t,t)*diff(y,t))/_speed^3 ), t );

> _NN := unapply( [-_T(t)[2],_T(t)[1]], t );

> _dir := 0;

> while _dir=0 do

> _pt := lo + rand()/10^12 * (hi-lo);

> _dir := evalf( linalg[innerprod]( _A(_pt), _NN(_pt) ) );

> end do;

> _N := signum(_dir)*_NN;

> # _pt :=lo + 0.123*(hi-lo); # a relatively random number in the parameter domain

> # _dir := evalf(linalg[innerprod](_A(_pt),_NN(_pt)));

> # if _dir <> 0 then

> # _N := signum(_dir)*_NN;

> # else

> # _N := NULL;

> # end if;

> pR := plot( [ x, y, p ], scaling=constrained );

> if has( _scene, R ) then

> vecR := _t -> plottools[arrow]( [0,0], _R(_t), .1, .2, .1, color=green ):

> else

> vecR := NULL;

> end if;

> if has( _scene, 'V' ) then

> vecV := _t -> plottools[arrow]( _R(_t), _R(_t)+_V(_t), .1, .2, .1, color=green ):

> else

> vecV := NULL;

> end if;

> if has( _scene, 'A' ) then

> vecA := _t -> plottools[arrow]( _R(_t), _R(_t)+_A(_t), .1, .2, .1, color=blue ):

> else

> vecA := NULL;

> end if;

> if has( _scene, 'T' ) then

> vecT := _t -> plottools[arrow]( _R(_t), _R(_t)+_T(_t), .1, .2, .1, color=orange ):

> else

> vecT := NULL;

> end if;

> if has( _scene, 'N' ) then

> vecN := _t -> plottools[arrow]( _R(_t), _R(_t)+_N(_t), .1, .2, .1, color=magenta ):

> else

> vecN := NULL;

> end if;

> if has( _scene, 'kappa' ) then

> ctrK := unapply( convert(evalm(_R(t)+_N(t)/_kappa(t)),list), t );

> cirK := _t -> plottools[circle]( ctrK(_t), 1/_kappa(_t), color=gold ):

> else

> cirK := NULL;

> end if;

> plot1 := unapply( display( vecR(_t), vecV(_t), vecA(_t), vecT(_t), vecN(_t), cirK(_t) ), _t );

> anim := display( [seq(plot1(t), t=evalf(lo + (hi-lo)*[$0..nframe-1]/(nframe-1))) ], scaling=constrained, insequence=true ):

> display( [pR,anim] );

> end proc: