[Tex/LaTex] Move Moon on its orbit around the Earth

tikz-pgf

I want to draw my Moon on its orbit around the Earth. I can easily draw the moon on the perpendicular axes centring on the Earth but to move it around would probably require some trigonometry… Is there an easy way to tweak my Moon's position, keeping it in orbit? Maybe with shift?

\documentclass{article}

\usepackage[margin=15mm]{geometry}
\usepackage{tikz}
\usetikzlibrary{3d,calc}

\begin{document}

\begin{tikzpicture}
    % Earth
    \shade[ball color=blue!10!white,opacity=0.20] (0,0) circle (1.5);
    \node[align=center](earth) at (0,0) {Earth};

    % Orbitz
    \draw[circle] (0,0) circle (3);

    %Moon
    \shade[ball color=blue!10!white,opacity=0.20] (0,3) circle (0.5);
    \node[align=center](moon) at (0,3) {Moon};


\end{tikzpicture}



\end{document}

enter image description here

Best Answer

Run with --shell-escape and needs imagemagick installed.

\documentclass[preview,border={10pt 0pt 10pt 10pt}]{standalone}

\usepackage{filecontents}
\begin{filecontents*}{moon.tex}
\documentclass[tikz,preview,border=15mm]{standalone}
\usetikzlibrary{calc}
\usetikzlibrary{3d,calc}

\begin{document}
 \foreach \x in {5,10,...,355}{
\begin{tikzpicture}
    % Earth
    \path[use as bounding box] (-3,-3) rectangle (3,3);
    \shade[ball color=blue!10!white,opacity=0.20] (0,0) circle (1.5);
    \node[align=center](earth) at (0,0) {Earth};

    % Orbitz
    \draw[circle] (0,0) circle (3);

    %Moon
    \shade[ball color=blue!10!white,opacity=0.20] (\x:3) circle (0.5);
    \node[align=center](moon) at (\x:3) {Moon};
\end{tikzpicture}
}
\end{document}

\end{filecontents*}
%
\immediate\write18{pdflatex moon}

% convert to GIF animation
%\immediate\write18{convert -delay 10 -loop 0 -density 400 -alpha remove moon.pdf moon.gif}
%
% convert to PNG
\makeatletter
\immediate\write18{convert -density 200 -alpha on moon.pdf moon-\@percentchar02d.png}
\makeatother

\usepackage{animate}
\begin{document}
\begin{preview}
%\animategraphics[controls,autoplay,loop,scale=<integer>]{<frame rate>}{<PDF filename without extension>}{<left blank>}{<left blank>}
\animategraphics[controls,autoplay,loop,scale=1]{10}{moon}{}{}
\end{preview}
\end{document}

enter image description here

Elliptical orbits:

\documentclass[preview,border={10pt 0pt 10pt 10pt}]{standalone}

\usepackage{filecontents}
\begin{filecontents*}{moon.tex}
\documentclass[tikz,preview,border=-2mm]{standalone}
\usetikzlibrary{calc}
\usetikzlibrary{3d,calc}

\begin{document}
 \foreach \x in {5,10,...,355}{
\begin{tikzpicture}[rotate=-52]
    % Earth
    \clip[use as bounding box,yslant=0.5,xslant=0.5,circle] (0,0) circle (5);
    %\draw[use as bounding box] (-4,-4) rectangle (4,4);
    \shade[ball color=blue!10!white,opacity=0.20] (0,0) circle (1.5);
    \node[align=center](earth) at (0,0) {Earth};

    % Orbitz
    \begin{scope}[yslant=0.5,xslant=0.5]
    \draw (0,0) circle (4);

    %Moon
    \node (\x) at (\x:4) {};
    \node[align=center](moon) at (\x:4) {Moon};
    \end{scope}
    \shade[ball color=blue!10!white,opacity=0.20] (\x) circle (0.5);
\end{tikzpicture}
}
\end{document}


\end{filecontents*}
%
\immediate\write18{pdflatex moon}

% convert to GIF animation
%\immediate\write18{convert -delay 10 -loop 0 -density 400 -alpha remove moon.pdf moon.gif}
%
% convert to PNG
\makeatletter
\immediate\write18{convert -density 200 -alpha on moon.pdf moon-\@percentchar02d.png}
\makeatother

\usepackage{animate}
\begin{document}
\begin{preview}
%\animategraphics[controls,autoplay,loop,scale=<integer>]{<frame rate>}{<PDF filename without extension>}{<left blank>}{<left blank>}
\animategraphics[controls,autoplay,loop,scale=1]{10}{moon}{}{}
\end{preview}
\end{document}

enter image description here