Polar Animation
A Maple Work Sheet
Learn Some "Maple" and Visualize Some Mathematics
Polar6 - plc
Initialize - This resets your Maple environment and loads the needed command package.
Place the cursor in the execution group (vertical left bracket defines a group) and [ENTER].
"Digits" limits all the "evalf" approximations to ... digits.
> restart: with(plots): Digits:=4:
--Select Your Function--
UN-comment the function you want by removing the "#" at the left.
OR enter your own, OR edit one of these. All but yours must be COMMENTed (have "#").
> #r:=t->sin(t); #circle
> #r:=t->t/6; #spiral
> #r:=t->abs(cos(t)); #2 circles
> #r:=t->1+cos(t); #cardioid
> #r:=t->cos(2*t); #4-pedals
> #r:=t->(cos(t))^2; #infinity
> #r:=t->1+2*cos(t); #limecon with inner loop
> #r:=t->(max(0,sin(2*t))^(1/2); #lemniscate {r^2=sin(2t)}
> #r:=t->2*sin(3*t); #3-pedals
> r:=t->sin(4*t); #8-pedals
> #r:=t->6/(3-2*cos(t)); #ellipse
> #r:=t->cos((2*t)/3); #
> #r:=t-> ; #
>
> #r:=t-> ; #
> #r:=t-> ; #insert YOUR OWN
Put the cursor somewhere in the red stuff above and press [ENTER] to execute your choice!
Domain - [B . . E] = angle domain to use in the graphs.
Edit the next line to fit your choice of function.
> B:=0: E:=2*Pi: lbl:=eval(r),` on ` (B..E): lbl;
Static Plot - polar graph of radius function r(t) on the domain [B .. E].
R is actually a parametric representation of the function r(t).
> R:=[r(t),t,t=B..E]:
> Opt1:=scaling=constrained: Opt2:=coords=polar,Opt1:
> Opta:=Opt2, color=black, thickness=2:
You can re-size any display by selecting (click on) and stretching.
> a:=plot(R,Opta): lbl; a;
--- Animation Stuff is Next ---
Preliminaries - Choices that effect niceness and/or efficiency timewise!
FF = # of subintervals to use (NOTE: FF+1 = # of frames in animation) - initially: 24 per Pi,
WW = width of domain, Dt = width of subintervals, NDt = # of points (for smoothness) in each,
DDt = distance between these, T(i) = i-th angle value. UN-comment the 3-rd line to see values.
Decreasing FF and increasing Ndt will retain a smooth curve and will be faster (less frames).
> FF:=trunc(evalf(24*(E-B)/Pi)): NDt:= 4:
> WW:=E-B: Dt:=WW/FF: DDt:=Dt/NDt:
This way of defining a function allows "remember" -- avoids recalculations (faster, costs space).
> T:=proc(i) option remember; global B, Dt; B+i*Dt; end:
> #FF, WW, Dt, NDt, DDt, T(i);
Basic Polar Coordinates. X(t) = r(t)cos(t) and Y(t) = r(t)sin(t)
Writing a function as a procedure with "remember" speeds thing up!!
"evalf( .... )" gives a decimal approximation and avoids the "non-numeric" PLOT error.
> X:=proc(t) option remember; evalf(r(t)*cos(t)) end:
> Y:=proc(t) option remember; evalf(r(t)*sin(t)) end:
> [X(t),Y(t)];
Max/Min values and VIEW limits -
First we get Max/Min values of x, y, r that occur in the graphs (disregards intermediate points).
> XX:=seq(X(T(i)),i=0..FF): Xm:=min(XX): XM:=max(XX):
> YY:=seq(Y(T(i)),i=0..FF): Ym:=min(YY): YM:=max(YY):
> RR:=seq(evalf(r(T(i))),i=0..FF): Rm:=min(RR): RM:=max(RR):
> [Xm .. XM], [Ym .. YM], [Rm .. RM];
VIEW limits - this is unneeded for "normal" polar graphs, since Maple auto-sizing is very good!
However, it is useful for wierd graphs to sieze this optional ability right away.
> XL:=max(min(-.5,1.1*Xm),-8): XR:=min(max(.5,1.1*XM),8):
> YL:=max(min(-.5,1.1*Ym),-8): YR:=min(max(.5,1.1*YM),8):
> Rm:=max(min(0,Rm),-8): RM:=min(max(0,RM),8):
OR set YOUR OWN VIEW rectangle, UN-comment the next line and put values in.
> #XL:=-5: XR:=5: YL:=-5: YR:=5:
> `VIEW = `(XL .. XR,YL .. YR);
This option will be used for polar graphs.
> Opt3:=VIEW(XL..XR,YL..YR):
The next VIEW limits are for showing Polar and Rectangular graphs at the same time.
The Rectangular graph is shifted to the right "1.2*XR" units, and X0 is used to begin that graph.
> XRR:=evalf(1.3*XR+WW): X0:=1.2*XR-B:
> YLL:=evalf(min(YL,1.05*Rm)): YRR:=evalf(max(YR,1.05*RM)):
This option will be used when doing polar with rectangular (shifted to the right).
> Opt4:=VIEW(XL..XRR,YLL..YRR):
Some Animation Pieces -
Colored growing CURVE -
pt(i) = the sequence of points on the polar graph in the i-th interval ( ok for i > 0 ).
> pt:=i->seq([X(T(i-1)+k*DDt),Y(T(i-1)+k*DDt)],k=0..NDt):
The 1-st animation frame should be blank. This function value overrides pt(0) from above.
> pt(0):=seq([X(T(0)),Y(T(0))],k=0..1):
A LIST is the input for CURVES, POLYGONS, etc. The extra [..] around pt(j) IS needed.
> Optqc:=COLOR(RGB,.8,0,0), THICKNESS(3):
qc(i) = is the full graph from t = B to angle/time t = T(i).
> qc:=i->seq(CURVES(evalf([pt(j)]),Optqc),j=0..i):
Warning, `k` in call to `seq` is not local
Warning, `j` in call to `seq` is not local
Inside Rotating RAY -
Ray from the origin with tip on graph -- that "evalf" avoids a "non-numeric" error!
> Optqr:=COLOR(RGB,0,.6,0), THICKNESS(5):
qr(i) = line from (0,0) to the point on the graph when t = T(i) - end of i-th angle/time interval.
> qr:=i->CURVES(evalf([[0,0],[X(T(i)),Y(T(i))]]),Optqr):
Rotating ANGLE Ray -
Length of rotating ray must be > r(t) (when r(t) >0) to be seen, else it is set at 1.2.
Almost the same as above, but for the function "1.2*max(1, r(t))".
> Mr:=t->max(1,r(t))*1.2:
> Mx:=t->Mr(t)*cos(t): My:=t->Mr(t)*sin(t):
> Optqra:=COLOR(RGB,0,0,.8), THICKNESS(4):
qra(i) = line from (0,0) to point on graph of max(1,r(t)) lengthened by 20%.
> qra:=i->CURVES(evalf([[0,0],[Mx(T(i)),My(T(i))]]),Optqra):
Changing TEXT to show current values of "t" and "r" -
String values for TEXT. This is a non-trivial example of the Maple "convert" procedure.
> st:=i->convert(t = T(i),string):
> sr:=i->convert(r = evalf(r(T(i)),3),string):
Note the "evalf(..... ,3)" - this limits the number of digits returned.
The location of this TEXT is reasonable since we took control of the VIEW option.
> Ttx:=.1*XR: Tty:=YR: Trx:=.5*XR: Try:=.96*YL:
qstrt(i) = string "strt(i)" at the specified location, in the specified FONT. qstrr(i) = similar.
> Optst:=ALIGNRIGHT,FONT(TIMES,BOLD,14):
> qst:=i->TEXT([Ttx,Tty],st(i),Optst):
> qsr:=i->TEXT([Trx,Try],sr(i),Optst):
Pre-Animation INSPECTION -
"order" of display matters - Maple uses a "1-st on top" logic. Change "qr" and "qra" to see!
> Optf:=axesfont=[TIMES,BOLD,10]:
> #display(qst(5),qr(5),qra(5),qc(4),Optf);
Animating the Pieces -
These are the animation parts: thick curve, ray on inside, angle ray, current "t" and "r" text.
PATIENCE may be needed - there is a lot going on!! OR decrease FF and increase NDt.
> Ac:=PLOT(ANIMATE(seq([qc(i)],i=0..FF)),Opt3):
> Ar:=PLOT(ANIMATE(seq([qr(i)],i=0..FF)),Opt3):
> Ara:=PLOT(ANIMATE(seq([qra(i)],i=0..FF)),Opt3):
> Ast:=PLOT(ANIMATE(seq([qst(i)],i=0..FF)),Opt3):
> Asr:=PLOT(ANIMATE(seq([qsr(i)],i=0..FF)),Opt3):
You can see any one individually, by UN-commenting the appropriate command line.
> #Ac; lbl;
> #Ar; lbl;
> #Ara; lbl;
> #Ast; lbl;
> #Asr; lbl;
Animated Polar Graph - "display( .... )" various animations simultaneously.
If you get a jiggling effect then stretch the size of the display - it comes from the "r = " text.
> display(Ar,Ac,Ara,Ast,Asr,Optf); lbl;
Polar vs. Rectangular - side-by-side animation.
The rectangular coordinates graph is shifted to the right to avoid overlap with the polar graph.
Graph points, curve, vertical ray for the rectangular plot.
> ptg:=i->seq(evalf([X0+T(i-1)+k*DDt,r(T(i-1)+k*DDt)]),k=0..NDt):
> ptg(0):=seq(evalf([X0+T(0),r(T(0))]),k=0..1):
> qgc:=i->seq(CURVES([ptg(j)],Optqc),j=0..i):
> qgr:=i->CURVES(evalf([[X0+T(i),0],[X0+T(i),r(T(i))]]),Optqr):
Animation of graph in rectangular coordinates.
> Agc:=PLOT(ANIMATE(seq([qgc(i)],i=0..FF)),Opt4):
> Agr:=PLOT(ANIMATE(seq([qgr(i)],i=0..FF)),Opt4):
No scaling helps to fill the display box better for non-squarish objects.
> Optno:=Optf,scaling=unconstrained:
Stretch the display to full width for best viewing.
> lbl; display(Ac,Ar,Ara,Agc,Agr,Ast,Asr,Optno);
Warning, `k` in call to `seq` is not local
Warning, `j` in call to `seq` is not local
POLAR COORDINATES RECTANGULAR COORDINATES
Colored Polygons -
Vertices ,Colors, and a STATIC Filled Plot -
p(i) = polygon vertices -- must be a list of points ( need the outer [..] ), "evalf" also needed!
> p:=i->evalf([[0,0],pt(i)]):
Function gives HUE value (must be in [0 .. 1]). Note the use of "h(i)" in Optb (i known later).
If the busy changing colors are a distraction, then substitute a constant function like: i-->.5
> h:=i->(i+2)/(FF+4): Optb:=COLOR(HUE,h(i)):
> b:=seq(POLYGONS(p(i),Optb),i=0..FF):
Maple uses a "1-st on top" logic for displays. You may see effects if the graph overlaps itself.
Remove the "#" to see a colorful static picture.
> PLOT(b,Opt3); lbl;
Animated Colored POLYGONS -
Note that p(j) is already a list and has been "evalf"ed to avoid the non-numeric error.
> Optqf:=COLOR(HUE,h(i-j)):
qf(i) = all the polygons from first (when t = B) to the i-th (when t = T(i)).
> qf:=i->seq(POLYGONS(p(j),Optqf),j=0..i):
DO NOT PANIC!! This should be the single longest computation.
> Af:=PLOT(ANIMATE(seq([qf(i)],i=0..FF)),Opt3):
The next command gives an animated colored polygon fill of the polar graph.
> Af; lbl;
Warning, `j` in call to `seq` is not local
The WHOLE THING - animated -
> display(Ast,Asr,Ac,Ar,Ara,Af,Optf); lbl;
Choose YOUR display -
Un-comment the display command and put in the animation parts you want to see.
a = static polar graph, Ac = animated polar curve, Ar = inside ray, Ara = angle ray,
b = filled polar graph, Af = fill polygons, Ast = "t" text, Asr = "r" text,
Agc = animated rect. graph, Agr = moving vertical line.
Keep Maple's "first on top" logic in mind when listing your choices.
>
> #display(Aqc, ,Optf); eval(R);