3

I'm trying to draw the following figures using TikZ, and I've found some issues :

enter image description here

Here's my attempt :

    \begin{tikzpicture}
\def\a{2} 
\def\b{1} 
\def\h{6}
\draw[->] (0,0)--(-\a,0) node[midway, above]{$r$};
\filldraw (0,0) circle(1pt); 
\filldraw (0,\h) circle(1pt); 
\draw[dashed, ->] (0,\h)--(0,\h+2) node[left] {$d\vec{S}$};
\draw[blue, thick] (\a,0)--(\a,\h) (-\a,0)--(-\a,\h);
\draw[dashed,blue, thick] (\a,0) arc [x radius=\a, y radius=\b, start angle=0, end angle=180];
\draw[blue, thick] (-\a,0) arc [x radius=\a, y radius=\b, start angle=180, end angle=360];
\draw[blue, thick]  (0,\h) ellipse (\a cm and \b cm);
\draw[->] (0,\h)--(3,\h) node[above, midway] {$\vec{E}$}; 
\draw[ultra thick] (0,0)--(0,\h) node[midway, left] {$\lambda >0$};
\end{tikzpicture}

enter image description here

And I need to draw some other figures, such as :

enter image description here

My problem is always that surface portion. Any thoughts ?

3 Answers3

5

Old notation: circle(1pt) and new notation: circle[radius=1 pt]. You make me anxious when you mix them.

\documentclass[tikz, border=1 cm]{standalone}
\begin{document}
\begin{tikzpicture}
\def\a{2} 
\def\b{1} 
\def\h{6}
\draw[->] (0,0)--(-\a,0) node[midway, above]{$r$};
\filldraw (0,0) circle[radius=1 pt]; 
\filldraw (0,\h) circle[radius=1 pt]; 
\draw[dashed, ->] (0,\h)--(0,\h+2) node[left] {$d\vec{S}$};
\draw[blue, thick] (\a,0)--(\a,\h) (-\a,0)--(-\a,\h);
\draw[dashed,blue, thick] (\a,0) arc[x radius=\a, y radius=\b, start angle=0, end angle=180];
\draw[blue, thick] (-\a,0) arc[x radius=\a, y radius=\b, start angle=180, end angle=360];
\draw[blue, thick]  (0,\h) ellipse[x radius=\a, y radius=\b];
\draw[->] (0,\h)--(3,\h) node[above, midway] {$\vec{E}$}; 
\draw[ultra thick] (0,0)--(0,\h) node[midway, left] {$\lambda >0$};
\draw[red, thick, fill=pink, opacity=0.5]
  ({\a*cos(-80)},{\b*sin(-80)+4}) arc[x radius=\a, y radius=\b, start angle=-80, end angle=-60] --
  ({\a*cos(-60)},{\b*sin(-60)+3.4}) arc[x radius=\a, y radius=\b, start angle=-60, end angle=-80] -- cycle;
\draw[red, thick, ->] ({\a*cos(-70)},{\b*sin(-70)+3.7}) -- ({2*\a*cos(-70)},{2*\b*sin(-70)+3.7}) node[above right, midway]{$\vec{E}$};
\end{tikzpicture}
\end{document}

Cylinder with small surface area

5

here is a code for the different surface and volume elements

% !TeX encoding = utf8
% !TeX spellcheck = fr

\documentclass{article} \usepackage{tikz} \usetikzlibrary{matrix,positioning,fit} \usepackage{tikz-3dplot} \usepackage[french]{babel} \usepackage[margin=1cm]{geometry}

\usepackage{subfig} \usepackage{esvect}

\begin{document}

\begin{figure}[!htb] \centering

