# Differential Volume in Spherical Coordinates

For more figures related to the definition of coordinate systems, please have a look at the “coordinates” tag.

Edit and compile if you like:

\documentclass[border=3pt]{standalone}

\usepackage{tikz}
\usepackage{tikz-3dplot}

\begin{document}

%Axis Angles
\tdplotsetmaincoords{70}{110}

%Macros
\pgfmathsetmacro{\rvec}{6}
\pgfmathsetmacro{\thetavec}{40}
\pgfmathsetmacro{\phivec}{45}

\pgfmathsetmacro{\dphivec}{20}
\pgfmathsetmacro{\dthetavec}{20}
\pgfmathsetmacro{\drvec}{1.5}

%Layers
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}

\pgfsetlayers{background, main, foreground}

\begin{tikzpicture}[tdplot_main_coords]

%Coordinates
\coordinate (O) at (0,0,0);
%
\tdplotsetcoord{A}{\rvec}{\thetavec}{\phivec}
\tdplotsetcoord{B}{\rvec}{\thetavec + \dthetavec}{\phivec}
\tdplotsetcoord{C}{\rvec}{\thetavec + \dthetavec}{\phivec + \dphivec}
\tdplotsetcoord{D}{\rvec}{\thetavec}{\phivec + \dphivec}
%
\tdplotsetcoord{E}{\rvec + \drvec}{\thetavec}{\phivec}
\tdplotsetcoord{F}{\rvec + \drvec}{\thetavec + \dthetavec}{\phivec}
\tdplotsetcoord{F'}{\rvec + \drvec}{90}{\phivec}
\tdplotsetcoord{G}{\rvec + \drvec}{\thetavec + \dthetavec}{\phivec + \dphivec}
\tdplotsetcoord{G'}{\rvec + \drvec}{90}{\phivec + \dphivec}
\tdplotsetcoord{H}{\rvec + \drvec}{\thetavec}{\phivec + \dphivec}
%%%Nodes
%\node at (A) {A};
%\node at (B) {B};
%\node at (C) {C};
%\node at (D) {D};
%\node at (E) {E};
%\node at (F) {F};
%\node at (G) {G};
%\node at (H) {H};

%Axis
\begin{pgfonlayer}{background}
\draw[thick,-latex] (0,0,0) -- (7,0,0) node[pos=1.1]{$x$};
\draw[thick,-latex] (0,0,0) -- (0,7,0) node[pos=1.05]{$y$};
\draw[thick,-latex] (0,0,0) -- (0,0,6) node[pos=1.05]{$z$};
\end{pgfonlayer}

%Help Lines
\begin{pgfonlayer}{background}
%Up
\draw[thick, blue] (O) -- (A) node[pos=0.6, above left, blue] {$r$};
\draw (O) -- (B);
\draw (O) -- (C);
\draw[dashed] (O) -- (D);
%Down
\draw (O) -- (F');
\draw (O) -- (G');
\end{pgfonlayer}
\begin{pgfonlayer}{foreground}
%%Help Curves
\tdplotsetthetaplanecoords{\phivec}
\tdplotdrawarc[tdplot_rotated_coords]{(O)}{\rvec}{\thetavec+\dthetavec}{90}{}{}
\tdplotdrawarc[tdplot_rotated_coords]{(O)}{\rvec+\drvec}{\thetavec+\dthetavec}{90}{}{}
\tdplotsetthetaplanecoords{\phivec+\dphivec}
\tdplotdrawarc[tdplot_rotated_coords, dashed]{(O)}{\rvec}{\thetavec+\dthetavec}{90}{}{}
\tdplotdrawarc[tdplot_rotated_coords]{(O)}{\rvec+\drvec}{\thetavec+\dthetavec}{90}{}{}
%
\tdplotdrawarc[tdplot_main_coords]{(O)}{\rvec}{\phivec}{\phivec+\dphivec}{}{}
\node[rotate=13] at (3,4.45,0) {$r\sin\theta\mathrm{d}\phi$};
\tdplotdrawarc[tdplot_main_coords]{(O)}{\rvec+\drvec}{\phivec}{\phivec+\dphivec}{}{}
\end{pgfonlayer}

%Angles
\begin{pgfonlayer}{foreground}
%Phi, dPhi
\tdplotdrawarc[-stealth]{(O)}{0.9}{0}{\phivec}{anchor=north}{$\phi$}
\tdplotdrawarc[-stealth]{(O)}{1.5}{\phivec}{\phivec + \dphivec}{}{}
\node at (1.4,1.9,0) {$\mathrm{d}\phi$};

\tdplotsetthetaplanecoords{\phivec}

%Theta, dTheta
\tdplotdrawarc[tdplot_rotated_coords, -stealth]{(0,0,0)}{1.2}{0}{\thetavec}{}{}
\node at (0,0.3,1.3) {$\theta$};
\tdplotdrawarc[tdplot_rotated_coords, -stealth]{(0,0,0)}{2.}{\thetavec}{\thetavec + \dthetavec}{anchor=south west}{$\mathrm{d}\theta$}
\end{pgfonlayer}

%Differential Volume

%%Lines
\begin{pgfonlayer}{foreground}
\draw[thick] (A) -- (E) node[midway, above left]{$\mathrm{d}r$};
\draw[thick] (B) -- (F);
\draw[thick] (C) -- (G);
\end{pgfonlayer}
\begin{pgfonlayer}{background}
\draw[dashed, thick] (D) -- (H);
\end{pgfonlayer}

%%Curved
\begin{pgfonlayer}{background}
\tdplotsetrotatedcoords{55}{-50.4313}{-6.4086}
\tdplotdrawarc[dashed, tdplot_rotated_coords, thick]{(O)}{\rvec}{0}{12.8173}{}{}
%
\tdplotsetthetaplanecoords{\phivec + \dphivec}
\tdplotdrawarc[dashed, tdplot_rotated_coords, thick]{(O)}{\rvec}{\thetavec}{\dthetavec + \thetavec}{}{}
\end{pgfonlayer}
\begin{pgfonlayer}{foreground}
\tdplotsetthetaplanecoords{\phivec}
\tdplotdrawarc[tdplot_rotated_coords, thick]{(O)}{\rvec}{\thetavec}{\dthetavec + \thetavec}{below left}{$r\mathrm{d}\theta$}
\tdplotdrawarc[tdplot_rotated_coords, thick]{(O)}{\rvec + \drvec}{\thetavec}{\dthetavec + \thetavec}{}{}
%
\tdplotsetthetaplanecoords{\phivec + \dphivec}
\tdplotdrawarc[tdplot_rotated_coords, thick]{(O)}{\rvec + \drvec}{\thetavec}{\dthetavec + \thetavec}{}{}
%
\tdplotsetrotatedcoords{55}{-50.4313}{-6.4086}
\tdplotdrawarc[tdplot_rotated_coords, thick]{(O)}{\rvec + \drvec}{0}{12.8173}{}{}
%
\tdplotsetrotatedcoords{55}{-30.3813}{-8.6492}
\tdplotdrawarc[tdplot_rotated_coords, thick]{(O)}{\rvec}{0}{17.2983}{}{}
\tdplotdrawarc[tdplot_rotated_coords, thick]{(O)}{\rvec + \drvec}{0}{17.2983}{}{}
\end{pgfonlayer}

%Fill Color
\begin{pgfonlayer}{main}
%Front
\fill[black, opacity=0.15] (E) to (A)  to[bend left=4] (B) to (F) to[bend right=4] cycle;
\fill[black, opacity=0.6] (E) to[bend left=4] (F)  to[bend left=2] (G) to[bend right=6.5] (H) to[bend right=4] cycle;
\fill[black, opacity=0.4] (F) to[bend left=2] (G) to[bend left=1.5] (C) to[bend right=2.5] (B) to[bend right=4] cycle;
\end{pgfonlayer}
\begin{pgfonlayer}{background}
%Back
\fill[black!50, opacity=0.5] (A) to[bend left=2] (D) to[bend left=6] (C) to[bend right=2.5] (B) to[bend right=4] cycle;
\fill[black!50, opacity=0.5] (A) to[bend left=2] (D) to (H) to[bend right=2.5] (E) to[bend right=4] cycle;
\fill[black!50, opacity=0.5] (D) to (H) to[bend left=6] (G) to[bend right=2] (C) to[bend right=6] cycle;
\end{pgfonlayer}

\end{tikzpicture}

\end{document}