Take two planets and draw lines connecting them as they orbit. A beautiful cardioid flower pattern will emerge! This animation shows how that pattern evolves as you vary the ratios of the planets’ orbital radii.
Code
Code
In[]:=
<<MaTeX`SetOptions[MaTeX,"Preamble"{"\\usepackage{color,txfonts}"}];SetDirectory[NotebookDirectory[]];
In[]:=
tstep=0.010;times=Table[t,{t,0,8,tstep}];nsteps=Length[times];r2max=3;r1max=1;orbit1[r_,t_]:=r*Cost,Sint;orbit2[r_,t_]:=r*Cost,Sint;animation[r1_,r2_,n_]:=Module{},orbit1pts=Table[orbit1[r1,2πt],{t,times}];orbit2pts=Table[orbit2[r2,2πt],{t,times}];lines=Table[Line[{orbit1pts[[i]],orbit2pts[[i]]}],{i,nsteps}];imgsize=620;ShowGraphicsOpacity[0.7],White,Thickness[.0005],lines[[1;;n]],Opacity[1],Red,Thickness[.005],Circle{0,0},r1,0,2πn*tstep,Blue,Thickness[.005],Circle{0,0},r2*1.005,0,2πn*tstep,Text[MaTeX["\\color{white} \\frac{\\color{red} r_1}{\\color{blue} r_2}="<>ToString@NumberForm[N[r1/r2],{3,3}],Magnification4*imgsize/1000],{-.8,1}],Opacity[1-],White,Thickness[0.005],Line[{orbit1[r1,2πn*tstep],orbit2[r2,2πn*tstep]}],Red,PointSize[.05],Point[orbit1[r1,2πn*tstep]],Blue,PointSize[.05],Point[orbit2[r2,2πn*tstep]],PlotRange1.3*{{-r1max,r1max},{-r1max,r1max}},ImageSizeimgsize,BackgroundBlack;Manipulate[animation[r1,1,i],{{r1,.85(*(5/8)^(2/3)*)},.2,0.85},{{i,nsteps},0,nsteps},SaveDefinitionsTrue]
3
r
3
r
3
r
3
r
3
r1
3
r2
4
(n/nsteps)
Out[]=
Saving frames
Saving frames
In[]:=
t1=5;t2=50;renderframe[t_]:=Module[{},If[t<t1,animation[.85,1,Round[nsteps*t/(t1)]],animation[.85-(.85-0.001)((t-t1)/(t2)),1,nsteps]]];
In[]:=
saveframe[tt_]:=Module[{frame,title},frame=renderframe[tt];title=IntegerString[Floor[tt*1000],10,8]<>".png";Export["frames/"<>title,frame];];
In[]:=
Monitor[Do[saveframe[tt],{tt,0,t1+t2,1/120}],ProgressIndicator[tt,{0,t1+t2}]]

