5

Does anyone of you have a clever way of coding

ellipse with dashed longitude and latitude cricles

in Tikz? My own solution currently is to draw an ellipse, then to specify each dashed arc explicitly, a thoroughly plebeian technique.

3 Answers 3

7

I very much like Altermundus' solution, but if you want exactly what you drew, here's how I would do it:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}
\node[draw,ellipse,minimum width=4cm,minimum height=2cm] (ell) {};
\foreach \ang in {-70,-60,...,70} {
  \pgfmathtruncatemacro{\rang}{180 - \ang}
  \draw[dashed,shorten >=1pt,shorten <=1pt] (ell.\ang) -- (ell.\rang);
}
\foreach \ang in {-65,-45,...,65} {
  \pgfmathsetmacro{\xrad}{2*sin(\ang)}
  \draw[dashed] (0,1) arc [x radius=\xrad,y radius=1,start angle=90,end angle=-90];
}
\end{tikzpicture}
\end{document}

Result:

ellipse

I think that if given a little latitude in the design, then I would add a gentle curve to the lines of latitude.

0
11

The next code is an adaptation of the code globe.tex of Tomasz M. Trzeciak

 \documentclass{scrartcl} 
\usepackage{tikz} 
\usetikzlibrary{calc} 
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}
\pagestyle{empty} 

\newcommand\pgfmathsinandcos[3]{% 
\pgfmathsetmacro#1{sin(#3)} 
\pgfmathsetmacro#2{cos(#3)}} 
\newcommand\LatitudePlane[3][current plane]{%
\pgfmathsinandcos\sinEl\cosEl{#2}
\pgfmathsinandcos\sint\cost{#3} 
}
\newcommand\LongitudePlane[3][current plane]{%
\pgfmathsinandcos\sinEl\cosEl{#2}
\pgfmathsinandcos\sint\cost{#3} 
\tikzset{#1/.estyle={cm={\cost,\sint*\sinEl,0,\cosEl,(0,0)}}}}

\newcommand\DrawLatitudeCircle[2][1]{
\LatitudePlane{\angEl}{#2}
\tikzset{current plane/.estyle={cm={\cost,0,0,\cost*\sinEl,(0,\cosEl*\sint)}}}
\tikzset{current plane/.prefix style={xscale=\R,yscale=\RR}}

\pgfmathsetmacro\sinVis{tan(#2)*tan(\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,black!80] (180-\angVis:1) arc (180-\angVis:\angVis:1);
}
\newcommand\DrawLongitudeCircle[2][1]{
  \LongitudePlane{\angEl}{#2}
  \tikzset{current plane/.prefix style={xscale=\R,yscale=\RR}}
% 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); 
}
\begin{document} 
\begin{tikzpicture}[scale=3]
\def\R{2.5}
\def\RR{3.5} 
\def\angEl{15}
\filldraw[ball color=gray!50] (0,0) circle[x radius=\R, y radius=\RR];
\foreach \t in {-80,-70,...,80} { \DrawLatitudeCircle[\R]{\t} }
\foreach \t in {-5,-35,...,-175} { \DrawLongitudeCircle[\R]{\t} }
\end{tikzpicture} 

\end{document}

enter image description here

1
  • Thank you, Altermundus, this is quite wonderful, but I'm afraid less close to what I wanted than Stacey's solution. Apr 2, 2011 at 21:18
2

This is only a complement with my own code and own package to get a similar drawing:

\documentclass[a4paper]{scrartcl}
\usepackage[usenames,dvipsnames,svgnames]{xcolor}
\usepackage{tkz-euclide} 
\usetkzobj{all} 
\usepackage[frenchb]{babel} 
\definecolor{fondpaille}{cmyk}{0,0,0.1,0}   
\tkzSetUpColors[background=fondpaille,text=Maroon]  

\begin{document} 

  \begin{tikzpicture}[xscale=.6,yscale=.4]
    \tkzInit[xmin=-10,xmax=10,ymin=-10,ymax=10]
    \tkzDefPoint(0 , 0){O}
    \tkzDefPoint(9 , 0){A}
    \tkzDefPoint(-9, 0){C} 
    \tkzDefPoint(0 , 9){B}
    \tkzDefPoint(0 ,-9){D}
    \tkzClipCircle(O,A) 
    \foreach \pti in {1,2,...,8}{
    \tkzDefPoint(10*\pti:9){P\pti}
    \tkzDefPoint(90:\pti){MP\pti}
    \tkzDefPoint(0: \pti){NP\pti}
    \tkzDefLine[mediator](MP\pti,P\pti) 
    \tkzInterLL(B,D)(tkzFirstPointResult,tkzSecondPointResult) 
    \tkzDrawCircle[color=Maroon](tkzPointResult,P\pti)
    } 
    \foreach \pti in {-1,-2,...,-8}{
    \tkzDefPoint(10*\pti:9){P\pti}
    \tkzDefPoint(-90:-\pti){MP\pti}
    \tkzDefPoint(0: -\pti){NP\pti}
    \tkzDefLine[mediator](MP\pti,P\pti)  
    \tkzInterLL(B,D)(tkzFirstPointResult,tkzSecondPointResult)
    \tkzDrawCircle[color=Maroon](tkzPointResult,P\pti)
    } 
    \foreach \pti in {1,2,...,8}{
    \tkzDefLine[mediator](B,NP\pti)  
    \tkzInterLL(A,C)(tkzFirstPointResult,tkzSecondPointResult)  
    \tkzDrawCircle[color=Maroon](tkzPointResult,NP\pti)
    }
    \foreach \pti in {1,2,...,8}{
    \tkzDefPoint(0: -\pti){NP\pti}
    \tkzDefLine[mediator](B,NP\pti) 
    \tkzInterLL(A,C)(tkzFirstPointResult,tkzSecondPointResult)    
    \tkzDrawCircle[color=Maroon](tkzPointResult,NP\pti)
    }  
    \tkzDrawCircle[R,color=Maroon](O,9 cm)
    \tkzDrawSegments[color=Maroon](A,C B,D)  
  \end{tikzpicture}     

  \end{document} 

enter image description here

4
  • By the way, I'd like to draw your attention to a question about TikZ on meta: meta.tex.stackexchange.com/q/1220/86 Apr 3, 2011 at 18:58
  • @Andrew I don't know exactly how to use this excellent forum, my english is not very good and I don't know exactly what is Meta ? I need to read the FAQ ! Apr 3, 2011 at 19:26
  • "Meta" is a website for talking about this place (talking about things like tagging policy and other stuff). In my comment, the text starting 'meta.tex....' should be a clickable link. If you click on it, you'll be taken to a question that I'd be interested in your opinion of. Apr 3, 2011 at 19:50
  • @Andrew thanks for the explanations. I need to read old answers to get an opinion. I think the idea to create a real community project is very good. Apr 3, 2011 at 20:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .