# Connecting an arced path in TikZ

I'm trying to draw an octant of a sphere. I'm not an expert on drawing perspective, but I managed that with, among others, the arc command. With the sphere drawn I made some layers, again with the arc command, that I'd like to fill to help distuingish them from the others layers. I made a path of one of the layers, filled it but not with the expected result. The path seems closed to me, but not to TikZ. How can I close the arced path and fill it? I presume my manual finetuning of the coordinates might be the cause of the problem?

MWE

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{through,shapes}

\begin{document}
\begin{tikzpicture}
% coordinaten
\coordinate (m) at (0,4,0);
% assen
\draw (0,0,0) -- (0,4,0); % z
\draw (0,0,0) -- (4,0,0); % x
\draw (0,0,0) -- (0,0,4.65); % y
% sfeer
\draw (4,0,0) arc (0:116.5:4cm and -2cm);
\draw (4,0,0) arc (0:90:4cm and 4cm);
\draw (0,4,0) arc (90:206.5:2cm and 4cm);
\node[draw,circle through={(m)}] (c) at (0,0,0) {};
% fotosfeer
\draw (3.875,0,0) arc (0:115.8:3.875cm and -1.875cm);
\draw (3.875,0,0) arc (0:90:3.875cm and 3.875cm);
\draw (0,3.875,0) arc (90:205.8:1.875cm and 3.875cm);
% convenctie zone
\draw (2,0,0) arc (0:116.5:2cm and -1cm);
\draw (2,0,0) arc (0:90:2cm and 2cm);
\draw (0,2,0) arc (90:206.5:1cm and 2cm);
\draw (1,0,0) arc (0:116.5:1cm and -0.5cm);
\draw (1,0,0) arc (0:90:1cm and 1cm);
\draw (0,1,0) arc (90:206.5:0.5cm and 1cm);
% fill
\draw[fill=blue] (0,3.875,0) -- (0,2,0) (3.875,0,0) arc (0:90:3.875cm and 3.875cm) (2,0,0) arc (0:90:2cm and 2cm) (3.875,0,0) -- (2,0,0);
\end{tikzpicture}
\end{document}


The part I'd like to fill is the biggest section of the xz plane, where the x axis is pointing to the east and the z axis is pointing north. With similar code I'd eventually like to fill the corresponding two parts as well.

PS: I use the circle through command instead of a plain circle node to have no problem with scaling the figure.

-
The paths must be drawn in strict order and direction as if you were drawing the contour without lifting hand. Test something like \draw[fill=blue] (3.875,0,0) arc (0:90:3.875) -- (0,3.875,0) -- (0,2,0) -- (0,2,0) arc (90:0:2) -- cycle; –  skpblack Jul 1 '14 at 23:27

Do you mean some thing like this?

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{through,shapes}

\begin{document}
\begin{tikzpicture}
% coordinaten
\coordinate (m) at (0,4,0);
% assen
\draw (0,0,0) -- (0,4,0); % z
\draw (0,0,0) -- (4,0,0); % x
\draw (0,0,0) -- (0,0,4.65); % y
% sfeer
\draw (4,0,0) arc (0:116.5:4cm and -2cm);
\draw (4,0,0) arc (0:90:4cm and 4cm);
\draw (0,4,0) arc (90:206.5:2cm and 4cm);
\node[draw,circle through={(m)}] (c) at (0,0,0) {};
% fotosfeer
\draw (3.875,0,0) arc (0:115.8:3.875cm and -1.875cm);
\draw (3.875,0,0) arc (0:90:3.875cm and 3.875cm);
\draw (0,3.875,0) arc (90:205.8:1.875cm and 3.875cm);
%fill
\draw[fill=blue] (0,0,0) --(0,3.875,0) arc (90:205.8:1.875cm and 3.875cm) --(0,0,0) -- (3.875,0,0)  arc (0:90:3.875cm and 3.875cm) -- (0,0,0) -- (3.875,0,0) arc (0:115.8:3.875cm and -1.875cm)--  cycle;
% convenctie zone
\draw (2,0,0) arc (0:116.5:2cm and -1cm);
\draw (2,0,0) arc (0:90:2cm and 2cm);
\draw (0,2,0) arc (90:206.5:1cm and 2cm);
%fill
\draw[fill=red] (0,0,0) -- (0,2,0) arc (90:206.5:1cm and 2cm) --(0,0,0) -- (2,0,0)  arc (0:90:2cm and 2cm) -- (0,0,0) -- (2,0,0) arc (0:116.5:2cm and -1cm)--  cycle;
\draw (1,0,0) arc (0:116.5:1cm and -0.5cm);
\draw (1,0,0) arc (0:90:1cm and 1cm);
\draw (0,1,0) arc (90:206.5:0.5cm and 1cm);
%fill
\draw[fill=green] (0,0,0) -- (0,1,0) arc (90:206.5:0.5cm and 1cm) --(0,0,0) -- (1,0,0)  arc (0:90:1cm and 1cm) -- (0,0,0) -- (1,0,0) arc (0:116.5:1cm and -0.5cm)--  cycle;

\end{tikzpicture}
\end{document}


