22

I can try to draw this in TikZ:

first image second image

I managed to draw the coordinate axis. The first image is in cylindrical coordinates and the second in spherical coordinates. I don't know draw in spherical coordinate system, the arrow labels, curved lines, and many other things.

I have started to read the manual of Till Tantau, but for now I'm a newbie with TikZ and I don't understand many things of this manual.

Kiyoshi
  • 1,112
  • 4
  • 13
  • 22

6 Answers6

28

I don't understand the 3D behavior of tikz very well, but here's a way to do one of your pictures in Asymptote using a bunch of lines, arcs, and labels.

A few of the built-in Asymptote commands I used:

  • X is the unit vector (1,0,0) similarly for Y and Z
  • expi(theta,phi) returns the unit vector in the theta,phi direction

Updated to incorporate a few of Charles Staats' suggestions

  • Changed the dashed lines to solid lines
  • Reduced weight on the labeling lines and arcs and increased weight on axes
  • added a light, nearly transparent spherical surface on which the volume element lives . . . I think this helps with perspective

 

\documentclass{article}
\usepackage{asymptote}

\begin{document}

\begin{asy}[width=0.5\textwidth]
settings.render=6;
settings.prc=false;
import three;
import graph3;
import grid3;
currentprojection=orthographic(1,-0.175,0.33,up=Z);

//Draw Axes
pen thickblack = black+0.75;
real axislength = 1.33;
draw(L=Label("$x$", position=Relative(1.1), align=SW), O--axislength*X,thickblack, Arrow3); 
draw(L=Label("$y$", position=Relative(1.1), align=N), O--axislength*Y,thickblack, Arrow3); 
draw(L=Label("$z$", position=Relative(1.1), align=N), O--axislength*Z,thickblack, Arrow3); 

//Set parameters of start corner of polar volume element
real r = 1;
real q=0.3pi; //theta
real f=0.35pi; //phi

real dq=0.15; //dtheta
real df=0.3; //dphi
real dr=0.1; 


// Arq is A + dr*rhat + dq*qhat, etc
triple A = r*expi(q,f);
triple Ar = (r+dr)*expi(q,f);
triple Aq = r*expi(q+dq,f);
triple Arq = (r+dr)*expi(q+dq,f);
triple Af = r*expi(q,f+df);
triple Arf = (r+dr)*expi(q,f+df);
triple Aqf = r*expi(q+dq,f+df);
triple Arqf = (r+dr)*expi(q+dq,f+df);

pen thingray = gray+0.33;

draw(A--Ar);
draw(Aq--Arq);
draw(Af--Arf);
draw(Aqf--Arqf);
draw( arc(O,A,Aq) ,thickblack );
draw( arc(O,Af,Aqf),thickblack );
draw( arc(O,Ar,Arq) );
draw( arc(O,Arf,Arqf) );
draw( arc(O,Ar,Arq) );
draw( arc(O,A,Af),thickblack );
draw( arc(O,Aq,Aqf),thickblack );
draw( arc(O,Ar,Arf) );
draw( arc(O,Arq,Arqf) );

pen thinblack = black+0.25;

//phi arcs
draw(O--expi(pi/2,f),thinblack);
draw("$\varphi$", arc(O,0.5*X,0.5*expi(pi/2,f)),thinblack,Arrow3);
draw(O--expi(pi/2,f+df),thinblack);
draw( "$d\varphi$", arc(O,expi(pi/2,f),expi(pi/2,f+df) ),thinblack );
draw( A.z*Z -- A,thinblack);
draw(L=Label("$r\sin{\theta}$",position=Relative(0.5),align=N), A.z*Z -- Af,thinblack);

//cotheta arcs
draw( arc(O,Aq,expi(pi/2,f)),thinblack );
draw( arc(O,Aqf,expi(pi/2,f+df) ),thinblack);

//theta arcs
draw(O--A,thinblack);
draw(O--Aq,thinblack);
draw("$\theta$", arc(O,0.25*length(A)*Z,0.25*A),thinblack,Arrow3);
draw(L=Label("$d\theta$",position=Relative(0.5),align=NE) ,arc(O,0.66*A,0.66*Aq),thinblack );


