# Differential of Surface Area Spherical Coordinates

Edit and compile if you like:

\documentclass{article}
\usepackage{tikz}
%\usepackage{amsmath,amssymb,amsfonts}
\usepackage{tikz-3dplot}
%\usetikzlibrary{math}
\usepackage{ifthen}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{1pt}
%
% File name: differential-of-surface-area-spherical-coordinates.tex
% Description:
% A geometric representation of the differential of surface area
% 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 surface area
\pgfmathsetmacro{\x}{1}
\pgfmathsetmacro{\y}{2}
\pgfmathsetmacro{\z}{2.5}
\pgfmathsetmacro{\step}{0.025}
% coordinates in spherical coordinates
\pgfmathsetmacro{\zf}{\radio+0.25} % 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
%
% 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$};
% Horizontal radius of length $\rho\,\sin\phi$
\draw[blue,<->] (0,0,\z) -- (\Sx,\Sy,\Sz) node [midway,sloped,fill=white] {\tiny$\rho\,\sin\phi$};
% Intersection of the sphere of radius $\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$};
% 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 surface area
\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 surface area
\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$
% 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 sufrace area in spherical coordinates
\draw[red,thick,fill=red,opacity=0.5] (\Px,\Py,\Pz) -- (\Tx,\Ty,\Tz) -- (\Wx,\Wy,\Wz) -- (\Sx,\Sy,\Sz) -- (\Px,\Py,\Pz);
% Nodes indicating lengths in the differential of surface area
\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) 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,1,0.5) node [right] {\footnotesize$\rho\,d\phi$};
\pgfmathsetmacro{\PTmx}{0.5*(\Px+\Tx)}
\pgfmathsetmacro{\PTmy}{0.5*(\Py+\Ty)}
\pgfmathsetmacro{\PTmz}{0.5*(\Pz+\Tz)}
\node[red,below right] at (\PTmx,\PTmy,\PTmz) {$dS$};
\end{tikzpicture}
\end{center}
%
\end{document}