Example: The Earth’s orbit around the Sun

Published 2013-03-09 | Author: Julien Cretel

The Earth’s orbit is an elliptical motion of the Earth around the Sun. This example calculates the distance between Earth and Sun, and the direction of the light hitting the Earth, and draws one complete step-by-step movement around the sun in a series of frames. This could be made to an animation, for example to an animated GIF or PNG or a PDF animation.

Download as: [PDF] [TEX]

The Earth's orbit around the Sun

Do you have a question regarding this example, TikZ or LaTeX in general? Just ask in the LaTeX Forum.
Oder frag auf Deutsch auf TeXwelt.de. En français: TeXnique.fr.

% The Earth's orbit around the Sun
% Author: Julien Cretel, 25/02/2013
\setbeamertemplate{navigation symbols}{}

  \pgfmathsetmacro{\Sunradius}{0.3}   % Sun radius
  \pgfmathsetmacro{\Earthradius}{0.1} % Earth radius
  \pgfmathsetmacro{\e}{0.25}          % Excentricity of the elliptical orbit
  \pgfmathsetmacro{\b}{sqrt(1-\e*\e)} % Minor radius (major radius = 1)

  % Draw the Sun at the right-hand-side focus
    top color=yellow!70,
    bottom color=red!70,
    shading angle={45},
   ] ({sqrt(1-\b*\b)},0) circle (\Sunradius);
    \draw ({sqrt(1-\b*\b)},-\Sunradius) node[below] {Sun};

  % Draw the elliptical path of the Earth.
  \draw[thin] (0,0) ellipse (1 and {\b});
  % This function computes the direction in which light hits the Earth.
      ((-\e+cos(#1))<0) * ( 180 + atan( \b*sin(#1)/(-\e+cos(#1)) ) ) 
      ((-\e+cos(#1))>=0) * ( atan( \b*sin(#1)/(-\e+cos(#1)) ) ) 

  % This function computes the distance between Earth and the Sun,
  % which is used to calculate the varying radiation intensity on Earth.
    \pgfmathparse{ sqrt((-\e+cos(#1))*(-\e+cos(#1))+\b*sin(#1)*\b*sin(#1)) }
  % Produces a series of frames showing one revolution
  % (the total number of frames is controlled by macro \N)
  \foreach \k in {0,1,...,\N}{
        % \onslide is used instead of \visible<.-(x)> and \pause,
        % in order not to break header and footer.
          top color=Earthlight,
          bottom color=blue,
          shading angle={90+f(\theta)},
        ] ({cos(\theta)},{\b*sin(\theta)}) circle (\Earthradius);
          \draw ({cos(\theta)},{\b*sin(\theta)-\Earthradius}) node[below] {Earth};		


Adding comments is currently not enabled.