// inner surface
triple rin(pair t) {  return r*expi(t.x,t.y);}
surface inner=surface(rin,(q,f),(q+dq,f+df),16,16);
draw(inner,emissive(gray+opacity(0.33)));
//part of a nearly transparent sphere to help see perspective
surface sphere=surface(rin,(0,0),(pi/2,pi/2),16,16);
draw(sphere,emissive(gray+opacity(0.125)));


// dr and rdtheta labels
draw(L=Label("$dr$",position=Relative(1.1)), Af + 0.5*(Arf-Af)--Af + 0.5*(Arf-Af)+0.25*Z,dotted);
triple U=expi(q+0.5*dq,f);
draw(L=Label("$rd\theta$",position=Relative(1.1)), r*U ---r*(1.33*U.x,1.33*U.y,U.z),dotted );

\end{asy}

\end{document}

enter image description here

Update #2

Charles Staats pointed out good parameters for an oblique projection, which better matches the original picture. Using currentprojection=obliqueX, width=\textwidth, and editing the labels a bit to better suit this projection:

enter image description here

Orthographic code:

\documentclass{article}
\usepackage{asymptote}

\begin{document}

\begin{asy}[width=\textwidth]
settings.render=6;
settings.prc=false;
import three;
import graph3;
import grid3;
currentprojection=obliqueX;

//Draw Axes
pen thickblack = black+0.75;
real axislength = 1.0;
draw(L=Label("$x$", position=Relative(1.1), align=SW), O--axislength*X,thickblack, Arrow3); 
draw(L=Label("$y$", position=Relative(1.1), align=E), O--axislength*Y,thickblack, Arrow3); 
draw(L=Label("$z$", position=Relative(1.1), align=N), O--axislength*Z,thickblack, Arrow3); 

//Set parameters of start corner of polar volume element
real r = 1;
real q=0.25pi; //theta
real f=0.3pi; //phi

real dq=0.15; //dtheta
real df=0.15; //dphi
real dr=0.15; 

triple A = r*expi(q,f);
triple Ar = (r+dr)*expi(q,f);
triple Aq = r*expi(q+dq,f);
triple Arq = (r+dr)*expi(q+dq,f);
triple Af = r*expi(q,f+df);
triple Arf = (r+dr)*expi(q,f+df);
triple Aqf = r*expi(q+dq,f+df);
triple Arqf = (r+dr)*expi(q+dq,f+df);

pen thingray = gray+0.33;

draw(A--Ar);
draw(Aq--Arq);
draw(Af--Arf);
draw(Aqf--Arqf);
draw( arc(O,A,Aq) ,thickblack );
draw( arc(O,Af,Aqf),thickblack );
draw( arc(O,Ar,Arq) );
draw( arc(O,Arf,Arqf) );
draw( arc(O,Ar,Arq) );
draw( arc(O,A,Af),thickblack );
draw( arc(O,Aq,Aqf),thickblack );
draw( arc(O,Ar,Arf) );
draw( arc(O,Arq,Arqf) );

pen thinblack = black+0.25;

//phi arcs
draw(O--expi(pi/2,f),thinblack);
draw("$\varphi$", arc(O,0.5*X,0.5*expi(pi/2,f)),thinblack,Arrow3);
draw(O--expi(pi/2,f+df),thinblack);
draw( "$d\varphi$", arc(O,expi(pi/2,f),expi(pi/2,f+df) ),thinblack );
draw( A.z*Z -- A,thinblack);
draw(L=Label("$r\sin{\theta}$",position=Relative(0.5),align=N), A.z*Z -- Af,thinblack);

//cotheta arcs
draw( arc(O,Aq,expi(pi/2,f)),thinblack );
draw( arc(O,Aqf,expi(pi/2,f+df) ),thinblack);

//theta arcs
draw(O--A,thinblack);
draw(O--Aq,thinblack);
draw("$\theta$", arc(O,0.25*length(A)*Z,0.25*A),thinblack,Arrow3);
draw(L=Label("$d\theta$",position=Relative(0.5),align=NE) ,arc(O,0.66*A,0.66*Aq),thinblack );


// inner surface
triple rin(pair t) {  return r*expi(t.x,t.y);}
surface inner=surface(rin,(q,f),(q+dq,f+df),16,16);
draw(inner,emissive(gray+opacity(0.33)));
//part of a nearly transparent sphere to help see perspective
surface sphere=surface(rin,(0,0),(pi/2,pi/2),16,16);
draw(sphere,emissive(gray+opacity(0.125)));


