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 trying to recreate this image right here to practice myself in TikZ (I am new):

What I have right now is this:

The problems I have is that I want the bottom arc to extend just until it hits the horizontal arc (xy-plane) (see red circle). A second problem I have is that I want to change the opacity of the intersection of the bottom two arcs (see red arrow and blue lines). Is there anyone who can give me some help? I'm new to TikZ. Thank you!

\documentclass{article}
\usepackage{tikz}  %TikZ is required for this to work.  Make sure this exists before the next line
\usepackage{tikz-3dplot}
\usepackage[active,tightpage]{preview}  %generates a tightly fitting border around the work
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{2mm}

\def\radius{6}
\def\Alpha{20}
\def\Beta{20}
\def\Gamma{20}

\begin{document}

\tdplotsetmaincoords{70}{150}

\begin{tikzpicture}[tdplot_main_coords]
% Axis: x, y, z
\tdplotsetrotatedcoords{0}{0}{0}
\draw[very thick,tdplot_rotated_coords,-o,shorten >=-3pt] (0,0,0) -- (\radius,0,0) node[anchor=north east]{$x$};
\draw[very thick,tdplot_rotated_coords,-o,shorten >=-3pt] (0,0,0) -- (0,\radius,0) node[anchor=north west]{$y$};
\draw[very thick,tdplot_rotated_coords,-o,shorten >=-3pt] (0,0,0) -- (0,0,\radius) node[anchor=south]{$z=z'$};

% Axis: x', y', z'
\tdplotsetrotatedcoords{\Alpha}{0}{0}
\draw[thick,tdplot_rotated_coords,-] (0,0,0) -- (\radius,0,0) node[anchor=north east]{$x'$};

% Axis: x'', y'', z''
\tdplotsetrotatedcoords{\Alpha}{\Beta}{0}
\draw[thick,tdplot_rotated_coords] (0,0,0) -- (\radius,0,0) node[anchor=north east]{$x''$};
\draw[thick,tdplot_rotated_coords] (0,0,0) -- (0,\radius,0) node[anchor=west]{$y'=y''$};
\draw[tdplot_rotated_coords] (0,-\radius,0) -- (0,\radius,0);

% Axis: X, Y, Z
\tdplotsetrotatedcoords{\Alpha}{\Beta}{\Gamma}
\draw[very thick,tdplot_rotated_coords,-*,shorten >=-3pt] (0,0,0) -- (\radius,0,0) node[anchor=north east]{$X$};
\draw[very thick,tdplot_rotated_coords,-*,shorten >=-3pt] (0,0,0) -- (0,\radius,0) node[anchor=west]{$Y$};
\draw[very thick,tdplot_rotated_coords,-*,shorten >=-3pt] (0,0,0) -- (0,0,\radius) node[anchor=east]{$z''=Z$};

% Circles
\tdplotsetrotatedcoords{\Alpha}{0}{0}
\draw [tdplot_rotated_coords,domain=-90:90] plot ({\radius*cos(\x)}, {\radius*sin(\x)});
\tdplotsetrotatedcoords{\Alpha}{90}{0}
\draw [tdplot_rotated_coords,domain=90:270] plot ({\radius*cos(\x)}, {\radius*sin(\x)});
\tdplotsetrotatedcoords{\Alpha+90}{90}{0}
\draw [tdplot_rotated_coords,domain=90+\Beta:270+\Beta] plot ({\radius*cos(\x)}, {\radius*sin(\x)});
\tdplotsetrotatedcoords{\Alpha}{\Beta}{0}
\draw [tdplot_rotated_coords,fill=black,fill opacity=0.1,domain=0:90] plot ({\radius*cos(\x)}, {\radius*sin(\x)});

\tdplotsetrotatedcoords{\Alpha}{\Beta}{0}
\draw [tdplot_rotated_coords,domain=-50:0] plot ({\radius*cos(\x)}, {\radius*sin(\x)});


% Arrows for alpha, beta, gamma
\tdplotsetrotatedcoords{0}{0}{0}
\tdplotdrawarc[tdplot_rotated_coords,-latex]{(0,0,0)}{0.8*\radius}{0}{\Alpha}{anchor=east}{$\alpha$}
\tdplotsetrotatedcoords{\Alpha+90}{90}{0}
\tdplotdrawarc[tdplot_rotated_coords,-latex]{(0,0,0)}{0.8*\radius}{-90}{-90+\Beta}{anchor=east}{$\beta$}
\tdplotsetrotatedcoords{\Alpha}{\Beta}{\Gamma}
\tdplotdrawarc[tdplot_rotated_coords,-latex]{(0,0,0)}{0.8*\radius}{-\Gamma}{0}{anchor=east}{$\gamma$}

\tdplotsetrotatedcoords{0}{0}{0}
\tdplotdrawarc[tdplot_rotated_coords,-latex]{(0,0,0)}{0.8*\radius}{90}{90+\Alpha}{anchor=east}{$\alpha$}
\tdplotsetrotatedcoords{\Alpha+90}{90}{0}
\tdplotdrawarc[tdplot_rotated_coords,-latex]{(0,0,0)}{0.8*\radius}{-180}{-180+\Beta}{anchor=east}{$\beta$}
\tdplotsetrotatedcoords{\Alpha}{\Beta}{\Gamma}
\tdplotdrawarc[tdplot_rotated_coords,-latex]{(0,0,0)}{0.8*\radius}{90-\Gamma}{90}{anchor=east}{$\gamma$}

\end{tikzpicture}
\end{document}
share|improve this question
    
This seems like an ambitious project for a newcomer! To solve the first problem, you may want to look at section 13.3.2 "Intersections of Arbitrary Paths" in the TikZ manual‌​. –  Māris Ozols Sep 30 '13 at 13:08
    
I have already checked that part of the manual before posting. The problem is that in that section, they calculate intersections after the two curves have been drawn. The difference is that I need to know the intersection to draw my second curve, while they have two curves and then find the intersection. –  James Sep 30 '13 at 13:19
    
Surely, if you are just recreating the original image it is easier to draw the "back half" of the white surface as semicircle followed by the gray circle, then the small dark gray sector, followed by the "front part" of the white surface as semicircle with a hole in it. The dotted lines can be drawn using clipped paths. Then no intersections are required. –  Mark Wibrow Sep 30 '13 at 14:11

1 Answer 1

Et voilà. Not sure I really understand how tikz-3dplot works (would no doubt help if I read the documentation) and have proceeded (mostly) along the same lines of the original code.

I just changed the order that things are drawn, and used clipping to draw the dashes for lines are behind other surfaces. This results in some rather disorganized code, as (for example) the axes are not grouped together (which would be ideal).

Things will no doubt fall apart if the \Alpha, \Beta and \Gamma parameters are changed significantly.

\documentclass[border=0.125cm]{standalone}
\usepackage{tikz} 
\usepackage{tikz-3dplot}

\def\radius{6}
\def\Alpha{20}
\def\Beta{20}
\def\Gamma{20}

\begin{document}


\tdplotsetmaincoords{70}{150}

\tikzset{% Some styles. More could be done.
    axis/.style={very thick, fill=white, -*, shorten >=-3pt},
    axis'/.style={thick, -},
    axis''/.style={thick, -},
    Axis/.style={very thick, fill=black, -*, shorten >=-3pt},
    behind lines/.style={loosely dashed}
}

\begin{tikzpicture}[tdplot_main_coords]

\begin{scope}[scale=\radius, every path/.style={tdplot_rotated_coords}]

% Back half of the white circle.
\tdplotsetrotatedcoords{\Alpha}{0}{0}
\draw  [fill=white] 
    plot    [domain=90:270, samples=100] (cos \x, sin \x) -- cycle;

% The light gray circle
\tdplotsetrotatedcoords{\Alpha}{\Beta}{\Gamma}
\draw  [fill=gray!20] 
    plot    [domain=0:360, samples=100] (cos \x, sin \x);

% The dashed edge of the back half of the white circle
\begin{scope}
\tdplotsetrotatedcoords{\Alpha}{\Beta}{\Gamma}
\path  [clip] 
    plot    [domain=0:360, samples=100] (cos \x, sin \x);

\tdplotsetrotatedcoords{\Alpha}{0}{0}
\draw  [behind lines] 
    plot    [domain=90:270, samples=100] (cos \x, sin \x);
\end{scope}

% The upper (unfilled) semi circles
\tdplotsetrotatedcoords{\Alpha}{90}{0}
\draw [domain=90:270, samples=100] plot (cos \x, sin \x);
\tdplotsetrotatedcoords{\Alpha+90}{90}{0}
\draw [domain=90+\Beta:270+\Beta, samples=100] plot (cos \x, sin \x);


% The dark gray sector
\tdplotsetrotatedcoords{\Alpha-90}{-90}{90}
\draw [fill=gray, thick, domain=0:\Beta] 
    (0,0) -- plot (cos \x, sin \x) -- cycle;

% The X axis
\tdplotsetrotatedcoords{\Alpha}{\Beta}{\Gamma}
\draw[Axis] (0,0,0) -- (1,0,0) node [below left] {$X$};

% The x'' axis
\tdplotsetrotatedcoords{\Alpha}{\Beta}{0}
\draw[axis'] (0,0,0) -- (1,0,0) node [below left] {$x''$};

% The front half of the white circle
\tdplotsetrotatedcoords{\Alpha}{0}{0}
\draw  [fill=white] 
    plot [domain=-90:0, samples=100] (cos \x, sin \x) 
    .. controls (0.125*cos 22.5, 0.125*sin 22.5) ..
    (cos 45, sin 45) -- plot    [domain=45:90, samples=100] (cos \x, sin \x) 
    -- cycle;

% The dashed lines in the front half of the white circle
\begin{scope}
\tdplotsetrotatedcoords{\Alpha}{0}{0}
\path  [clip] 
    plot [domain=-90:0, samples=100] (cos \x, sin \x) 
    .. controls (0.125*cos 22.5, 0.125*sin 22.5) ..
    (cos 45, sin 45) -- plot    [domain=45:90, samples=100] (cos \x, sin \x) 
    -- cycle;

\tdplotsetrotatedcoords{\Alpha-90}{-90}{90}
\draw [behind lines] (0,0) -- (cos \Beta, sin \Beta);

\tdplotsetrotatedcoords{\Alpha}{\Beta}{\Gamma}
\draw [behind lines] (0,0,0) -- (1,0,0);

\end{scope}


% Axes x, y, z
\tdplotsetrotatedcoords{0}{0}{0}
\draw[axis] (0,0,0) -- (1,0,0) node [below left]  {$x$};
\draw[axis] (0,0,0) -- (0,1,0) node [below right] {$y$};
\draw[axis] (0,0,0) -- (0,0,1) node [above=0.1cm] {$z=z'$};

% Axis x'
\tdplotsetrotatedcoords{\Alpha}{0}{0}
\draw[axis] (0,0,0) -- (1,0,0) node [below left] {$x'$};

% Axes Y
\tdplotsetrotatedcoords{\Alpha}{\Beta}{\Gamma}
\draw[Axis] (0,0,0) -- (0,1,0) node [right] {$Y$};
% Axes z' and Z
\draw[Axis] (0,0,0) -- (0,0,1) node [left=0.1cm] {$z''=Z$};

% Axes y' and y''
\tdplotsetrotatedcoords{\Alpha}{\Beta}{0}
\draw[axis'] (0,0,0) -- (0,1,0) node [below right] {$y'=y''$};

% Arrows
\tdplotsetrotatedcoords{0}{0}{0}
\tdplotdrawarc[-latex]{(0,0,0)}{0.8}{0}{\Alpha}{below left=0cm}{$\alpha$}
\tdplotsetrotatedcoords{\Alpha+90}{90}{0}
\tdplotdrawarc[-latex]{(0,0,0)}{0.8}{-90}{-90+\Beta}{left}{$\beta$}
\tdplotsetrotatedcoords{\Alpha}{\Beta}{\Gamma}
\tdplotdrawarc[-latex]{(0,0,0)}{0.8}{-\Gamma}{0}{below}{$\gamma$}

\tdplotsetrotatedcoords{0}{0}{0}
\tdplotdrawarc[-latex]{(0,0,0)}{0.8}{90}{90+\Alpha}{above left=0cm}{$\alpha$}
\tdplotsetrotatedcoords{\Alpha+90}{90}{0}
\tdplotdrawarc[-latex]{(0,0,0)}{0.8}{-180}{-180+\Beta}{above}{$\beta$}
\tdplotsetrotatedcoords{\Alpha}{\Beta}{\Gamma}
\tdplotdrawarc[-latex]{(0,0,0)}{0.8}{90-\Gamma}{90}{left}{$\gamma$}

\end{scope}

\end{tikzpicture}

\end{document}

enter image description here

share|improve this answer
    
Thank you so much how can I ever thank you. I have learned a lot through your code, the use of scopes, clip, defining styles and much much more, thank you very much it was very helpfull! –  James Oct 1 '13 at 7:39

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.