(*^
::[	Information =

	"This is a Mathematica Notebook file.  It contains ASCII text, and can be
	transferred by email, ftp, or other text-file transfer utility.  It should
	be read or edited using a copy of Mathematica or MathReader.  If you 
	received this as email, use your mail application or copy/paste to save 
	everything from the line containing (*^ down to the line containing ^*)
	into a plain text file.  On some systems you may have to give the file a 
	name ending with ".ma" to allow Mathematica to recognize it as a Notebook.
	The line below identifies what version of Mathematica created this file,
	but it can be opened using any other version as well.";

	FrontEndVersion = "Macintosh Mathematica Notebook Front End Version 2.2";

	MacintoshStandardFontEncoding; 
	
	fontset = title, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeTitle, center, M7, bold, e8,  24, "Times"; 
	fontset = subtitle, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeTitle, center, M7, bold, e6,  18, "Times"; 
	fontset = subsubtitle, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeTitle, center, M7, italic, e6,  14, "Times"; 
	fontset = section, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeSection, grayBox, M22, bold, a20,  18, "Times"; 
	fontset = subsection, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeSection, blackBox, M19, bold, a15,  14, "Times"; 
	fontset = subsubsection, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeSection, whiteBox, M18, bold, a12,  12, "Times"; 
	fontset = text, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7,  14, "Times"; 
	fontset = smalltext, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7,  10, "Times"; 
	fontset = input, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeInput, M42, N23, bold, L-5,  12, "Courier"; 
	fontset = output, output, inactive, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, L-5,  12, "Courier"; 
	fontset = message, inactive, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, R65535, L-5,  12, "Courier"; 
	fontset = print, inactive, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, L-5,  12, "Courier"; 
	fontset = info, inactive, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, B65535, L-5,  12, "Courier"; 
	fontset = postscript, PostScript, formatAsPostScript, output, inactive, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeGraphics, M7, l34, w183, h186,  12, "Courier"; 
	fontset = name, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, italic,  10, "Geneva"; 
	fontset = header, inactive, noKeepOnOnePage, preserveAspect, M7,  12, "Times"; 
	fontset = leftheader, inactive, L2,  12, "Times"; 
	fontset = footer, inactive, noKeepOnOnePage, preserveAspect, center, M7,  12, "Times"; 
	fontset = leftfooter, inactive, L2,  12, "Times"; 
	fontset = help, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7,  10, "Times"; 
	fontset = clipboard, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7,  12, "Times"; 
	fontset = completions, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7,  12, "Times"; 
	fontset = special1, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7,  12, "Times"; 
	fontset = special2, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7,  12, "Times"; 
	fontset = special3, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7,  12, "Times"; 
	fontset = special4, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7,  12, "Times"; 
	fontset = special5, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7,  12, "Times"; 
	paletteColors = 128; currentKernel; 
]
:[font = section; inactive; Cclosed; preserveAspect; cellOutline; backColorRed = 58981; backColorGreen = 58981; backColorBlue = 58981; startGroup]
Example 1:  Visualize Orbits of Planets:

A single vector case:
;[s]
2:0,0;40,1;64,-1;
2:1,19,14,Times,1,18,0,0,0;1,16,12,Times,1,14,0,0,0;
:[font = text; inactive; Cclosed; preserveAspect; startGroup]
Let's use some graphics to help visualize the orbit of the earth as viewed from the reference frame of the sun.  This is also useful in visualizing the orbits of the other planets as view from the earth. 
:[font = input; preserveAspect]
Clear["Global`*"]
:[font = text; inactive; preserveAspect]
Let's setup our coordinate system.  In polar coordinates, the sun-earth radius and angular velocity is {r1,w1}. We can then determine the Cartesian coordinates in terms of the polar coordinates.  We arbitrarily take {r1,w1} = {1,2 Pi}.
:[font = input; preserveAspect]
x1=     r1 Cos[w1 t];
y1=     r1 Sin[w1 t];
:[font = text; inactive; preserveAspect]
Let's set some parameters: 
r is the relative radius: r = r2/r1
w is the relative angular velocity: w = w2/w1
:[font = input; preserveAspect]
r1=r;
w1=w;

rule= {r,w}->{1,2 Pi} //Thread
:[font = text; inactive; preserveAspect]
Now let's construct the orbits. First, we draw a line from the sun, to earth to moon. Then we put a large point at the position of the moon. Then we make a Green circle of the earth orbit, and a blue circle of the moon orbit.   
I use "rule" to substitute the values {r,w}, and the rule {t->tt} to substitue the value of "t" after the "rule" substitution. Finally, we make this a Graphics. 
:[font = input; preserveAspect]
Clear[vec];
vec[tt_]:=
{Line[{{0,0},{x1,y1}}]
,PointSize[0.03],Point[{x1,y1}]
,RGBColor[0,1,0],Circle[{0,0}, r1]
} /.rule /.{t->tt} //Graphics;
:[font = text; inactive; preserveAspect]
Let's have a look at how this looks. Fix the PlotRange to a square area large enough to accomodate the biggest graphic, and force the AspectRatio to 1 so that circles don't appear as ellipses. 
:[font = input; preserveAspect]
Show[ vec[1/5]
     ,PlotRange->{{-2,2},{-2,2}}
     ,AspectRatio->1
     ];
:[font = text; inactive; preserveAspect]
Let's verify we can dynamically change {r,w}.
Note the difference with the above: 
:[font = input; preserveAspect]
rule= {r,w}->{0.25,+4/3} //Thread; 

Show[ vec[1/5]
     ,PlotRange->{{-2,2},{-2,2}}
     ,AspectRatio->1
     ];
:[font = text; inactive; preserveAspect]
Let's reset "rule" to the original value:
:[font = input; preserveAspect]
rule= {r,w}->{0.5,-2/3} //Thread;
:[font = text; inactive; preserveAspect]
For the next step, we want to trace the path of the moon in red. We'll do this with ParametricPlot. 
:[font = input; preserveAspect]
Clear[par];
par[0]=par[10^-6];  (* This avoids problems for tt=0 *)
par[tt_]:=
ParametricPlot[{x1,y1} /.rule //Evaluate
    ,{t, 0, tt}
    ,PlotRange->{{-2,2},{-2,2}}
    ,AspectRatio->1
    ,PlotStyle->{{RGBColor[1,0,0],Thickness[0.010]}}
    ,DisplayFunction->Identity   
    ,Axes->False
    ];

:[font = text; inactive; preserveAspect]
Let's try this out.
:[font = input; preserveAspect]
Show[ par[2 Pi]  ,DisplayFunction->$DisplayFunction ];
:[font = text; inactive; preserveAspect]
Again, we verify that we can change the parameters dynamically.
:[font = input; preserveAspect]
rule= {r,w}->{0.25,+4/3} //Thread; 

Show[ par[Pi]  ,DisplayFunction->$DisplayFunction ];

rule= {r,w}->{0.5,-2/3} //Thread;
:[font = text; inactive; preserveAspect]
Now, let's overlay the two plots.
:[font = input; preserveAspect]
Show[{par[Pi],vec[Pi]} 
    ,DisplayFunction->$DisplayFunction    
];
:[font = text; inactive; preserveAspect]
We'll make a small function to do this automatically as a function of time.
We choose Pi  as the unit of time. 
:[font = input; preserveAspect]
Clear[doit];
doit[time_]:=
   Show[{par[Pi time],vec[Pi time]}
        ,DisplayFunction->$DisplayFunction
       ];
       
doit[1];
:[font = text; inactive; preserveAspect]
Now we are ready to animate. 
:[font = input; preserveAspect; infiniteLoop; loopDistance = 1]
n=4;
Do[ doit[time] ,{time,0,3,3/n}]
:[font = text; inactive; preserveAspect]
We can also use the "par" function to view the path of the moon. 
:[font = input; preserveAspect; endGroup; endGroup]
rule= {r,w}->{0.5,+3/4} //Thread; 

Show[ par[10 Pi]  ,DisplayFunction->$DisplayFunction ];

:[font = section; inactive; Cclosed; preserveAspect; cellOutline; backColorRed = 58981; backColorGreen = 58981; backColorBlue = 58981; startGroup]
Problem 2: Visualize Orbits of Planets:

Exercise: A double vector case:
;[s]
2:0,0;39,1;73,-1;
2:1,19,14,Times,1,18,0,0,0;1,16,12,Times,1,14,0,0,0;
:[font = text; inactive; preserveAspect; startGroup]
Let's use some graphics to help visualize the orbit of the moon as viewed from the reference frame of the sun.  This is also useful in visualizing the orbits of the other planets as view from the earth. 
:[font = input; preserveAspect]
Clear["Global`*"]
:[font = text; inactive; preserveAspect]
Let's setup our coordinate system. 
In polar coordinates, the sun-earth radius and angular velocity is {r1,w1},  and the earth moon radius and angular velocity is {r2,w2}. We can then determine the Cartesian coordinates in terms of the polar coordinates.  We arbitrarily take {r1,w1} = {1,2 Pi} since it is only the relative quantities we will want to vary. 
:[font = input; preserveAspect]
r1=1;
r2= r r1;

w1=2 Pi;
w2= w w1;

x1=     r1 Cos[w1 t];
y1=     r1 Sin[w1 t];
:[font = subsubsection; inactive; preserveAspect]
Modify this so that {x2,y2} are correct. 
;[s]
1:0,1;42,-1;
2:0,13,9,Times,1,12,0,0,0;1,13,9,Times,1,12,65535,0,0;
:[font = input; preserveAspect; fontColorBlue = 65535]
x2= 
y2= 
:[font = text; inactive; preserveAspect]
Let's set some parameters: 
r is the relative radius: r = r2/r1
w is the relative angular velocity: w = w2/w1
:[font = input; preserveAspect]
rule= {r,w}->{0.5,-2/3} //Thread
:[font = text; inactive; preserveAspect]
Now let's construct the orbits. First, we draw a line from the sun, to earth to moon. Then we put a large point at the position of the moon. Then we make a Green circle of the earth orbit, and a blue circle of the moon orbit.   
I use "rule" to substitute the values {r,w}, and the rule {t->tt} to substitue the value of "t" after the "rule" substitution. Finally, we make this a Graphics. 
:[font = subsubsection; inactive; preserveAspect; fontColorRed = 65535]
Modify this: 
Extend the Line to {x2,y2}.
Place the point at {x2,y2}.
Add a blue Circle centered at {x1,y1} with radius r2. 
;[s]
3:0,0;76,1;80,0;125,-1;
2:2,13,9,Times,1,12,65535,0,0;1,13,9,Times,1,12,0,0,65535;
:[font = input; preserveAspect; fontColorBlue = 65535]
Clear[vec];
vec[tt_]:=
{Line[{{0,0},{x1,y1}}]
,PointSize[0.03],Point[{x1,y1}]
,RGBColor[0,1,0],Circle[{0,0}, r1]
} /.rule /.{t->tt} //Graphics;
:[font = text; inactive; preserveAspect]
Let's have a look at how this looks. Fix the PlotRange to a square area large enough to accomodate the biggest graphic, and force the AspectRatio to 1 so that circles don't appear as ellipses. 
:[font = input; preserveAspect]
Show[ vec[1/5]
     ,PlotRange->{{-2,2},{-2,2}}
     ,AspectRatio->1
     ];
:[font = text; inactive; preserveAspect]
Let's verify we can dynamically change {r,w}.
Note the difference with the above: 
:[font = input; preserveAspect]
rule= {r,w}->{0.25,+4/3} //Thread; 

Show[ vec[1/5]
     ,PlotRange->{{-2,2},{-2,2}}
     ,AspectRatio->1
     ];
:[font = text; inactive; preserveAspect]
Let's reset "rule" to the original value:
:[font = input; preserveAspect]
rule= {r,w}->{0.5,-2/3} //Thread;
:[font = text; inactive; preserveAspect]
For the next step, we want to trace the path of the moon in red. We'll do this with ParametricPlot. 
:[font = subsubsection; inactive; preserveAspect; fontColorRed = 65535]
Change this to display {x2,y2} instead.
:[font = input; preserveAspect; fontColorBlue = 65535]
Clear[par];
par[0]=par[10^-6];  (* This avoids problems for tt=0 *)
par[tt_]:=
ParametricPlot[{x1,y1} /.rule //Evaluate
    ,{t, 0, tt}
    ,PlotRange->{{-2,2},{-2,2}}
    ,AspectRatio->1
    ,PlotStyle->{{RGBColor[1,0,0],Thickness[0.008]}}
    ,DisplayFunction->Identity   
    ,Axes->False
    ];

:[font = text; inactive; preserveAspect]
Let's try this out.
:[font = input; preserveAspect]
Show[ par[Pi]  ,DisplayFunction->$DisplayFunction ];
:[font = text; inactive; preserveAspect]
Again, we verify that we can change the parameters dynamically.
:[font = input; preserveAspect]
rule= {r,w}->{0.25,+4/3} //Thread; 

Show[ par[Pi]  ,DisplayFunction->$DisplayFunction ];

rule= {r,w}->{0.5,-2/3} //Thread;
:[font = text; inactive; preserveAspect]
Now, let's overlay the two plots.
:[font = input; preserveAspect]
Show[{par[Pi/4],vec[Pi/4]} ,DisplayFunction->$DisplayFunction];
:[font = subsubsection; inactive; preserveAspect; fontColorRed = 65535]
Sample: for reference:
:[font = text; inactive; preserveAspect]
We'll make a small function to do this automatically as a function of time.
We choose Pi  as the unit of time. 
:[font = input; preserveAspect]
Clear[doit];
doit[time_]:=
   Show[{par[Pi time],vec[Pi time]}
        ,DisplayFunction->$DisplayFunction
       ];
       
doit[1/3];
:[font = text; inactive; preserveAspect]
Now we are ready to animate. 
:[font = input; preserveAspect; infiniteLoop; loopDistance = 1]
n=4;
Do[ doit[time] ,{time,0,Pi/3,Pi/3/n}]
:[font = text; inactive; preserveAspect]
We can also use the "par" function to view the path of the moon. 
:[font = input; preserveAspect]
rule= {r,w}->{0.5,+3/4} //Thread; 

Show[ par[10 Pi]  ,DisplayFunction->$DisplayFunction ];

:[font = text; inactive; preserveAspect]
Here we have varied {r,w}. Note that when the ratio of the angular velocities is not a rational number, the orbits do not close, and we get a space filling curve. 
:[font = input; preserveAspect; endGroup; endGroup]
rule= {r,w}->{0.5,+1/Sqrt[2]} //Thread; 

Show[ par[10 Pi]  ,DisplayFunction->$DisplayFunction ];

:[font = section; inactive; preserveAspect; cellOutline; fontColorRed = 65535; backColorRed = 58981; backColorGreen = 58981; backColorBlue = 58981; startGroup]
Exercises:
Can you discover the {r,w} parameters that generates the following figures.
What other variations can you find?
;[s]
2:0,0;10,1;123,-1;
2:1,19,14,Times,1,18,65535,0,0;1,16,12,Times,1,14,65535,0,0;
:[font = text; inactive; preserveAspect]
A straight line:
:[font = text; inactive; preserveAspect]
A circle
:[font = text; inactive; preserveAspect]
A cycloid
:[font = text; inactive; preserveAspect]
A 4-leaf clover
:[font = text; inactive; preserveAspect; endGroup]
Exercise:  Can you animate the orbit of one of the solar system planets in the reference frame of the earth? 
^*)