// dr and rdtheta labels
triple V= Af + 0.5*(Arf-Af);
draw(L=Label("$dr$",position=Relative(1.1)), V--(1.5*V.x,1.5*V.y,V.z),dotted);
triple U=expi(q+0.5*dq,f);
draw(L=Label("$rd\theta$",position=Relative(1.1)), r*U ---r*(1.66*U.x,1.66*U.y,U.z),dotted );

\end{asy}

\end{document}
  • This is beautiful! Nevertheless, I can't resist a couple of points. The dashed line below dtheta should be solid, and there should be another line (solid, from this point of view) to the fourth corner of the surface. (The original diagram gets away with omitting this because that line would be blocked from view; but from your point of view, it's not.) – Charles Staats Feb 15 '14 at 00:24
  • One of the great things about this answer is that it's easy to experiment with changing the parameters and the point of view. The one exception is the inner surface, which will work better from many points of view if you replace gray+opacity(0.25) by emissive(gray+opacity(0.25)). – Charles Staats Feb 15 '14 at 00:28
  • One final point, for those interesting in playing around with this excellent diagram: the projection used in the original diagram is called obliqueX in Asymptote. – Charles Staats Feb 15 '14 at 00:34
  • @CharlesStaats Thanks for the suggestions, I've made a few changes to incorporate them. (The dashed lines were a bad idea.) I'm not sure what you mean by the "fourth corner" of the surface, though. Also, I know that I have strayed a bit from the OP's diagram, but I added a light sphere that I think really helps with perspective. – Chris Chudzicki Feb 15 '14 at 01:01
  • @CharlesStaats Thanks for pointing out obliqueX! Unfortunately [and it may just be the (theta,phi) values I chose] I find it much harder to see the dr length when using this perspective. – Chris Chudzicki Feb 15 '14 at 01:03
  • I find that the following parameters work fairly well for obliqueX: [width=\textwidth], axislength=1.0, q=0.25pi, f=0.3pi, and dq, df, dr are all equal to 0.15. – Charles Staats Feb 15 '14 at 01:12
  • Also, I agree that the quarter-sphere improves the clarity of the diagram. – Charles Staats Feb 15 '14 at 01:13
  • I will accept this answer as good because the community so desires. Not what I wanted (I wanted to do with TikZ), but I value this response. – Kiyoshi Feb 17 '14 at 21:51
  • I tried to use the orthographic code - but it does not work for me - see here: https://www.overleaf.com/read/djcwkngcnjdr - whats wrong here? – Vertexwahn Apr 28 '17 at 19:51
24

I have prepared a lecture notes on electromagnetic field theory for my students. I have drawn surfaces used in cylindrical coordinate system. For this I have used tikz-3dplot package. Here is the code and output. I hope this is a starting point for you.

\documentclass{article}
\usepackage{tikz,tikz-3dplot}
\begin{document}

\begin{figure}
\centering
\tdplotsetmaincoords{70}{120}
\begin{tikzpicture}[tdplot_main_coords][scale=0.75]
\tikzstyle{every node}=[font=\small]
\draw[thick,-latex] (0,0,0) -- (6,0,0) node[anchor=north east]{$x$};
\draw[thick,-latex] (0,0,0) -- (0,6,0) node[anchor=north west]{$y$};
\draw[thick,-latex] (0,0,0) -- (0,0,6) node[anchor=south]{$z$};
\draw [thick](0,0,0) circle (3);
\draw [thick](0,0,4) circle (3);
\draw [thick](1.9,-2.35,0) -- (1.9,-2.35,4) node[midway, left]{$r=r_1$ surface};
\draw [thick](-1.9,2.35,0) -- (-1.9,2.35,4);
\filldraw[fill=orange, nearly transparent] (-4,-4,4) -- (4,-4,4) --  (4,5,4) -- (-4,5,4) -- (-4,-4,4);
\filldraw[fill=blue, nearly transparent] (0,0,4) -- (5.2,6,4) --  (5.2,6,0) -- (0,0,0) -- (0,0,4);
\filldraw [color=blue](2,2.25,4) circle (0.075cm) ;
\draw (-4,5,4) node[anchor=south]{$z=z_1$ plane};
\draw (5.2,6,0) node[anchor=south west]{$\phi=\phi_1$ plane};
\node at (1.8,1,4)  { $P_1(r_1,\phi_1,z_1)$};
\draw[ultra thick,-latex](2,2.25,4) -- (3,3.45,4) node[anchor=north] {$\mathbf{a}_r$};
\draw[ultra thick,-latex](2,2.25,4) -- (1,2.5,4) node[anchor=north west] {$\mathbf{a}_\phi$};
\draw[ultra thick,-latex](2,2.25,4) -- (2,2.25,4.75) node[anchor=north west] {$\mathbf{a}_z$};
\draw [thick,->](4,0,0) arc (0:45:4 and 4.5);
\draw (3.6,2,0) node[anchor=north] {$\phi_1$};
\draw[ultra thick,-latex](0,0,0) -- (2,2.35,0);
\draw (1,1,0) node[anchor=north] {$r_1$};
\draw [ultra thick] (2,2.25,4)--(1.95,2.25,0);

