3

I Hope someone can help me. I want to make a picture like this in latex. Everywhere I'm searching there are examples that are much too complicated, I think.

I can draw a circle, but LaTeX don't recognize it as a 3D-object. So I can't get a proper radius on it. I will give you my MWE but it's very minimal, I hope it don't bothers you to much for this time.

sphere_axis

\documentclass{standalone}

\usepackage{tikz}

\usepackage{pgfplots}
\usetikzlibrary{quotes,angles,shapes,arrows}

\pgfplotsset{compat=1.11}
\tikzset{>=latex}

\pagestyle{empty}

\begin{document}
\begin{tikzpicture} 
  \begin{axis}[
    view={35}{15},
    unit vector ratio=1 1 1,
    ticks = none,
    ymin=-2.8,
    ymax=0,
    xmax=2.8,
    xmin=0,
    zmin=0,
    zmax=2,
    axis lines=middle,
    xlabel=$x$,
    ylabel=$y$,
    zlabel=$z$,
    every axis x label/.style={at={(ticklabel* cs:1)},anchor=west,},
    every axis y label/.style={at={(ticklabel* cs:0)},anchor=north east,},
    every axis z label/.style={at={(ticklabel* cs:1)},anchor=south,},
    x axis line style=-,
    y axis line style=-,
    z axis line style=-,
    clip=false
  ]
    \draw[->](0,0)--(-2,2) node[midway, fill=white]{$r$};
    \shade[ball color = blue, opacity = 0.2] (0,0,0) circle [radius=2];
    \draw (0,0,0) circle [radius=2];
    \filldraw(0,0) circle (1pt) node[align=right,above,xshift=0.8em] {$G$};
  \end{axis}
\end{tikzpicture}
\end{document}

Thank you in advance,

Kees

  • The reason why your circle gets deformed is that you are drawing it in the xy plane. To the best of my knowledge there is not predefined coordinate system "screen coordinates" in pgfplots, but tikz-3dplot does have such a coordinate system. –  Jun 26 '19 at 19:05

1 Answers1

6

Welcome to TeX-SE! The reason why it does not work as you may expect is that you draw the circle in the xy plane, so it gets projected. You can of course use pgfplots to draw a sphere. In fact, if you do that, you have access to these powerful tools.

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture} 
  \begin{axis}[
    view={35}{15},
    unit vector ratio=1 1 1,
    ticks = none,
    ymin=-2.8,
    ymax=0,
    xmax=2.8,
    xmin=0,
    zmin=0,
    zmax=2,
    axis lines=middle,
    xlabel=$x$,
    ylabel=$y$,
    zlabel=$z$,
    every axis x label/.style={at={(ticklabel* cs:1)},anchor=west,},
    every axis y label/.style={at={(ticklabel* cs:0)},anchor=north east,},
    every axis z label/.style={at={(ticklabel* cs:1)},anchor=south,},
    x axis line style=-,
    y axis line style=-,
    z axis line style=-,
    clip=false
  ]
    \draw[->](0,0)--(-2,2) node[midway, fill=white]{$r$};
    \addplot3[surf,shader=interp,domain=0:360,y domain=-90:90,opacity=0.5,
    colormap={bluewhite}{color=(blue) color=(blue!30)},
    point meta=z+0.8*x+0.3*y] ({2*cos(y)*cos(x)},
    {2*cos(y)*sin(x)},{2*sin(y)});
    \addplot3[samples y=0,domain=0:360,smooth]({2*cos(x)},  {2*sin(x)},0);
    \filldraw(0,0) circle (1pt) node[align=right,above,xshift=0.8em] {$G$};
  \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

However, if you want to produce something similar to the screen shot, you may want to use tikz-3dplot instead. This allows you to draw a circle in the screen coordinates.

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{105}{-30}
\begin{tikzpicture}[tdplot_main_coords,thick]
    \path (0,0,0) coordinate (O);
    \pgfmathsetmacro{\Radius}{2} 
    \draw[gray]  (O) -- (\Radius,0,0) coordinate(X);
    \draw[gray] (O) -- (0,\Radius,0) coordinate(Y); 
    \draw[gray] (O) -- (0,0,\Radius) coordinate(Z);
    \draw[tdplot_screen_coords,-stealth] (O) -- (45:\Radius) node[midway,fill=white]{$r$};
    \shade[ball color=blue,tdplot_screen_coords,opacity=0.4] (O) circle[radius=\Radius];
    \foreach \X/\Y in {xy/z,yz/x,zx/y}
    {\begin{scope}[canvas is \X\space plane at \Y=\Radius]
     \fill circle[radius=2pt];
    \end{scope}}
    \draw[-stealth]  (X) -- (1.5*\Radius,0,0) node[pos=1.2] {$y$};
    \draw[-stealth] (Y) -- (0,2*\Radius,0) node[pos=1.2] {$x$};
    \draw[-stealth] (Z) -- (0,0,1.5*\Radius) node[pos=1.1] {$z$};
    \draw[thin] (xyz spherical cs:radius=\Radius,latitude=45,longitude=-20)
    to[bend right=20] node[pos=1.1,left]{$V=\frac{4}{3}\pi r^3$} (xyz spherical
    cs:radius=1.5*\Radius,latitude=45,longitude=-20);
\end{tikzpicture}
\end{document}

enter image description here