# Spherical triangles and great circles [duplicate]

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:

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.

-

## marked as duplicate by Ingo, Peter Jansson, Svend Tveskæg, Thomas F. Sturm, Benedikt BauerMar 31 '14 at 9:18

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

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) :

With Tikz :

\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,
\path[draw,name path global=s\n] (-2,0) arc [start angle=180,
end angle=360,
\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

-
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 '14 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 '14 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 '14 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

\begin{tikzpicture}[scale=5,tdplot_main_coords]
% Draw circle in the un-rotated coordinates

% 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

% Change coordinate system, rotate about the reference x and y axis
\tdplotsetrotatedcoords{40}{60}{0}
\end{tikzpicture}

\end{document}


which results in

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

-
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 '14 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 '14 at 13:52
\documentclass{article}
\usepackage{pst-3dplot}
\begin{document}

\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]
%
\psset{linecolor=blue,arrows=->,arrowscale=2,linewidth=1.5pt,linestyle=solid}
\pstThreeDEllipse[SphericalCoor,beginAngle=\PhiI,endAngle=90]%
\pstThreeDEllipse[SphericalCoor,beginAngle=90,endAngle=\PhiI]%
\pscustom[fillstyle=solid,fillcolor=blue!40,opacity=0.4]{
\pstThreeDEllipse[SphericalCoor,beginAngle=\PhiI,endAngle=90]%