\draw[ultra thick](0.1,0,4) -- (-0.1,0,4) node[anchor=south west] {$z_1$};
\end{tikzpicture}
\end{figure}
\end{document}

enter image description here

giordano
  • 8,486
  • @ferahfera - Thanks, is a good starting point for a cylindrical illustration. – Kiyoshi Feb 10 '14 at 11:06
  • You use a circle for making the illustration, but I don't need a complete cylinder, how I can take only the part between the x axis and the y axis? – Kiyoshi Feb 10 '14 at 15:02
  • @Kiyoshi, u can use 'arc' command. http://tex.stackexchange.com/q/66216/31034 –  Feb 10 '14 at 18:18
  • Thanks for the link but I can't do what I want. For now my knowledge about TikZ are insufficient. – Kiyoshi Feb 10 '14 at 19:16
  • @ferahfeza Where did you find 3dplot.sty? Shouldn't it be tikz-3dplot.sty? – giordano Feb 14 '14 at 23:41
  • @giordano, i found it from here: http://code.google.com/p/tikz-examples/source/browse/examples/contrib4/3dplot.sty?r=78ee4de214cf8986093a2da99c579531c150c000 –  Feb 15 '14 at 11:38
  • @ferahfeza http://www.ctan.org/pkg/tikz-3dplot – giordano Feb 15 '14 at 11:47
  • @giordano, i dont know what is difference between two style file. As you see my file name is 3dplot.sty –  Feb 15 '14 at 12:04
  • 2
    @ferahfeza CTAN is the official resource for LaTeX style files, a random repository on Google Code is not. TeX Live and MikTeX take their LaTeX packages from CTAN. The package I linked is the updated version of that 3dplot.sty, probably you already have tikz-3dplot in your distribution without manually downloading an old version from the Internet. – giordano Feb 15 '14 at 12:15
9

First, I want to give all the credit to @mrc . His work is quite good.

