Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am new to tikz and have been working from the following example ( http://www.texample.net/tikz/examples/map-projections/ ) to get a head start.

For better or worse I have managed to get what I need, minus a few things to make the picture look even better. I would like to hide some (not all) of the dashed lines, specifically only when they are behind the Earth. I would like to add text similar to this picture from google

What are the best ways and commands to go about doing this? I am uploading my modified tex file for reference. Also, I googled around for a model of the Earth as tikz picture and didn't come up with anything fruitful. Anyone here know of anything like this (or maybe how to outline the continents on the sphere, haha)?

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,fadings,decorations.pathreplacing}
\usepackage{verbatim}
%% helper macros
\newcommand\pgfmathsinandcos[3]{%
  \pgfmathsetmacro#1{sin(#3)}%
  \pgfmathsetmacro#2{cos(#3)}%
}
\newcommand\LongitudePlane[3][current plane]{%
  \pgfmathsinandcos\sinEl\cosEl{#2} % elevation
  \pgfmathsinandcos\sint\cost{#3} % azimuth
  \tikzset{#1/.estyle={cm={\cost,\sint*\sinEl,0,\cosEl,(0,0)}}}
}
\newcommand\LatitudePlane[3][current plane]{%
  \pgfmathsinandcos\sinEl\cosEl{#2} % elevation
  \pgfmathsinandcos\sint\cost{#3} % latitude
  \pgfmathsetmacro\yshift{\cosEl*\sint}
  \tikzset{#1/.estyle={cm={\cost,0,0,\cost*\sinEl,(0,\yshift)}}} %
}
\newcommand\DrawLongitudeCircle[2][1]{
  \LongitudePlane{\angEl}{#2}
  \tikzset{current plane/.prefix style={scale=#1}}
   % angle of "visibility"
  \pgfmathsetmacro\angVis{atan(sin(#2)*cos(\angEl)/sin(\angEl))} %
  \draw[current plane] (\angVis:1) arc (\angVis:\angVis+180:1);
  \draw[current plane,dashed] (\angVis-180:1) arc (\angVis-180:\angVis:1);
}
\newcommand\DrawLatitudeCircle[2][1]{
  \LatitudePlane{\angEl}{#2}
  \tikzset{current plane/.prefix style={scale=#1}}
  \pgfmathsetmacro\sinVis{sin(#2)/cos(#2)*sin(\angEl)/cos(\angEl)}
  % angle of "visibility"
  \pgfmathsetmacro\angVis{asin(min(1,max(\sinVis,-1)))}
  \draw[current plane] (\angVis:1) arc (\angVis:-\angVis-180:1);
  \draw[current plane,dashed] (180-\angVis:1) arc (180-\angVis:\angVis:1);
}

%% document-wide tikz options and styles

\tikzset{%
  >=latex, % option for nice arrows
  inner sep=0pt,%
  outer sep=2pt,%
  mark coordinate/.style={inner sep=0pt,outer sep=0pt,minimum size=4pt,
  fill=black,circle}%
}

\begin{document}
\begin{tikzpicture}[rotate=-23.5] % "THE GLOBE" showcase


    \def\R{2} % sphere radius
    \def\angEl{5} % elevation angle
    \def\angAz{105} % azimuth angle
    \def\angPhi{-40} % longitude of point P
    \def\angBeta{19} % latitude of point P

    \pgfmathsetmacro\H{\R*cos(\angEl)} % distance to north pole
    \tikzset{xyplane/.estyle={cm={cos(\angAz),sin(\angAz)*sin(\angEl),-sin(\angAz),
                                  cos(\angAz)*sin(\angEl),(0,-\H)}}}
    \LongitudePlane[xzplane]{\angEl}{\angAz}
    \LatitudePlane[equator]{\angEl}{0}

     \filldraw[ball color=green, fill opacity=1] (0,0) circle (\R);
    \draw (0,0) circle (\R);
    \coordinate (O) at (0,0);
    \coordinate[mark coordinate] (N) at (0,\H);
    \coordinate[mark coordinate] (S) at (0,-\H);



    \draw[<->] (0,-\H-5) -- (0,\R+5) node[above] {}; %axis of rotation
    \draw[<->,rotate=23.5] (0,-\H-5) -- (0,\R+5) node[above] {}; %axis of rotation

    \path[xzplane] (\R,0) coordinate (XE);

    \DrawLatitudeCircle[\R,color=red]{0} % equator

    \node[above=10pt, right=6pt] at (N) {\bf{North}};
    \node[above=2pt, right=9pt] at (N) {\bf{Pole}};

    \node[below=3pt, left=6pt] at (S) {\bf{South}};
    \node[below=12pt, left=9pt] at (S) {\bf{Pole}};

    \def\R{6} % sphere radius
    \def\angEl{5} % elevation angle
    \def\angAz{105} % azimuth angle
    \def\angPhi{-40} % longitude of point P
    \def\angBeta{19} % latitude of point P

    \pgfmathsetmacro\H{\R*cos(\angEl)} % distance to north pole
    \tikzset{xyplane/.estyle={cm={cos(\angAz),sin(\angAz)*sin(\angEl),-sin(\angAz),
                                  cos(\angAz)*sin(\angEl),(0,-\H)}}}
    \LongitudePlane[xzplane]{\angEl}{\angAz}
    \LatitudePlane[equator]{\angEl}{0}

     \filldraw[ball color=blue, fill opacity=0.3] (0,0) circle (\R);
    \draw (0,0) circle (\R);

    \coordinate (O) at (0,0);
    \coordinate[mark coordinate] (N) at (0,\H);
    \coordinate[mark coordinate] (S) at (0,-\H);
    \path[xzplane] (\R,0) coordinate (XE);


    \DrawLatitudeCircle[\R,fill=red,fill opacity =0.1,color=red]{0} % equator
    \DrawLatitudeCircle[\R,rotate=23.5, color=yellow]{0} % ecliptic

    \DrawLongitudeCircle[\R]{\angAz+15} % xzplane

    \node[above=10pt, right=5pt] at (N) {\bf{North Celestial Pole}};
    \node[below=10pt, left=5pt] at (S) {\bf{South Celestial Pole}};

    \end{tikzpicture}
    \end{document} 
share|improve this question
    
Welcome to TeX.SE. While code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. This is especially important for tikz as there are numerous libraries. –  Peter Grill Jul 4 '12 at 23:50
    
Thanks for the reply. I just realized I left that out, but since it is based on the example stated in the beginning, this is just the modified section code. That being said I will try to update it. –  John III Jul 5 '12 at 0:56
    
This is a nice document with pstricks, asymptote, and metapost code for celestial sphere. www.math.nus.edu.sg/aslaksen/projects/Wu%20ChengYuan.pdf –  R. Schumacher Jul 5 '12 at 1:09
add comment

2 Answers 2

First you have some code with TikZ arc on a 3d-sphere-in-tikz

Then you can use Google Earth to create a picture of the earth with png or pdf. (I don't know if I can place this kind of picture here. I can remove it If this is not allowed.)

enter image description here

In the next example, I haven't turned the earth to have the correct position. It's only to make an attempt. Then you place this picture in the background. I take your code, remove the earth and place this code :

\begin{pgfonlayer}{background}  
         \node {\includegraphics[scale=.655]{earth.pdf}};  
\end{pgfonlayer}  

With the next code you get :

enter image description here The complete code is :

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,fadings,decorations.pathreplacing,backgrounds}
\usepackage{verbatim}
%% helper macros
\newcommand\pgfmathsinandcos[3]{%
  \pgfmathsetmacro#1{sin(#3)}%
  \pgfmathsetmacro#2{cos(#3)}%
}
\newcommand\LongitudePlane[3][current plane]{%
  \pgfmathsinandcos\sinEl\cosEl{#2} % elevation
  \pgfmathsinandcos\sint\cost{#3} % azimuth
  \tikzset{#1/.estyle={cm={\cost,\sint*\sinEl,0,\cosEl,(0,0)}}}
}
\newcommand\LatitudePlane[3][current plane]{%
  \pgfmathsinandcos\sinEl\cosEl{#2} % elevation
  \pgfmathsinandcos\sint\cost{#3} % latitude
  \pgfmathsetmacro\yshift{\cosEl*\sint}
  \tikzset{#1/.estyle={cm={\cost,0,0,\cost*\sinEl,(0,\yshift)}}} %
}
\newcommand\DrawLongitudeCircle[2][4]{
  \LongitudePlane{\angEl}{#2}
  \tikzset{current plane/.prefix style={scale=#1}}
   % angle of "visibility"
  \pgfmathsetmacro\angVis{atan(sin(#2)*cos(\angEl)/sin(\angEl))} %
  \draw[current plane] (\angVis:1) arc (\angVis:\angVis+180:1);
  \draw[current plane,dashed] (\angVis-180:1) arc (\angVis-180:\angVis:1);
}
\newcommand\DrawLatitudeCircle[2][5]{
  \LatitudePlane{\angEl}{#2}
  \tikzset{current plane/.prefix style={scale=#1}}
  \pgfmathsetmacro\sinVis{sin(#2)/cos(#2)*sin(\angEl)/cos(\angEl)}
  % angle of "visibility"
  \pgfmathsetmacro\angVis{asin(min(1,max(\sinVis,-1)))}
  \draw[current plane] (\angVis:1) arc (\angVis:-\angVis-180:1);
  \draw[current plane,dashed] (180-\angVis:1) arc (180-\angVis:\angVis:1);
}

%% document-wide tikz options and styles

\tikzset{%
  >=latex, % option for nice arrows
  inner sep=0pt,%
  outer sep=2pt,%
  mark coordinate/.style={inner sep=0pt,outer sep=0pt,minimum size=4pt,
  fill=black,circle}%
}

\begin{document}
\begin{tikzpicture}[rotate=-23.5] % "THE GLOBE" showcase


    \def\R{2} % sphere radius
    \def\angEl{5} % elevation angle
    \def\angAz{105} % azimuth angle
    \def\angPhi{-40} % longitude of point P
    \def\angBeta{19} % latitude of point P

    \pgfmathsetmacro\H{\R*cos(\angEl)} % distance to north pole
    \tikzset{xyplane/.estyle={cm={cos(\angAz),sin(\angAz)*sin(\angEl),-sin(\angAz),
                                  cos(\angAz)*sin(\angEl),(0,-\H)}}}
    \LongitudePlane[xzplane]{\angEl}{\angAz}
    \LatitudePlane[equator]{\angEl}{0}

   %  \filldraw[ball color=green, fill opacity=1] (0,0) circle (\R);
  %  \draw (0,0) circle (\R);
    \coordinate (O) at (0,0);
    \coordinate[mark coordinate] (N) at (0,\H);
    \coordinate[mark coordinate] (S) at (0,-\H);



    \draw[<->] (0,-\H-5) -- (0,\R+5) node[above] {}; %axis of rotation
    \draw[<->,rotate=23.5] (0,-\H-5) -- (0,\R+5) node[above] {}; %axis of rotation

    \path[xzplane] (\R,0) coordinate (XE);

    \DrawLatitudeCircle[\R,color=red]{0} % equator

    % \node[above=10pt, right=6pt] at (N) {\bf{North}};
    % \node[above=2pt, right=9pt] at (N) {\bf{Pole}};
    % 
    % \node[below=3pt, left=6pt] at (S) {\bf{South}};
    % \node[below=12pt, left=9pt] at (S) {\bf{Pole}};    

    \def\R{6} % sphere radius
    \def\angEl{5} % elevation angle
    \def\angAz{105} % azimuth angle
    \def\angPhi{-40} % longitude of point P
    \def\angBeta{19} % latitude of point P

    \pgfmathsetmacro\H{\R*cos(\angEl)} % distance to north pole
    \tikzset{xyplane/.estyle={cm={cos(\angAz),sin(\angAz)*sin(\angEl),-sin(\angAz),
                                  cos(\angAz)*sin(\angEl),(0,-\H)}}}
    \LongitudePlane[xzplane]{\angEl}{\angAz}
    \LatitudePlane[equator]{\angEl}{0}

     \filldraw[ball color=blue, fill opacity=0.3] (0,0) circle (\R);
    \draw (0,0) circle (\R);

    \coordinate (O) at (0,0);
    \coordinate[mark coordinate] (N) at (0,\H);
    \coordinate[mark coordinate] (S) at (0,-\H);
    \path[xzplane] (\R,0) coordinate (XE);


    \DrawLatitudeCircle[\R,fill=red,fill opacity =0.1,color=red]{0} % equator
    \DrawLatitudeCircle[\R,rotate=23.5, color=yellow]{0} % ecliptic

    \DrawLongitudeCircle[\R]{\angAz+15} % xzplane

    \node[above=10pt, right=5pt] at (N) {\bf{North Celestial Pole}};
    \node[below=10pt, left=5pt] at (S) {\bf{South Celestial Pole}};
\begin{pgfonlayer}{background}  
         \node {\includegraphics[scale=.655]{earth.pdf}};  
\end{pgfonlayer}   

    \end{tikzpicture}
    \end{document}  
share|improve this answer
    
Another possibility is to use the map from Herbert's method ! –  Alain Matthes Jul 5 '12 at 10:19
add comment

Important is the correct setting of the data path with the key path=.... Run with xelatex (needs some time) or with latex->dvips->ps2pdf

\documentclass{article}
\usepackage{pst-map3d}
\begin{document}

\begin{pspicture}(-4,-4)(4,4)
\psset{RotX=-23,RotZ=30,PHI=46.5833,THETA=0.3333,visibility=false,
  Decran=15,path=/usr/local/texlive/2011/texmf-dist/tex/generic/pst-geo/data}
\WorldMapThreeD[circles=false,blueEarth=false]
\WorldMapThreeD[circles=false,visibility=true,opacity=0.7]
\psmeridien[visibility=true]{13.33}  
\psparallel[visibility=true]{52.51}
\mapputIIID(13.33,52.51){Berlin}
\psparallel[visibility=true]{0}
\end{pspicture}

\end{document}

enter image description here

share|improve this answer
    
@Herbet can this not be done with pdf to latex? –  dustin Apr 25 '13 at 23:02
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.