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.

This question already has an answer here:

I want to draw an image of a non-shaded sphere (just a circular border) with three intersecting great circles that are solid on the visible side and dashed on the back side. Further I want to be able to mark angles, sides and points as well as radiuses.

In the end I need to be able to draw Images like this one:

enter image description here

PS: I already searched through many tutorials with TikZ and other packages, the main problems were that I was not able to draw circles other than longitude or latitude circles.

I am thankful for any tutorials or example documents that show solutions for this.

share|improve this question

marked as duplicate by Ingo, Peter Jansson, Svend Tveskæg, Thomas F. Sturm, Benedikt Bauer Mar 31 at 9:18

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
tikz-3dplot may come in handy. –  Manuel Mar 30 at 13:27

3 Answers 3

up vote 8 down vote accepted

It's very easy to draw, but as often difficult to fill because of the big lake in tikz with using pathes especially drawing following them. With metapost it's peace of cake. Here the intersection points are calculated, but I don't know how to draw a cycle following the pathes, when buildcycle does that in one command in metapost...

With Metapost (see code below) :

enter image description here

With Tikz :

enter image description here

\documentclass[tikz]{standalone}
\usetikzlibrary{intersections}

\newcommand{\InterSec}[3]{%
    \path[name intersections={of=#1 and #2, by=#3, sort by=#1,total=\t}]
        \pgfextra{\xdef\InterNb{\t}}; }

\begin{document}
\begin{tikzpicture}

\draw[thick] (0,0) circle (2) ;

\foreach \angle[count=\n from 1] in {-5,225,290} {

    \begin{scope}[rotate=\angle]
    \path[draw,dashed,name path global=d\n] (2,0) arc [start angle=0,
                            end angle=180,
                            x radius=2cm,
                            y radius=1cm] ;
    \path[draw,name path global=s\n] (-2,0) arc [start angle=180,
                        end angle=360,
                        x radius=2cm,
                        y radius=1cm] ;
    \end{scope}
    }

    \InterSec{s1}{s2}{I3} ;
    \InterSec{s1}{s3}{I2} ;
    \InterSec{s3}{s2}{I1} ;
    \fill[red] (I1)--(I2)--(I3)--cycle ;

    \InterSec{d1}{d2}{J3} ;
    \InterSec{d1}{d3}{J2} ;
    \InterSec{d3}{d2}{J1} ;
    \fill[blue] (J1)--(J2)--(J3)--cycle ;

\end{tikzpicture}
\end{document}

Metapost code :

prologues := 2 ;
verbatimtex
%&latex
\documentclass[10pt]{article}
\usepackage{amsmath,amsfonts,amssymb}
\begin{document}
\scriptsize
etex;

%input Macros-nk ;

u := 1.5cm ;

%##############
\beginfig(1) %#
%##############

path p[] ;

draw fullcircle scaled 4u withpen pencircle scaled 1pt ;

p0 := halfcircle scaled 4u yscaled .5;

for i=0 upto 2 :
    p[i+1] := p0 rotated (-5+60*i) ;
    p[i+4] := p0 rotated (-5+60*i+180) ;
    endfor 

fill buildcycle(p1,p2,p3) withcolor .7[red,white] ;
fill buildcycle(p4,p5,p6) withcolor .7[blue,white] ;

z1 = p1 intersectionpoint p2 ;
z2 = p2 intersectionpoint p3 ;
z3 = p3 intersectionpoint p1 ;

for i=1 upto 2 :
    draw p[i] withpen pencircle scaled .3pt ;
    draw p[i+3] withpen pencircle scaled .3pt dashed evenly scaled .5;
    draw z[i]--(-z[i]) withpen pencircle scaled .3pt dashed evenly ;    
    endfor 

draw halfcircle scaled (.6*u) rotated 90 shifted z1
        cutafter p2 cutbefore p1
        withpen pencircle scaled .1pt ; 
draw halfcircle scaled (.6*u) shifted z2
        cutafter p3 cutbefore p2
        withpen pencircle scaled .1pt ; 
draw halfcircle scaled (.45*u) rotated -90 shifted z3
        cutafter p1 cutbefore p3
        withpen pencircle scaled .1pt ; 

label(btex $\alpha$ etex , z1 shifted (-.2u,-.1u)) ;
label(btex $\beta$ etex , z2 shifted (0u,.2u)) ;
label(btex $\gamma$ etex , z3 shifted (.1u,-.1u)) ;

%##############
endfig;      %#1
%##############

end
share|improve this answer
    
Thank you for your examples - I did not know about MetaPost, this really looks like a promising alternative to tikz - much easier to understand! –  flawr Mar 30 at 21:18
    
@Tarass: I stored your metapost code as spherical-triangle.mp, then I run mpost spherical-triangle.mp. But the result does not look like your result. The labels in the red triangle are missing. What did I do wrong? –  moose Oct 3 at 11:20
    
@moose Nothing wrong, just use includegraphics in a tex document. If you use pdf tex output such as pdflatex or lualatex ... add outputtemplate := "%j-%c.mps"; in the metapost file. –  Tarass Oct 3 at 13:23

Here is a first attempt at an answer, based on tikz-3dplot, as suggested by @Manuel above. Consider the following MWE:

\documentclass[border=2pt,tikz]{standalone}
\usepackage{tikz-3dplot}

\begin{document}
\pgfmathsetmacro{\alpha}{55}
\pgfmathsetmacro{\beta}{60}
\tdplotsetmaincoords{\alpha}{\beta} % Perspective on the main coordinate system
\pgfmathsetmacro{\radius}{0.8} % radius of the circle

\begin{tikzpicture}[scale=5,tdplot_main_coords]
% Draw circle in the un-rotated coordinates
\draw[blue,tdplot_screen_coords] (0,0,0) circle (\radius);

% draw coordinate vectors for reference
\draw[->] (-1,0,0) -- (1,0,0) node[anchor=north east]{$x$};
\draw[->] (0,-1,0) -- (0,1,0) node[anchor=north west]{$y$};
\draw[->] (0,0,-1) -- (0,0,1) node[anchor=south]{$z$};

% draw the "visible" and  "hidden" portions of the circumference as a solid and dashed semi-circles, parametrically 
\draw[red,domain={-180+\beta}:\beta] plot ({\radius*cos(\x)}, {\radius*sin(\x)});
\draw[red,dashed,domain=\beta:{180+\beta}] plot ({\radius*cos(\x)}, {\radius*sin(\x)});

% Change coordinate system, rotate about the reference x and y axis
\tdplotsetrotatedcoords{40}{60}{0} 
\draw [green,tdplot_rotated_coords,domain=160:340] plot ({\radius*cos(\x)}, {\radius*sin(\x)});
\draw [green,dashed,tdplot_rotated_coords,domain=-20:160] plot ({\radius*cos(\x)}, {\radius*sin(\x)});
\end{tikzpicture}

\end{document}

which results in

enter image description here

I adapted one of the examples used in the tikz-3dplot manual to define a three-dimensional coordinate system, draw two semicircles on it (one solid, one dashed). I then changed the coordinate system to produce the intersecting circle.

It could be the basis for what you need: I would need to work out where, in the new coordinate system, solid semi-circle should meet the dashed one and how to fill the intersections with different colors.

EDIT: I changed the way in which the coordinate system is updated. Also, I drew semi-circles using the procedure suggested in Draw arc in tikz when center of circle is specified

share|improve this answer
    
Thank you very much for your effort, this really helped me. One further question: Is it possible to draw an 'angle-symbol' (little arc with the corresponding greek letter) - as @Tarass did it in Metapost - on the intersection of those two circles? –  flawr Mar 30 at 21:14
    
For the intersection, you need the intersections library in TikZ, like @Tarass used in the answer below. I'm not very proficient in it, but you can find examples here: texample.net/tikz/examples/feature/intersections –  MatteoS Mar 31 at 13:52
\documentclass{article}
\usepackage{pst-3dplot}   
\begin{document}

\def\radius{4 }\def\PhiI{20 }\def\PhiII{50 }
\def\RadIs{\radius \PhiI sin mul}
\def\RadIc{\radius \PhiI cos mul}

\begin{pspicture}(-4,-4)(4,5)
  \psset{Alpha=45,Beta=30,linestyle=dashed}
  \pstThreeDSphere[linecolor=black!15](0,0,0){4}
  \pstThreeDCoor[linestyle=solid,xMin=-5,xMax=5,yMax=5,zMax=5,IIIDticks]
  \pstThreeDEllipse(\RadIs,0,0)(0,\RadIc,0)(0,0,\RadIc)
  \pstThreeDEllipse[SphericalCoor](0,0,0)(\radius,90,\PhiI)(\radius,0,0)
  \pstThreeDEllipse[SphericalCoor](0,0,0)(\radius,90,\PhiII)(\radius,0,0)
%
  \psset{linecolor=blue,arrows=->,arrowscale=2,linewidth=1.5pt,linestyle=solid}
    \pstThreeDEllipse[SphericalCoor,beginAngle=\PhiI,endAngle=90]%
    (0,0,0)(\radius,90,\PhiII)(\radius,0,0)
    \pstThreeDEllipse[SphericalCoor,beginAngle=90,endAngle=\PhiI]%
    (0,0,0)(\radius,90,\PhiI)(\radius,0,0)
    \pstThreeDEllipse[beginAngle=\PhiI,endAngle=\PhiII](\RadIs,0,0)(0,\RadIc,0)(0,0,\RadIc)
  \pscustom[fillstyle=solid,fillcolor=blue!40,opacity=0.4]{
    \pstThreeDEllipse[SphericalCoor,beginAngle=\PhiI,endAngle=90]%
    (0,0,0)(\radius,90,\PhiII)(\radius,0,0)
    \pstThreeDEllipse[SphericalCoor,beginAngle=90,endAngle=\PhiI]%
    (0,0,0)(\radius,90,\PhiI)(\radius,0,0)
    \pstThreeDEllipse[beginAngle=\PhiI,endAngle=\PhiII](\RadIs,0,0)(0,\RadIc,0)(0,0,\RadIc)
  }
\end{pspicture}

\end{document}

enter image description here

share|improve this answer
    
Very nice. One of the dashed circle is not great circle, it should pass through the pole ? –  Tarass Mar 31 at 16:10
1  
Yes, that was intended to show that it is possible. –  Herbert Mar 31 at 16:15

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