I want to complete a few details on his work. Basically he is missing two segments which makes sometimes the visualization difficult. For example the bottom of the cube, could look like the side towards the reader due to the missing two segments. Small details are arrows for angles increments, tilted text, smaller fonts, and different perspective, but again I am building on top of @mrc work.Spherical Coordinates

 \begin{asy}[]
  if(!settings.multipleView) settings.batchView=false;
  import three;
  settings.tex="pdflatex";
  defaultfilename="input-1";
  if(settings.render < 0) settings.render=40;
  settings.outformat="";
  settings.inlineimage=true;
  settings.embed=true;
  settings.toolbar=false;
  defaultpen(fontsize(8pt));



  size(9.5cm);
  settings.outformat="pdf";
  settings.prc=false;
  import graph3;
  import grid3;

  currentprojection=orthographic(
  camera=(2.9637389483254,1.48144594554777,1.03154384251566),
  up=(-0.00245695858860577,0.00028972293310393,0.00664306468788549),
  target=(0,0,0),
  zoom=0.971150237157127);


  //Draw Axes
  pen thickblack = black+0.75;
  real axislength = 1.0;
  draw(L=Label("$x$", position=Relative(1.1), align=SW),
  O--axislength*X,thickblack, Arrow3);
  draw(L=Label("$y$", position=Relative(1.1), align=E),
  O--axislength*Y,thickblack, Arrow3);
  draw(L=Label("$z$", position=Relative(1.1), align=N),
  O--axislength*Z,thickblack, Arrow3);

  //Set parameters of start corner of polar volume element
  real r = 0.8;
  real q=0.25pi; //theta
  real f=0.3pi; //phi

  real dq=0.25; //dtheta
  real df=0.25; //dphi
  real dr=0.15;

  triple A = r*expi(q,f);
  triple Ar = (r+dr)*expi(q,f);
  triple Aq = r*expi(q+dq,f);
  triple Arq = (r+dr)*expi(q+dq,f);
  triple Af = r*expi(q,f+df);
  triple Arf = (r+dr)*expi(q,f+df);
  triple Aqf = r*expi(q+dq,f+df);
  triple Arqf = (r+dr)*expi(q+dq,f+df);

  //label("$A$",A);
  //label("$Ar$",Ar);
  //label("$Aq$",Aq);
  //label("$Arq$",Arq);
  //label("$Af$",Af);
  //label("$Aqf$",Aqf);
  //label("$Arf$",Arf);
  //label("$\; \; \quad Arqf$",Arqf);


  pen thingray = gray+0.33;

  draw(A--Ar);
  draw(Aq--Arq);
  draw(Af--Arf);
  draw(Aqf--Arqf);
  draw(O--Af, dashed);
  draw(O--Aqf);
  draw( arc(O,A,Aq) ,thickblack );
  draw( arc(O,Af,Aqf),thickblack );
  draw( arc(O,Ar,Arq) );
  draw( arc(O,Arf,Arqf) );
  draw( arc(O,Ar,Arq) );
  draw( arc(O,A,Af),thickblack );
  draw( arc(O,Aq,Aqf),thickblack );
  draw( arc(O,Ar,Arf) );
  draw( arc(O,Arq,Arqf));

  pen thinblack = black+0.25;

  //phi arcs
  draw(O--expi(pi/2,f),thinblack);
  draw("$\phi$", arc(O,0.5*X,0.5*expi(pi/2,f)),thinblack,Arrow3);
  draw(O--expi(pi/2,f+df),thinblack);
  draw( "$d\phi$", arc(O,expi(pi/2,f),expi(pi/2,f+df) ),thinblack , Arrow3);
  draw( A.z*Z -- A,thinblack);
  draw(L=Label(rotate(-5)*"$r\sin{\theta}$",position=Relative(0.5),align=N), A.z*Z -- Af,thinblack);

  //cotheta arcs
  draw( arc(O,Aq,expi(pi/2,f)),thinblack );
  draw( arc(O,Aqf,expi(pi/2,f+df) ),thinblack);

  //theta arcs
  draw(O--A,thinblack);
  draw(O--Aq,thinblack);
  draw(L=Label("$\theta$",position=Relative(0.5), align=NE),
  arc(O,0.25*length(A)*Z,0.25*A),thinblack,Arrow3);
  draw(L=Label("$d\theta$",position=Relative(0.5),align=NE) ,arc(O,0.66*A,0.66*Aq),
  thinblack, Arrow3 );


  // inner surface
  triple rin(pair t) { return r*expi(t.x,t.y);}
  triple rout(pair t) { return 1.24*r*expi(t.x,t.y);}
  surface inner=surface(rin,(q,f),(q+dq,f+df),16,16);
  draw(inner,emissive(gray+opacity(0.33)));

  // surface sider=surface(rin,(f,r),(f+df,r+dr),16,16);
  // draw(sider,emissive(gray+opacity(0.33)));


  //part of a nearly transparent sphere to help see perspective
  surface sphere=surface(rout,(0,0),(pi/2,pi/2),26,26);
  draw(sphere,emissive(gray+opacity(0.125)));


  // dr and rdtheta labels
  triple V= Af + 0.5*(Arf-Af);
  draw(L=Label("$dr$",position=Relative(1.1)), V--(1.5*V.x,1.5*V.y,V.z),dotted);
  triple U=expi(q+0.5*dq,f);
  draw(L=Label("$rd\theta$",position=Relative(1.1)),
  r*U ---r*(1.66*U.x,1.66*U.y,U.z),dotted );
