1

I got this code:

\begin{tikzpicture}
\draw (0,0) circle (3);

\draw[dashed] (({3*cos(45)},{3*sin(45)}) arc (0:180:{3*cos(45)} and 0.7);
\draw (({3*cos(45)},{3*sin(45)}) arc (0:-180:{3*cos(45)} and 0.7);

\draw[dashed] (({3*cos(30)},{3*sin(30)}) arc (0:180:{3*cos(30)} and 0.7);
\draw (({3*cos(30)},{3*sin(30)}) arc (0:-180:{3*cos(30)} and 0.7);

\draw[dashed] (3,0) arc (0:180:3 and 0.7);
\draw (3,0) arc (0:-180:3 and 0.7);

\draw[dashed] (({3*cos(-30)},{3*sin(-30)}) arc (0:180:{3*cos(-30)} and 0.7);
\draw (({3*cos(-30)},{3*sin(-30)}) arc (0:-180:{3*cos(-30)} and 0.7);

\end{tikzpicture}

which produces the following sphere:

enter image description here

My question is: Why do the arcs' borders are slightly out of the sphere? Is there a way to fix it so I can get those arcs within the sphere boundaries? Of course I know I can manually start testing values for the arcs' radii to achieve my goal, but I want a general solution.

Thanks!

  • Have a look at this question: https://tex.stackexchange.com/questions/46850/how-can-i-draw-an-arc-from-point-a-b-on-a-3d-sphere-in-tikz – Nico Jul 15 '20 at 11:38
  • You might find https://tex.stackexchange.com/questions/408245/clipping-more-complicated-shapes-in-tikz/410379?r=SearchResults&s=12|3.8830#410379 useful. – John Kormylo Jul 15 '20 at 12:37

1 Answers1

2

This question have good hints in the comments for drawing the sphere and its parallels in 3d. But if only the parallels are needed there is a simple way to do it in 2d.

The following code

\documentclass[border=2mm]{standalone}
\usepackage{tikz}

\def\r{2} % sphere radius \def\k{0.7} % ratio between ellipse axes b/a, 0<k<1 \def\n{31} % number of parallels to draw, n>1 \pgfmathsetmacro\f{sqrt(1-\k\k)} % relation between a tangent point and its height \begin{document} \begin{tikzpicture} \foreach\i in {1,...,\n} {% \pgfmathsetmacro\h{(\i/(\n+1)-0.5)2\r\f} % parallel height \pgfmathsetmacro\y{\h/\f/\f} % tangent point y \pgfmathsetmacro\a{sqrt(\r\r-\y\y+(\y-\h)(\y-\h)/(\k\k))} % semi-major axis \pgfmathsetmacro\b{\k\a} % semi-minor axis \begin{scope} % front parallels, both spheres \clip (-\r,\y) rectangle (3.5\r,-\r); \draw (0,\h) ellipse (\a cm and \b cm); % left sphere (parallels) \draw (2.5\r,\h) ellipse (\a cm and \b cm); % right sphere (parallels) \end{scope} \begin{scope} % back parallels, right sphere \clip (-\r,\y) rectangle (3.5\r,\r); \draw[thin,gray!50] (2.5\r,\h) ellipse (\a cm and \b cm); \end{scope} } \draw[thick,red] (0,0) circle (\r); % left sphere \draw[thick,red] (2.5\r,0) circle (\r); % right sphere \end{tikzpicture} \end{document}

produces: enter image description here

A hint at the maths
Let x^2+y^2=r^2 be the 2d projection of the sphere and x^2/a^2+(y-h)^2/b^2=1 be the 2d projection of a parallel at height h. Fix b=ka with k given (all the ellipses must have the same axes ratio k). Imposing that both curves have a common tangent point (for example, taking derivatives and equaling them) we obtain an expression for the y coordinate of such tangent point. Then we find the value of a (semi-major axis) so the ellipse passes through that point. Now, as b=ka, we have the equation of the ellipse. We could also calculate the angles for drawing arcs instead of clipping the ellipses, but in this case I think that the clips are easier than the maths.

Juan Castaño
  • 28,426