-
Oh, is that what the OP meant? I think I misunderstood. I thought the other two corresponding parts were in the same plane but I guess they are the parts in other planes? I take a long time with tikz so you posted while I was fiddling even though you must have posted ages before I did. :( –  cfr Jul 2 '14 at 0:28
It scares me you can do that in 5 minutes (or anything with tikz) ;). –  cfr Jul 2 '14 at 0:44
@cfr Not anything but this one. It is a matter of drawing few arcs. Thats all :) –  Harish Kumar Jul 2 '14 at 0:48
(+1) regardless... I don't draw many arcs... –  cfr Jul 2 '14 at 2:20
This is exactly what I had in mind, thank you. I don't know what you mean with 'adjust the angles properly' though. –  Johannes Jul 2 '14 at 11:41

I think that you've just 'twisted' the path. You need to go around the outside for the fill to work.

At least, if I've understood what you want to do correctly. Note that I've adjusted things slightly but you need to tidy up more...

\documentclass{standalone}
\usepackage[rgb]{xcolor}
\usepackage{tikz}
\usetikzlibrary{through}

\begin{document}
\begin{tikzpicture}[inner sep=0, outer sep=0]
% coordinaten
\coordinate (m) at (0,4,0);
% assen
\draw  (0,0,0) -- (0,4,0); % z
\draw  (0,0,0) -- (4,0,0); % x
\draw  (0,0,0) -- (0,0,4.65); % y
% sfeer
\draw (4,0,0) arc (0:116.5:4cm and -2cm);
\draw (4,0,0) arc (0:90:4cm and 4cm);
\draw (0,4,0) arc (90:206.5:2cm and 4cm);
\node[draw, inner color=black!50, outer color=black!75, circle through={(m)}] (c) at (0,0,0) {};
\node [ball color=purple, fill opacity=.25, circle through={(m)}] at (0,0,0) {};
% fotosfeer
\draw (3.875,0,0) arc (0:115.8:3.875cm and -1.875cm);
\draw (3.875,0,0) arc (0:90:3.875cm and 3.875cm);
\draw (0,3.875,0) arc (90:205.8:1.875cm and 3.875cm);
% convenctie zone
\draw (2,0,0) arc (0:116.5:2cm and -1cm);
\draw (2,0,0) arc (0:90:2cm and 2cm);
\draw (0,2,0) arc (90:206.5:1cm and 2cm);
\draw (1,0,0) arc (0:116.5:1cm and -0.5cm);
\draw (1,0,0) arc (0:90:1cm and 1cm);
\draw (0,1,0) arc (90:206.5:0.5cm and 1cm);
% fill
\draw[fill=blue] (4,0,0) arc (0:90:4cm and 4cm) -- (0,3.875,0) arc (90:0:3.875cm and 3.875cm) -- (4,0,0);
\draw[fill=blue!70] (3.875,0,0) arc (0:90:3.875cm and 3.875cm) -- (0,2,0) arc (90:0:2cm and 2cm) -- (3.875,0,0);
\draw[fill=blue!40] (2,0,0) arc (0:90:2cm and 2cm) -- (0,1,0) arc (90:0:1cm and 1cm) -- (2,0,0);
\draw[fill=blue!10] (1,0,0) arc (0:90:1cm and 1cm) -- (0,0,0) -- (1,0,0);
\draw[fill=green] (4,0,0) arc (0:116.5:4cm and -2cm) -- (0,0,3.875) arc (115.8:0:3.7cm and -1.65cm) -- (4,0,0);
\draw[fill=green!70] (3.875,0,0) arc (0:115.8:3.875cm and -1.875cm) -- (0,0,2) arc (115.8:0:.96cm and -.865cm) -- (3.875,0,0);
\draw[fill=green!40] (2,0,0) arc (0:116.5:2cm and -1cm) -- (0,0,1) arc (115.8:0:.96cm and -.43cm) -- (2,0,0);
\draw[fill=green!10] (1,0,0) arc (0:116.5:1cm and -.5cm) -- (0,0,0) -- (1,0,0);
\draw[fill=magenta] (0,4,0) arc (90:206.5:2cm and 4cm) -- (0,0,3.875) arc (206.5:90:1.65cm and 3.7cm) -- (0,4,0);
\draw[fill=magenta!70] (0,3.875,0) arc (90:205.8:1.875cm and 3.875cm) -- (0,0,2) arc (205.8:90:.86cm and 1.925cm) -- (0,3.875,0);
\draw[fill=magenta!40] (0,2,0) arc (90:206.5:1cm and 2cm) -- (0,0,1) arc (206.5:90:.43cm and .96cm) -- (0,2,0);
\draw[fill=magenta!10] (0,1,0) arc (90:206.5:.5cm and 1cm) -- (0,0,0) -- (0,1,0);
\end{tikzpicture}
\end{document}

-
It's cool to see the outside of the sphere colored as well. What do you suggest to clean up the code more? As an amateur tikz user my code seemed quite clean and readable. –  Johannes Jul 2 '14 at 11:42
@Johannes I wasn't thinking about the code but more that the angles seem not quite right.I guess this is Harish Kumar's point so perhaps he can explain how to do it. I think this is why I had to fiddle with the distances to approximate the right segments to fill. Even so, the results are clearly inaccurate as you can see the 'straight' lines are not always perfectly so... –  cfr Jul 2 '14 at 16:21
Perhaps a curved path between the points is a better option? Like (4,0,0) to[out=xx, in=yy] (0,4,0). That's what I was thinking about while I awaited answer. –  Johannes Jul 2 '14 at 16:35
@Johannes That certainly seems as if it would be worth a try. Have you experimented with it? –  cfr Jul 2 '14 at 17:55