\end{asy}
  • Is it possible to publish a PDF version of that last picture (all vectorial) ? I would like to open it in my drawing app to edit it. – Cham Jul 19 '17 at 19:59
  • Hello, I would like to add this figure in my notes on dynamic meteorology. However when I insert this code in my document I do not get any plot, except the following error "Latexmk: Missing input file: 'Meteodyn-1.pdf' from line 'Package asymptote Warning: file `Meteodyn-1.pdf' not found on input line 1002" and line 1002 happens to be \end{asy}. Is there something am missing? perhaps import hraph3, import grid3? I hope I can get some help. – Zilore Mumba Dec 24 '17 at 22:38
  • I am sorry that I cannot help on this. I did this long time ago. I do not even have asymptote in my new computer. – Herman Jaramillo Dec 26 '17 at 01:44
  • 1
    @Jaramillo finally I have been able to use your wonderful work. From other posts I learnt that I should have the file latexmkrc in the same directory as the .tex file I run. When I did this my file compiles. I really appreciate your work, thanks and best wishes. – Zilore Mumba Dec 26 '17 at 05:22
  • Thank you very much. I am glad that my script helped in any way. – Herman Jaramillo Jan 16 '18 at 21:45
8

1.Spherical Coordinates

I came up with this when I was trying to make my university notes more vivid:

\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}

%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}{}{} %
\tdplotdrawarc[tdplot_main_coords]{(O)}{\rvec+\drvec}{\phivec}{\phivec+\dphivec}{below, rotate=13}{$r\sin\theta\mathrm{d}\phi$} \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.5}{\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}{}{}
\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}{above right}{$r\mathrm{d}\theta$}
%
\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}

Differential Volume in Spherical Coordinates

2.Cylindrical Coordinates

With some modifications and a \newcommand for specifying coordinates in cylindrical manner the code and the figure are as follows:

\documentclass[border=3pt]{standalone}

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

