# Differential of Volume Spherical Coordinates

Edit and compile if you like:

\documentclass{article}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usepackage{ifthen}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{1pt}
%
% File name: differential-of-volume-spherical-coordinates.tex
% Description:
% A geometric representation of the differential of volume
% in spherical coordinates is shown.
%
% Date of last modification: October, 9th, 2022.
% Author: Efraín Soto Apolinar.
% https://www.aprendematematicas.org.mx/author/efrain-soto-apolinar/instructing-courses/
% Source: page 122 of the
% Glosario Ilustrado de Matem\'aticas Escolares.
% https://tinyurl.com/5udm2ufy
%
% According to TikZ.net
%
\begin{document}
%
\begin{center}
\tdplotsetmaincoords{70}{120}
%
\begin{tikzpicture}[tdplot_main_coords]
% Coordinates of the location of the differential of volume
\pgfmathsetmacro{\x}{0.75}
\pgfmathsetmacro{\y}{1.5}
\pgfmathsetmacro{\z}{2.25}
\pgfmathsetmacro{\step}{0.025}
% coordinates in spherical coordinates
\pgfmathsetmacro{\zf}{\radio+1.0} % To indicate the end point in the z axis
\pgfmathsetmacro{\angulot}{atan(\y/\x)} % angle $\theta$
\pgfmathsetmacro{\dominio}{\angulot*pi/180}	% Convert $\theta$ into radians
\pgfmathsetmacro{\angulop}{acos(\z/\radio)} % angle $\phi$
\pgfmathsetmacro{\dominiop}{\angulop*pi/180}	% Convert $\phi$ into radians
% Diferencial
\pgfmathsetmacro{\dradio}{0.75}	% Differential of $r$
\pgfmathsetmacro{\dangulot}{10}	% Differential of $\theta$
\pgfmathsetmacro{\dangulop}{10}	% Differential of $\phi$
\pgfmathsetmacro{\dominiof}{(\angulot+\dangulot)*pi/180}
% Vertices of the differential of area
% on the xy plane (in polar coordinates)
%
\pgfmathsetmacro{\angulotf}{\angulot+\dangulot}
\pgfmathsetmacro{\angulopf}{\angulop+\dangulop}
% Location of the node to indicate the angles $\theta$ and $\phi$
\pgfmathsetmacro{\xnodo}{0.35*cos(0.5*\angulot)}
\pgfmathsetmacro{\ynodo}{0.35*sin(0.5*\angulot)}
\pgfmathsetmacro{\xnodop}{0.35*sin(0.5*\angulop)*cos(\angulot)}
\pgfmathsetmacro{\ynodop}{0.35*sin(\angulop)*sin(\angulot)}
\pgfmathsetmacro{\znodop}{0.35*cos(0.5*\angulop)}
%
% Vertices of the differential of area in spherical coordinates
%
% Points to draw the angle $\phi$
% The origin
\coordinate (O) at (0,0,0);
% Coordinate axis
\draw[thick,->] (0,0,0) -- (\radiof+0.5,0,0) node [below left] {$x$};
\draw[thick,->] (0,0,0) -- (0,\radiof+0.5,0) node [right] {$y$};
\draw[thick,->] (0,0,0) -- (0,0,\zf+0.5) node [above] {$z$};
% Intersection of the sphere of radius $\rho$ with the plane $y = 0$
% Intersection of the sphere of radius $\rho + d\rho$ with the plane $y = 0$
% Differential of area in polar coordinates (on the xy-plane)
\draw[blue,dashed](0,0,0) --  (\xfrayouno,\yfrayouno,0) node[below left] {$\theta$};
\draw[blue,dashed](0,0,0) --  (\xfrayodos,\yfrayodos,0) node [below right] {$\theta + d\theta$};
% Indication of the angle $\theta$
\draw[blue] plot[domain=0:\dominio,smooth,variable=\t] ({0.5*cos(\t r)},{0.5*sin(\t r)},{0.0});  % 0.5236
\node[blue,below] at (\xnodo,\ynodo,0) {$\theta$};
%
\node[blue,above left] at (\radio,0,0) {$\rho$};
\node[blue,above left] at (\radiof,0,0) {$\rho + d\rho$};
% Differerential of area
\draw[blue] (\Ax,\Ay,0) -- (\Bx,\By,0)
-- (\Dx,\Dy,0)
-- (\Ax,\Ay,0);
% Plane at $\theta + d\theta$ (inside of the sphere)
\draw[blue,dashed,fill=yellow!50,opacity=0.35]
(0,0,0) -- (\Dx,\Dy,0) -- plot[domain=0.5*pi:0.0,smooth,variable=\t]
-- (0,0,0);
% lines from the origin to the differential of volume
\draw[blue,dashed] (O) -- (\Tx,\Ty,\Tz);
\draw[blue,dashed] (O) -- (\Wx,\Wy,\Wz);
% Plane at $\theta$ (inside the sphere)
\draw[blue,dashed,fill=yellow!50,opacity=0.35]
(0,0,0) -- (\Ax,\Ay,0) -- plot[domain=0.5*pi:0.0,smooth,variable=\t]
-- (0,0,0);
% lines from the origin to the differential of volume
\draw[blue,dashed] (O) -- (\Px,\Py,\Pz);
\draw[blue,dashed] (O) -- (\Sx,\Sy,\Sz);
% Arc to indicate the angle $\phi$
\draw[blue] plot[domain=0:\dominiop,smooth,variable=\t] ({0.5*sin(\t r)*cos(\angulot)},{0.5*sin(\t r)*sin(\angulot)},{0.5*cos(\t r)});
\node[blue,above] at (\xnodop,\ynodop,\znodop) {$\phi$};
\node[blue] at (\xnododp,\ynododp,\znododp) {$d\phi$};
% Intersection of the sphere of radius $\rho$ with the plane $x = 0$
% Intersection of the sphere of radius $\rho + d\rho$ with the plane $x = 0$
% Sphere of radius $\rho$
\draw[cyan,line width=3pt,opacity=0.05] plot[domain=0:0.5*pi,smooth,variable=\t] ({\r*cos(\t r)},{\r*sin(\t r)},{\altura});
\draw[cyan,thin,opacity=0.25] plot[domain=0:0.5*pi,smooth,variable=\t] ({\r*cos(\t r)},{\r*sin(\t r)},{\altura});
}
% The differential of volume in spherical coordinates
\draw[red,thick] (\Px,\Py,\Pz) -- (\Qx,\Qy,\Qz) -- (\Rx,\Ry,\Rz) -- (\Sx,\Sy,\Sz) -- (\Px,\Py,\Pz);
\draw[red,thick] (\Tx,\Ty,\Tz) -- (\Ux,\Uy,\Uz) -- (\Vx,\Vy,\Vz) -- (\Wx,\Wy,\Wz) -- (\Tx,\Ty,\Tz);
\draw[red,thick] (\Px,\Py,\Pz) -- (\Tx,\Ty,\Tz);
\draw[red,thick] (\Qx,\Qy,\Qz) -- (\Ux,\Uy,\Uz);
\draw[red,thick] (\Rx,\Ry,\Rz) -- (\Vx,\Vy,\Vz);
\draw[red,thick] (\Sx,\Sy,\Sz) -- (\Wx,\Wy,\Wz);
% Sphere of radius $\rho + d\rho$
\draw[cyan,line width=3pt,opacity=0.05] plot[domain=0:0.5*pi,smooth,variable=\t] ({\r*cos(\t r)},{\r*sin(\t r)},{\altura});
\draw[cyan,thin,opacity=0.25] plot[domain=0:0.5*pi,smooth,variable=\t] ({\r*cos(\t r)},{\r*sin(\t r)},{\altura});
}
% Plane at $\theta + d\theta$ (part that is out of the sphere)
\draw[blue,dashed,fill=yellow!50,opacity=0.35]
(\Cx,\Cy,0) -- (\xfrayodos,\yfrayodos,0) -- plot[domain=0.5*pi:0.0,smooth,variable=\t]
-- (0,0,\zf) -- (\xfrayodos,\yfrayodos,\zf) -- (\xfrayodos,\yfrayodos,0) -- (\Cx,\Cy,0);
% Indication for the angle $\phi$
\draw[blue,dashed] (\Ux,\Uy,\Uz) -- (\Uex,\Uey,\Uez);
\draw[blue,dashed] (\Vx,\Vy,\Vz) -- (\Vex,\Vey,\Vez);
% Plane at $\theta$ (part that is out of the sphere)
\draw[blue,dashed,fill=yellow!50,opacity=0.35]
(\Bx,\By,0) -- (\xfrayouno,\yfrayouno,0) -- plot[domain=0.5*pi:0.0,smooth,variable=\t]
-- (0,0,\zf) -- (\xfrayouno,\yfrayouno,\zf) -- (\xfrayouno,\yfrayouno,0) -- (\Bx,\By,0);
% Indication for the angle $\phi$
\draw[blue,dashed] (\Qx,\Qy,\Qz) -- (\Qex,\Qey,\Qez);
\draw[blue,dashed] (\Rx,\Ry,\Rz) -- (\Rex,\Rey,\Rez);
%
% Nodes indicating lengths in the differential of volume
%
\pgfmathsetmacro{\SWmx}{0.5*(\Sx+\Wx)}
\pgfmathsetmacro{\SWmy}{0.5*(\Sy+\Wy)}
\pgfmathsetmacro{\SWmz}{0.5*(\Sz+\Wz)}
\draw[<-,shift={(\SWmx,\SWmy,\SWmz)}] (0,0,0) -- (-0.5,-0.5,1.75) node [above] {\footnotesize$\rho\,\sin\phi\,d\theta$};
\pgfmathsetmacro{\TWmx}{0.5*(\Wx+\Tx)}
\pgfmathsetmacro{\TWmy}{0.5*(\Wy+\Ty)}
\pgfmathsetmacro{\TWmz}{0.5*(\Wz+\Tz)}
\draw[<-,shift={(\TWmx,\TWmy,\TWmz)}] (0,0,0) -- (-1,0.75,1.5) node [above] {~~~\footnotesize$\rho\,d\phi$};
\end{tikzpicture}
\end{center}
%
\end{document}