\makeatletter \define@key{x sphericalkeys}{radius}{\def\myradius{#1}} \define@key{x sphericalkeys}{theta}{\def\mytheta{#1}} \define@key{x sphericalkeys}{phi}{\def\myphi{#1}} \tikzdeclarecoordinatesystem{x spherical}{% %%%rotation around x \setkeys{x sphericalkeys}{#1}% \pgfpointxyz{\myradiuscos(\mytheta)}{\myradiussin(\mytheta)cos(\myphi)}{\myradiussin(\mytheta)*sin(\myphi)}}

%along y axis \define@key{y sphericalkeys}{radius}{\def\myradius{#1}} \define@key{y sphericalkeys}{theta}{\def\mytheta{#1}} \define@key{y sphericalkeys}{phi}{\def\myphi{#1}} \tikzdeclarecoordinatesystem{y spherical}{% %%%rotation around x \setkeys{y sphericalkeys}{#1}% \pgfpointxyz{\myradiussin(\mytheta)cos(\myphi)}{\myradiuscos(\mytheta)}{\myradiussin(\mytheta)*sin(\myphi)}}

%along z axis \define@key{z sphericalkeys}{radius}{\def\myradius{#1}} \define@key{z sphericalkeys}{theta}{\def\mytheta{#1}} \define@key{z sphericalkeys}{phi}{\def\myphi{#1}} \tikzdeclarecoordinatesystem{z spherical}{% %%%rotation around x \setkeys{z sphericalkeys}{#1}% \pgfpointxyz{\myradiussin(\mytheta)cos(\myphi)}{\myradiussin(\mytheta)sin(\myphi)}{\myradius*cos(\mytheta)}}

\makeatother \subfloat[coordonnées cartésiennes]{ \begin{tikzpicture}[scale=1.2] \draw[fill=yellow] (0.2,0.2)coordinate(aa) rectangle (2,3)coordinate(bb); \draw[-latex] (0,0) -- (2.5,0) nodeabove{$\vv{x}$}; \draw[-latex] (0,0) coordinate(oo) -- (0,3.3) noderight{$\vv{y}$};

\draw[dashed] (oo-|aa)node[below]{$X_1$} --(aa); \draw[dashed] (oo|-aa)node[left]{$Y_1$} --(aa); \draw[dashed] (oo-|bb)nodebelow{$X_2$} --(aa-|bb); \draw[dashed] (oo|-bb)nodeleft{$Y_2$} --(aa|-bb); \node[fill=gray] (P) at (1.2,1.3){+}; \node[above=0em of P] {$\mathrm{d}x$}; \node[right=0em of P] {$\mathrm{d}y$}; \draw[dashed] (P.center) --(P.center|-oo)node[below]{$x$}; \draw[dashed] (P.center) --(oo|-P.center)node[left]{$y$};

\nodefit=(xx) (Y2) (X2){}; \node[below=0em of cadre]{$\mathrm{d} s= \mathrm{d} x \cdot \mathrm{d} y$}; \end{tikzpicture} } \hspace{1em} \subfloat[coordonnées polaires]{ \begin{tikzpicture}[scale=1.3] \draw [dashed] (0,0) coordinate(oo) -- (15:1.5cm)coordinate(aa) --(15:3cm)coordinate(bb); \draw [dashed] (0,0) coordinate(oo) -- (75:1.5cm)coordinate(aa1) --(75:3cm)coordinate(bb1); \draw[fill=yellow] (aa) arc (15:75:1.5cm) -- (bb1) arc (75:15:3cm) --(aa); \draw[-latex] (0,0) -- (3.5,0) node[above]{$\vv{x}$}; \draw[-latex] (0,0) coordinate(oo) -- (0,3) node[right]{$\vv{y}$};

\draw [-latex] (2.5,0) arc(0:15:2.5cm); \path (0,0) -- (60:.9cm)node[above right=0em] {$\theta_2$} ; \draw [-latex] (1,0) arc (0:75:1cm); \path (0,0) -- (5:2.5cm)node[right] {$\theta_1$} ; \draw[dashed] (1.5,0) node[below]{$R_1$}arc (0:15:1.5cm); \draw[dashed] (3,0) nodebelow{$R_2$}arc (0:15:3cm);

\draw[fill=gray] (35:2cm) coordinate(aa) arc (35:43:2cm)coordinate(bb) --(43:2.5) arc (43:35:2.5) -- (35:2cm) ; \draw[dashed] (0,0) -- (aa); \draw[dashed] (0,0) --(bb); \node (P) at (39:2.25){+}; \node[above right=0em of P]{$r\cdot\mathrm{d}\theta$}; \draw[dashed] (0,0) --(P.center)node[right]{$P$}; \node[above left=0em of P]{$\mathrm{d}r$}; \draw[latex-latex] (46:2cm) -- (46:2.5cm); \draw[latex-latex] (35:2.7cm) arc (35:43:2.7cm); \draw[dashed] (2.25,0) node[below]{$r$}arc (0:39:2.25cm); \draw [-latex] (1.7,0) arc (0:38:1.7cm); \path (0,0) -- (6:1.7cm)node[right] {$\theta$} ;

\nodefit=(xx) (yy) (R2){}; \node[below=0em of cadre]{$\mathrm{d} s=r\cdot \mathrm{d} \theta \cdot \mathrm{d} r$}; \end{tikzpicture} }

\subfloat[coordonnées cylindriques ]{

\begin{tikzpicture}[scale=2.6]

\begin{scope}[canvas is zx plane at y=0] %\draw (0,0) circle (1cm); \draw (0,0)coordinate(O) -- (1,0) (0,0) -- (0,1); \coordinate (Z0) at (0:0.5); \draw[fill=green!30,opacity=0.3] (0,0) -- (10:1)coordinate(A1) arc (10:110:1) coordinate(A2)-- (0,0); \foreach \aa in {10,15,20,...,110}{ \coordinate (A\aa) at (\aa:1); } \end{scope}

  \begin{scope}[canvas is zx plane at y=0.9]
 \draw[fill=green!30,opacity=0.3] (0,0) -- (10:1)coordinate(B1) arc (10:110:1) coordinate(B2)-- (0,0);
 \foreach \aa in {10,15,20,...,110}{
 \coordinate (B\aa) at (\aa:1);
 }

\end{scope}

\begin{scope}[canvas is zx plane at y=0.4]
      \foreach \aa in {30,32,34,...,42}{
 \coordinate (C\aa) at (\aa:1);
 }
 \draw[dashed](0,0)-- (0:1.5);   
 \coordinate (Z4) at (0:0.5);     
 \draw[dashed](0,0) -- (C30) coordinate[pos=2] (ff) -- (ff);    
 \draw[dashed](0,0) -- (C42) coordinate[pos=2] (ff) -- (ff);
 \draw[-latex] (0:1.5) arc (0:30:1.5)node[pos=0.5,below]{$\theta$};
  \draw[latex-latex] (30:1.6) arc (30:40:1.6)node[pos=0.5,below]{$\mathrm{d}\,\theta$};

\end{scope}

\begin{scope}[canvas is zx plane at y=0.65]
      \foreach \aa in {30,32,34,...,42}{
 \coordinate (D\aa) at (\aa:1);
 }
 \draw[dashed](0,0)coordinate(Z6) -- (D30);    
 \draw[dashed](0,0) -- (D42);
 \coordinate (Z6) at (0:0.5);

\end{scope}

\draw[-latex] (0,0,0) -- (1.1,0,0) nodeabove{$\vv{y_0}$}; \draw[-latex] (0,0,0) -- (0,1.1,0) nodeabove{$\vv{z_0}$}; \draw[-latex] (0,0,0) -- (0,0,1.1) nodeabove{$\vv{x_0}$};

\foreach \aa in {10,15,20,...,105}{ \pgfmathsetmacro{\bb}{\aa+5} \fill[fill=black!30,opacity=0.3] (A\aa) -- (A\bb) -- (B\bb) -- (B\aa) -- cycle;
}

\foreach \aa in {30,32,34,...,40}{ \pgfmathsetmacro{\bb}{\aa+2} \fill[fill=blue,opacity=0.3] (C\aa) -- (C\bb) -- (D\bb) -- (D\aa) -- cycle;
}

\draw[-latex] (Z0) -- (Z4) node[left,pos=0.5]{$z$}; \draw[latex-latex] (Z4) -- (Z6) node[left,pos=0.5]{$\mathrm{d},z$};

\nodefit=(xx) (yy) (zz){}; \node[below=0.5em of cadre]{ $\mathrm{d}s=r\cdot \mathrm{d}\theta\cdot \mathrm{d} z $}; \end{tikzpicture} } \subfloat[coordonnées sphériques]{

\tdplotsetmaincoords{60}{110}

\pgfmathsetmacro{\rvec}{.8} \pgfmathsetmacro{\thetavec}{30} \pgfmathsetmacro{\phivec}{55} \pgfmathsetmacro{\dphi}{12} \pgfmathsetmacro{\dtheta}{12} \pgfmathsetmacro{\drvec}{0.15} \pgfmathsetmacro{\Rvec}{\rvec+\drvec} \pgfmathsetmacro{\Thetavec}{\thetavec+\dtheta} \pgfmathsetmacro{\Phivec}{\phivec+\dphi}

\begin{tikzpicture}[scale=4,tdplot_main_coords]

%----------------------- \coordinate (O) at (0,0,0);

\tdplotsetcoord{P}{\rvec}{\thetavec}{\phivec} \tdplotsetcoord{P3}{\rvec}{\Thetavec}{\phivec}

\tdplotsetcoord{Q}{\rvec}{\thetavec}{\Phivec}

\tdplotsetcoord{Q3}{\rvec}{\Thetavec}{\Phivec}

\tdplotsetthetaplanecoords{0} \draw[red,fill=green!30,,tdplot_rotated_coords] (0,0) -- (\rvec,0,0) arc (0:90:\rvec) -- (0,0);

\tdplotsetthetaplanecoords{90} \draw[red,fill=green!30,,tdplot_rotated_coords] (0,0) -- (\rvec,0,0) arc (0:90:\rvec) -- (0,0); \draw (0,0) -- (30:\rvec) coordinatepos=1.2; \draw[latex-] (30:\rvec) -- (ff)--++(0,0.1)node[above]{$R$};

\draw[] (\rvec,0,0) arc (0:90:\rvec); \foreach \aa in {0,2,4,...,90}{ \coordinate (A\aa) at (\aa:\rvec); }

if you want to convince yourself that this works: \draw[blue,fill=green!30,opacity=0.5] plot[variable=\x,domain=90:0] (z spherical cs: radius = \rvec, phi = 0, theta= \x) -- plot[variable=\x,domain=0:90] (z spherical cs: radius = \rvec, phi = \x, theta= 0) -- plot[variable=\x,domain=0:90] (z spherical cs: radius = \rvec, phi = 90, theta= \x) -- plot[variable=\x,domain=90:0] (z spherical cs: radius = \rvec, phi = \x, theta= 90);

%draw figure contents %-------------------- %draw the main coordinate system axes \draw[thick,->] (0,0,0) -- (0.9,0,0) nodeabove{$\vv{x}$}; \draw[thick,->] (0,0,0) -- (0,0.9,0) nodeabove{$\vv{y}$}; \draw[thick,->] (0,0,0) -- (0,0,0.9) noderight{$\vv{z}$};

%draw a line from origin to point (P) \draw[,color=red] (O) -- (P)

; \draw[,color=red] (O) -- (P3); \draw[color=red] (O) -- (Q3);

\draw[dashed, color=red] (O) -- (Pxy); \draw[dashed, color=red] (P) -- (Pxy); % \draw[dashed, color=red] (O) -- (P3xy); \draw[dashed, color=red] (P3) -- (P3xy);

%draw a line from origin to point (Q) \draw[,color=red] (O) -- (Q); \draw[,color=red] (O) -- (Q3);

\draw[dashed, color=red] (O) -- (Qxy); \draw[dashed, color=red] (Q) -- (Qxy); % \draw[dashed, color=red] (O) -- (Q3xy); \draw[dashed, color=red] (Q3) -- (Q3xy);

\pgfmathsetmacro{\Rproj}{\Rvec*sin(\Thetavec)}

\draw[latex-latex] (P3xy) -- (Q3xy)node[below]{$\mathrm{d}\theta$};

\tdplotdrawarc[-latex]{(O)}{0.3}{0}{\phivec}{anchor=north}{$\theta$}

\tdplotsetthetaplanecoords{\phivec}

\tdplotdrawarc[tdplot_rotated_coords,-latex]{(0,0,0)}{0.5}{0}{\thetavec}{anchor=south west}{$\varphi$} \tdplotdrawarc[tdplot_rotated_coords,latex-latex]{(0,0,0)}{0.55}{\thetavec}{\Thetavec}{anchor=south west}{$\mathrm{d}\phi$}

\draw[dashed,tdplot_rotated_coords] (\rvec,0,0) arc (0:90:\rvec);

\draw[dashed] (\rvec,0,0) arc (0:90:\rvec);

\tdplotsetthetaplanecoords{\Phivec}

\draw[dashed,tdplot_rotated_coords] (\rvec,0,0) arc (0:90:\rvec); \begin{scope}[tdplot_main_coords] \draw[blue,fill=blue!30 ] plot[variable=\x,domain=\thetavec:\Thetavec] (z spherical cs: radius = \rvec, phi = \Phivec, theta= \x) -- plot[variable=\x,domain=\Phivec:\phivec] (z spherical cs: radius = \rvec, phi = \x, theta= \Thetavec) -- plot[variable=\x,domain=\Thetavec:\thetavec] (z spherical cs: radius = \rvec, phi = \phivec, theta= \x) -- plot[variable=\x,domain=\phivec:\Phivec] (z spherical cs: radius = \rvec, phi = \x, theta= \thetavec); %

\end{scope} \nodefit=(xx) (yy) (zz){}; \node[below=0em of cadre]{$\mathrm{d} s=R\cdot \sin\varphi \cdot \mathrm{d} \theta \cdot R\cdot \mathrm{d} \varphi$}; \end{tikzpicture} }

\caption{Élément de surface $\mathrm{d}s$} \label{fig:elementdesurface} \end{figure}

\begin{figure}[!htb] \makeatletter \define@key{x sphericalkeys}{radius}{\def\myradius{#1}} \define@key{x sphericalkeys}{theta}{\def\mytheta{#1}} \define@key{x sphericalkeys}{phi}{\def\myphi{#1}} \tikzdeclarecoordinatesystem{x spherical}{% %%%rotation around x \setkeys{x sphericalkeys}{#1}% \pgfpointxyz{\myradiuscos(\mytheta)}{\myradiussin(\mytheta)cos(\myphi)}{\myradiussin(\mytheta)*sin(\myphi)}}

%along y axis \define@key{y sphericalkeys}{radius}{\def\myradius{#1}} \define@key{y sphericalkeys}{theta}{\def\mytheta{#1}} \define@key{y sphericalkeys}{phi}{\def\myphi{#1}} \tikzdeclarecoordinatesystem{y spherical}{% %%%rotation around x \setkeys{y sphericalkeys}{#1}% \pgfpointxyz{\myradiussin(\mytheta)cos(\myphi)}{\myradiuscos(\mytheta)}{\myradiussin(\mytheta)*sin(\myphi)}}

%along z axis \define@key{z sphericalkeys}{radius}{\def\myradius{#1}} \define@key{z sphericalkeys}{theta}{\def\mytheta{#1}} \define@key{z sphericalkeys}{phi}{\def\myphi{#1}} \tikzdeclarecoordinatesystem{z spherical}{% %%%rotation around x \setkeys{z sphericalkeys}{#1}% \pgfpointxyz{\myradiussin(\mytheta)cos(\myphi)}{\myradiussin(\mytheta)sin(\myphi)}{\myradius*cos(\mytheta)}}

\makeatother

\tdplotsetmaincoords{60}{110}

\pgfmathsetmacro{\rvec}{.7} \pgfmathsetmacro{\thetavec}{30} \pgfmathsetmacro{\phivec}{50} \pgfmathsetmacro{\dphi}{12} \pgfmathsetmacro{\dtheta}{12} \pgfmathsetmacro{\drvec}{0.2} \pgfmathsetmacro{\Rvec}{\rvec+\drvec} \pgfmathsetmacro{\Thetavec}{\thetavec+\dtheta} \pgfmathsetmacro{\Phivec}{\phivec+\dphi}

\centering \subfloat[coordonnées cartésiennes]{ \begin{tikzpicture}[scale=0.5] \coordinate(O) at (0,0,0); \coordinate(A1) at (4,4,4); \draw[fill=red!80,opacity=0.5] ($(A1)+(0.4,0.4,0) $)coordinate(aa) --($(A1)+(0.4,-0.4,0)$)coordinate(bb) --($(A1)+(-0.4,-0.4,0)$)coordinate(cc) --($(A1)+(-0.4,0.4,0)$)coordinate(dd)-- cycle; \draw[fill=red!80,opacity=0.5] ($(A1)+(0.4,0.4,0.8) $)coordinate(aa1) --($(A1)+(0.4,-0.4,0.8)$)coordinate(bb1) --($(A1)+(-0.4,-0.4,0.8)$)coordinate(cc1)--($(A1)+(-0.4,0.4,0.8)$)coordinate(dd1)-- cycle; \foreach \aa/\bb in {cc/dd,dd/aa,aa/bb,bb/cc}{ \draw[fill=red!80,opacity=0.5] (\aa) --(\aa1) --(\bb1) --(\bb) ; }

\coordinate(A) at (6,5.8,4.8); \draw[fill=green!50,opacity=0.5] ($(A)+(2,2,0) $)coordinate(aa) --($(A)+(2,-2,0)$)coordinate(bb) --($(A)+(-2,-2,0)$)coordinate(cc) --($(A)+(-2,2,0)$)coordinate(dd)-- cycle; \draw[fill=green!80,opacity=0.5] ($(A)+(2,2,4) $)coordinate(aa1) --($(A)+(2,-2,4)$)coordinate(bb1) --($(A)+(-2,-2,4)$)coordinate(cc1)--($(A)+(-2,2,4)$)coordinate(dd1)-- cycle; \foreach \aa/\bb in {cc/dd,dd/aa,aa/bb,bb/cc}{ \draw[fill=green!50,opacity=0.5] (\aa) --(\aa1) --(\bb1) --(\bb) ; } %\draw[dashed] (0,4,0)node[above left]{$y$} -- (0,4,4)coordinate(aa) --(0,0,4); %\draw[dashed] (4,0,0) --(4,0,4) coordinate(bb)--(0,0,4)node[left]{$z$} ; %\draw[dashed] (4,0,0)node[above right]{$x$} --(4,4,0) coordinate(cc)--(0,4,0); %\draw[dashed] (aa) --(A1); %\draw[dashed] (bb) --(A1); %\draw[dashed] (cc) --(A1); \node[above =1em of A1]{$\mathrm{d}y$}; \node[left =1.8em of A1]{$\mathrm{d}z$}; \node[below right =0.5em of A1]{$\mathrm{d}x$};

\draw-latex -- (5,0,0) noderight{$\vv{y_0}$}; \draw-latex -- (0,5,0) noderight{$\vv{z_0}$}; \draw-latex -- (0,0,3) noderight{$\vv{x_0}$};

\nodefit=(xx) (yy) (zz){}; \node[below=0em of cadre]{ $\mathrm{d}v= \mathrm{d}x\cdot \mathrm{d} y \cdot\mathrm{d}z$}; \end{tikzpicture}} \hspace{1em} \subfloat[coordonnées cylindriques]{ \begin{tikzpicture}[scale=2.6]

\begin{scope}[canvas is zx plane at y=0] %\draw (0,0) circle (1cm); \draw (0,0)coordinate(O) -- (1,0) (0,0) -- (0,1); \coordinate (Z0) at (0:0.1); \draw[fill=green!30,opacity=0.3] (0,0) -- (10:1)coordinate(A1) arc (10:110:1) coordinate(A2)-- (0,0); \foreach \aa in {10,15,20,...,110}{ \coordinate (A\aa) at (\aa:1); } \end{scope}

  \begin{scope}[canvas is zx plane at y=0.9]
 %\draw (0,0) circle (1cm);
 \draw[fill=green!30,opacity=0.3] (0,0) -- (10:1)coordinate(B1) arc (10:110:1) coordinate(B2)-- (0,0);
 \foreach \aa in {10,15,20,...,110}{
 \coordinate (B\aa) at (\aa:1);
 }

\end{scope}

\begin{scope}[canvas is zx plane at y=0.4]
 %\draw (0,0) circle (1cm);
 \draw[fill=red!30,opacity=0.3] (30:0.7) -- (30:0.5)coordinate(A1) arc (30:50:0.5) -- (50:0.7) arc (50:30:0.7) -- cycle;
      \foreach \aa in {30,32,34,...,50}{
 \coordinate (C\aa) at (\aa:0.7);
 \coordinate (E\aa) at (\aa:0.5);     
 }
 \draw[dashed](0,0)-- (0:1);   
 \coordinate (Z4) at (0:0.1);     
 \draw[dashed](0,0) -- (C30) coordinate[pos=2] (ff) -- (ff);    
 \draw[dashed](0,0) -- (C50) coordinate[pos=2] (ff) -- (ff);
 \draw[-latex] (0:0.8) arc (0:30:0.8)node[pos=0.5,below]{$\theta$};
  \draw[latex-latex] (30:1) arc (30:50:1)node[pos=0.5,below]{$\mathrm{d}\,\theta$};

\end{scope}

\begin{scope}[canvas is zx plane at y=0.6]
 %\draw (0,0) circle (1cm);
 \draw[fill=red!30,opacity=0.3] (30:0.7) -- (30:0.5)coordinate(A1) arc (30:50:0.5) -- (50:0.7) arc (50:30:0.7) -- cycle;
           \foreach \aa in {30,32,34,...,50}{
 \coordinate (D\aa) at (\aa:0.7);
 \coordinate (F\aa) at (\aa:0.5);
 }
 \draw[dashed](0,0)coordinate(Z6) -- (D30) coordinate[pos=2] (ff) -- (ff);    
 \draw[dashed](0,0) -- (D50) coordinate[pos=2] (ff) -- (ff);
 \coordinate (Z6) at (0:0.1);

\end{scope}

\draw[-latex] (0,0,0) -- (1.1,0,0) nodeabove{$\vv{y_0}$}; \draw[-latex] (0,0,0) -- (0,1.1,0) nodeabove{$\vv{z_0}$}; \draw[-latex] (0,0,0) -- (0,0,1.1) nodeabove{$\vv{x_0}$};

\foreach \aa in {10,15,20,...,105}{ \pgfmathsetmacro{\bb}{\aa+5} \fill[fill=green!30,opacity=0.3] (A\aa) -- (A\bb) -- (B\bb) -- (B\aa) -- cycle;
}

\foreach \aa in {30,32,34,...,48}{ \pgfmathsetmacro{\bb}{\aa+2} \fill[fill=red!30,opacity=0.3] (C\aa) -- (C\bb) -- (D\bb) -- (D\aa) -- cycle;
\fill[fill=red!30,opacity=0.3] (E\aa) -- (E\bb) -- (F\bb) -- (F\aa) -- cycle;
} \draw[fill=red!30,opacity=0.3] (C30) -- (E30) -- (F30) -- (D30) -- cycle;

\draw[fill=red!30,opacity=0.3] (C50) -- (E50) -- (F50) -- (D50) -- cycle;

\draw[-latex] (Z0) -- (Z4) node[left,pos=0.5]{$z$}; \draw[latex-latex] (Z4) -- (Z6) node[left,pos=0.5]{$\mathrm{d},z$}; \draw [dashed] (D50) --++(0,0.15)coordinate(aa); \draw [dashed] (F50) --++(0,0.15)coordinate(bb); \draw[latex-latex] (aa) -- (bb) node[above,pos=0.5,sloped]{$\mathrm{d},r$};

\nodefit=(xx) (yy) (zz){}; \node[below=0.5em of cadre]{ $\mathrm{d}v=r\cdot \mathrm{d}\theta\cdot \mathrm{d} r \cdot\mathrm{d}z$}; \end{tikzpicture}

}\hspace{1em} \subfloat[coordonnées sphériques]{ \begin{tikzpicture}[scale=0.9] %\clip[draw] (-1.7,-2) rectangle (3.5,3.5); \begin{scope}[scale=4.2,tdplot_main_coords]

%----------------------- \coordinate (O) at (0,0,0);

\tdplotsetcoord{P}{\rvec}{\thetavec}{\phivec} \tdplotsetcoord{P1}{\Rvec}{\thetavec}{\phivec} \tdplotsetcoord{P2}{\Rvec}{\Thetavec}{\phivec} \tdplotsetcoord{P3}{\rvec}{\Thetavec}{\phivec}

\tdplotsetcoord{Q}{\rvec}{\thetavec}{\Phivec} \tdplotsetcoord{Q1}{\Rvec}{\thetavec}{\Phivec} \tdplotsetcoord{Q2}{\Rvec}{\Thetavec}{\Phivec} \tdplotsetcoord{Q3}{\rvec}{\Thetavec}{\Phivec}

\draw[thick,fill=green!30] (P) -- (P1) -- (Q1) -- (Q)--cycle; \draw[thick,fill=green!30] (P3) -- (P2) -- (Q2) -- (Q3)--cycle; %draw figure contents %-------------------- %draw the main coordinate system axes \draw[thick,->] (0,0,0) -- (0.9,0,0) nodeabove{$\vv{x_0}$}; \draw[thick,->] (0,0,0) -- (0,0.9,0) nodeabove{$\vv{y_0}$}; \draw[thick,->] (0,0,0) -- (0,0,1) noderight{$\vv{z_0}$};

%draw a line from origin to point (P) \draw[,color=red] (O) -- (P); \draw[,color=red] (O) -- (P2); \draw[color=red] (O) -- (P3);

\draw[dashed, color=red] (O) -- (Pxy); \draw[dashed, color=red] (P) -- (Pxy); % \draw[dashed, color=red] (O) -- (P2xy); \draw[dashed, color=red] (P2) -- (P2xy);

%draw a line from origin to point (Q) \draw[,color=red] (O) -- (Q); \draw[,color=red] (O) -- (Q2); \draw[color=red] (O) -- (Q3);

%\draw[,color=red] (P) -- (P1) --(P2) --(P3)--(P); %draw projection on xy plane, and a connecting line \draw[dashed, color=red] (O) -- (Qxy); \draw[dashed, color=red] (Q) -- (Qxy); % \draw[dashed, color=red] (O) -- (Q2xy); \draw[dashed, color=red] (Q2) -- (Q2xy);

\pgfmathsetmacro{\Rproj}{\Rvec*sin(\Thetavec)}

\draw[fill=gray!50] (Pxy) -- (Qxy) -- (Q2xy) -- (P2xy)--cycle;

\tdplotdrawarc[-latex]{(O)}{0.25}{0}{\phivec}{anchor=north}{$\theta$} \tdplotdrawarc[latex-latex]{(O)}{0.65}{\phivec}{\Phivec}{anchor=north}{$\mathrm{d},\theta$}

\tdplotsetthetaplanecoords{\phivec}

\tdplotdrawarc[tdplot_rotated_coords,-latex]{(0,0,0)}{0.5}{0}{\thetavec}{anchor=south west}{$\varphi$}

\tdplotdrawarc[tdplot_rotated_coords,latex-latex]{(0,0,0)}{1.2}{\thetavec}{\Thetavec}{above,rotate=-55}{$\mathrm{d},\varphi$}

\draw[dashed,tdplot_rotated_coords] (\rvec,0,0) arc (0:90:\rvec); \draw[dashed,tdplot_rotated_coords] (\Rvec,0,0) arc (0:90:\Rvec);

\draw[dashed] (\rvec,0,0) arc (0:90:\rvec); \draw[dashed] (\Rvec,0,0) arc (0:90:\Rvec);

\tdplotsetthetaplanecoords{\Phivec}

\draw[dashed,tdplot_rotated_coords] (\rvec,0,0) arc (0:90:\rvec); \draw[dashed,tdplot_rotated_coords] (\Rvec,0,0) arc (0:90:\Rvec);

\begin{scope}[tdplot_main_coords] \draw[blue,fill=red!30,opacity=0.3] plot[variable=\x,domain=\thetavec:\Thetavec] (z spherical cs: radius = \rvec, phi = \Phivec, theta= \x) -- plot[variable=\x,domain=\Phivec:\phivec] (z spherical cs: radius = \rvec, phi = \x, theta= \Thetavec) -- plot[variable=\x,domain=\Thetavec:\thetavec] (z spherical cs: radius = \rvec, phi = \phivec, theta= \x) -- plot[variable=\x,domain=\phivec:\Phivec] (z spherical cs: radius = \rvec, phi = \x, theta= \thetavec); % \draw[blue,fill=red!30] plot[variable=\x,domain=\thetavec:\Thetavec] (z spherical cs: radius = \Rvec, phi = \Phivec, theta= \x) -- plot[variable=\x,domain=\Phivec:\phivec] (z spherical cs: radius = \Rvec, phi = \x, theta= \Thetavec) -- plot[variable=\x,domain=\Thetavec:\thetavec] (z spherical cs: radius = \Rvec, phi = \phivec, theta= \x) -- plot[variable=\x,domain=\phivec:\Phivec] (z spherical cs: radius = \Rvec, phi = \x, theta= \thetavec);

\end{scope}

\tdplotsetthetaplanecoords{\phivec}

%\tdplotdrawarc[tdplot_rotated_coords]{(0,0,0)}{0.5}{0}{\thetavec}{anchor=south west}{$\theta$}

\draw[dashed,tdplot_rotated_coords] (\rvec,0,0) arc (0:90:\rvec); \draw[dashed,tdplot_rotated_coords] (\Rvec,0,0) arc (0:90:\Rvec); \draw[tdplot_rotated_coords,black,fill=blue!30,opacity=0.3] (P) -- (P1) arc (\thetavec:\Thetavec:\Rvec) -- (P3) arc (\Thetavec:\thetavec:\rvec);

\draw[dashed] (\rvec,0,0) arc (0:90:\rvec); \draw[dashed] (\Rvec,0,0) arc (0:90:\Rvec);

\draw[latex-latex] (60:\rvec) -- (60:\Rvec) node[right]{$\mathrm{d},r$}; \draw[latex-latex] (75:0) --node[sloped,above,pos=0.8]{$r$} (75:\rvec) ;

\tdplotsetthetaplanecoords{\Phivec}

\draw[dashed,tdplot_rotated_coords] (\rvec,0,0) arc (0:90:\rvec); \draw[dashed,tdplot_rotated_coords] (\Rvec,0,0) arc (0:90:\Rvec); \draw[tdplot_rotated_coords,black,fill=blue!30,opacity=0.3] (Q) -- (Q1) arc (\thetavec:\Thetavec:\Rvec) -- (Q3) arc (\Thetavec:\thetavec:\rvec); \end{scope}

\nodefit=(xx) (yy) (zz){}; \node[below=1em of cadre]{$\mathrm{d}v=r\cdot \sin \varphi \cdot\mathrm{d}\theta\cdot r \cdot\mathrm{d}\phi \cdot\mathrm{d}r$.}; \end{tikzpicture}

}

\caption{Élément de volume } \label{fig:elementdevolume} \end{figure} \end{document}

enter image description here

rpapa
  • 12,350
5

You can try this code

\documentclass[tikz,border=3mm]{standalone}
\usepackage{tikz-3dplot}
\usepackage{esvect}
\usetikzlibrary{calc,3dtools}% https://github.com/marmotghost/tikz-3dtools
\begin{document}
    \begin{tikzpicture}[3d/install view={phi=110,theta=70},line join = round, line cap = round,declare function={R=2;h=4;myalgle=30;myphi = 50;}]
\draw[3d/hidden]
(0,0,0) -- (R,0,0)
 (0,0,0) -- (0,R,0)
 (0,0,0) -- (0,0,h);
\draw[3d/visible,-latex] (R,0,0) -- (R+ 2,0,0) node[below]{$x$};
\draw[3d/visible,-latex] (0,R,0) -- (0,R+1.5,0) node[below]{$y$};
\draw[3d/visible,-latex] (0,0,h) -- (0,0,h + 2) node[right]{$z$};
\pic{3d/frustum={R=R,r=R,h=h}};
\path ({R*cos(myalgle)},{R*sin(myalgle)},h-2) coordinate (A)
({R*cos(myalgle+ myphi)},{R*sin(myalgle+ myphi)},h-2) coordinate (B)
({R*cos(myalgle)},{R*sin(myalgle)},h-1) coordinate (C)
({R*cos(myalgle+ myphi)},{R*sin(myalgle+ myphi)},h-1) coordinate (D)
;
\draw[red, fill=pink, opacity=0.5] (A) arc[start angle=myalgle,end angle=myalgle +myphi ,radius=R]-- (D) arc[start angle=myalgle +myphi,end angle=myalgle,radius=R] -- cycle;

\pgfmathsetmacro{\mybarycenter}{barycenter("(A),(B),(C),(D)")} \path (\mybarycenter) coordinate (G); \path[overlay,3d coordinate={(N)=(G)-(A)x(G)-(B)},3d coordinate={(H)=(G)+ (N)}]; \pgfmathsetmacro{\absn}{sqrt(TD("(H)o(H)"))}; \path[overlay,3d coordinate={(myn)=(H)/\absn}]; \draw[-latex,red] (G) -- (myn) node[above]{$\vv{E}$}; \draw[-latex,green] (0,0,0) -- (N); \end{tikzpicture} \end{document}

enter image description here

Or

\documentclass[tikz,border=3mm]{standalone}
\usepackage{tikz-3dplot}
\usepackage{esvect}
\usetikzlibrary{calc,3dtools}% https://github.com/marmotghost/tikz-3dtools
\begin{document}
    \begin{tikzpicture}[3d/install view={phi=110,theta=70},line join = round, line cap = round,declare function={R=2;h=4;myalgle=0;myphi = 90;}]
\draw[3d/hidden]
(0,0,0) -- (R,0,0)
 (0,0,0) -- (0,R,0)
 (0,0,0) -- (0,0,h);
\draw[3d/visible,-latex] (R,0,0) -- (R+ 2,0,0) node[below]{$x$};
\draw[3d/visible,-latex] (0,R,0) -- (0,R+1.5,0) node[below]{$y$};
\draw[3d/visible,-latex] (0,0,h) -- (0,0,h + 2) node[right]{$z$};
\pic{3d/frustum={R=R,r=R,h=h}};
\path ({R*cos(myalgle)},{R*sin(myalgle)},h) coordinate (A)
({R*cos(myalgle+ myphi)},{R*sin(myalgle+ myphi)},h) coordinate (B)
({R*cos(myalgle)},{R*sin(myalgle)},0) coordinate (C)
({R*cos(myalgle+ myphi)},{R*sin(myalgle+ myphi)},0) coordinate (D)
;
\draw[red, fill=pink, opacity=0.5] (A) arc[start angle=myalgle,end angle=myalgle +myphi ,radius=R]-- (D) arc[start angle=myalgle +myphi,end angle=myalgle,radius=R] -- cycle;

\pgfmathsetmacro{\mybarycenter}{barycenter("(A),(B),(C),(D)")} \path (\mybarycenter) coordinate (G); \path[overlay,3d coordinate={(N)=(G)-(A)x(B)-(G)},3d coordinate={(H)=(G)+ (N)}]; \pgfmathsetmacro{\absn}{sqrt(TD("(H)o(H)"))}; \path[overlay,3d coordinate={(myn)=(H)/\absn}]; \draw[-latex,red] (G) -- (myn) node[above]{$\vv{E}$}; %\draw[-latex,green] (0,0,0) -- (N); \end{tikzpicture} \end{document}

enter image description here