%Cylindrical Coordinate \newcommand{\cylindricalcoordinate}[4]{% \coordinate (#4) at ({#1cos(#2)},{#1sin(#2)},{#3});% \coordinate (#4xy) at ({#1cos(#2)},{#1sin(#2)},0);% }

\begin{document}

%Axis Angles \tdplotsetmaincoords{70}{110}

%Macros \pgfmathsetmacro{\rvec}{5} \pgfmathsetmacro{\phivec}{45} \pgfmathsetmacro{\zvec}{4}

\pgfmathsetmacro{\drvec}{1.5} \pgfmathsetmacro{\dphivec}{20} \pgfmathsetmacro{\dzvec}{1}

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

\pgfsetlayers{background, main, foreground}

\begin{tikzpicture}[tdplot_main_coords]

%Coordinates \coordinate (O) at (0,0,0); %% \cylindricalcoordinate{\rvec}{\phivec}{\zvec}{A} \cylindricalcoordinate{\rvec}{\phivec}{(\zvec+\dzvec)}{B} \cylindricalcoordinate{\rvec}{(\phivec+\dphivec)}{\zvec}{C} \cylindricalcoordinate{\rvec}{(\phivec+\dphivec)}{(\zvec+\dzvec)}{D} %% \cylindricalcoordinate{(\rvec+\drvec)}{\phivec}{\zvec}{A'} \cylindricalcoordinate{(\rvec+\drvec)}{\phivec}{(\zvec+\dzvec)}{B'} \cylindricalcoordinate{(\rvec+\drvec)}{(\phivec+\dphivec)}{\zvec}{C'} \cylindricalcoordinate{(\rvec+\drvec)}{(\phivec+\dphivec)}{(\zvec+\dzvec)}{D'}

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

%Vectors \begin{pgfonlayer}{main} \draw[blue, thick] (O) -- (A); \draw[thick] (O) -- (Axy) node [pos=0.6, below left] {$\varpi$}; \draw (A) -- ($(A)-(Axy)$) node [left] {$z$}; \draw (B) -- ($(A)-(Axy)+(0,0,\dzvec)$) node [left] {$z+\mathrm{d}z$}; \draw (D) -- ($(A)-(Axy)+(0,0,\dzvec)$); \end{pgfonlayer} \begin{pgfonlayer}{background} \draw[dashed] (C) -- ($(A)-(Axy)$) node [left] {$z$}; \end{pgfonlayer}

%Help Lines \begin{pgfonlayer}{background} \draw (A) -- (Axy); \draw (A') -- (A'xy); \draw[thick] (Axy) -- (A'xy) node [pos=0.6, below left] {$\mathrm{d}\varpi$}; % \draw (O) -- (D'xy); \draw[dashed] (C) -- (Dxy); \draw (C') -- (C'xy); %%Arcs \tdplotdrawarc{(0,0,0)}{\rvec}{\phivec}{\phivec+\dphivec}{}{} \tdplotdrawarc{(0,0,0)}{\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$};
\end{pgfonlayer}

%Differential Volume

%%Lines \begin{pgfonlayer}{foreground} \draw[thick] (A) -- (B) -- (B') -- (A') -- cycle node [midway, below] {$\mathrm{d}\varpi$}; \draw[thick] (D) -- (D') -- (C') node [midway, right] {$\mathrm{d}z$}; \end{pgfonlayer} \begin{pgfonlayer}{background} \draw[thick, dashed] (C') -- (C) -- (D); \end{pgfonlayer}

%%Curved \begin{pgfonlayer}{background} \tdplotdrawarc[thick, dashed]{(0,0,\zvec)}{\rvec} {\phivec}{\phivec+\dphivec}{}{} \end{pgfonlayer} \begin{pgfonlayer}{foreground} \tdplotdrawarc[thick]{(0,0,\zvec+\dzvec)}{\rvec} {\phivec}{\phivec+\dphivec}{}{} \tdplotdrawarc[thick]{(0,0,\zvec+\dzvec)}{\rvec+\drvec} {\phivec}{\phivec+\dphivec}{}{} \tdplotdrawarc[thick]{(0,0,\zvec)}{\rvec+\drvec} {\phivec}{\phivec+\dphivec}{below}{$\varpi\mathrm{d}\phi$} \end{pgfonlayer}

%%Fill Color \begin{pgfonlayer}{main} %Front \fill[black, opacity=0.15] (B) to (B') to[bend right=4] (D') to (D) to[bend left=4] cycle; \fill[black, opacity=0.6] (B') to[bend right=4] (D') to (C') to[bend left=4] (A') to cycle; \fill[black, opacity=0.4] (B) to (B') to (A') to (A) to cycle; \end{pgfonlayer} \begin{pgfonlayer}{background} %Back \fill[black!50, opacity=0.5] (D) to (D') to (C') to (C) to cycle; \fill[black!50, opacity=0.5] (B) to[bend right=4] (D) to (C) to[bend left=4] (A) to cycle; \fill[black!50, opacity=0.5] (A) to (A') to[bend right=4] (C') to (C) to[bend left=4] cycle; \end{pgfonlayer}

\end{tikzpicture}

\end{document}

Differential Volume in Cylindrical Coordinates

2

I decided to do this figure from a very different prospective. Instead of including the problem here, I will point to the link where I included the code and figure. 3D spherical volumen element

0

It is important to avoid manual or sophisticated calculation of boundaries when drawing the projected cylinder. To this end, let me show a robust way with 3d-plot library (adapted from my other post):

\documentclass{standalone}
\usepackage{tikz,tikz-3dplot}
\begin{document}

\def\rotx{70} \def\rotz{110} \tdplotsetmaincoords{\rotx}{\rotz} \begin{tikzpicture}[tdplot_main_coords][scale=0.75] \tikzstyle{every node}=[font=\small] \draw[dashed,-latex] (0,0,0) -- (6,0,0) node[anchor=north east]{$x$}; \draw[dashed,-latex] (0,0,0) -- (0,6,0) node[anchor=north west]{$y$}; \draw[dashed,-latex] (0,0,0) -- (0,0,6) node[anchor=south]{$z$}; \draw thick circle (3); \draw thick circle (3); % manual edges \draw dotted -- (1.9,-2.34,4) node[midway, left]{}; \draw dotted -- (-1.9,2.35,4); % automatic edges ! \pgfcoordinate{edge1_top}{ \pgfpointcylindrical{\rotz}{3}{4} }; \pgfcoordinate{edge1_bottom}{ \pgfpointcylindrical{\rotz}{3}{0} }; \draw[thick] (edge1_top) -- (edge1_bottom); \pgfcoordinate{edge2_top}{ \pgfpointcylindrical{\rotz+180}{3}{4} }; \pgfcoordinate{edge2_bottom}{ \pgfpointcylindrical{\rotz+180}{3}{0} }; \draw[thick] (edge2_top) -- (edge2_bottom); \end{tikzpicture}

\end{document}

Which gives this effect (manual edges are dotted, made bit imprecise on purpose) enter image description here