如何绘制连接 3D 表面的电池?

如何绘制连接 3D 表面的电池?

我需要绘制两个圆形表面,它们之间相隔一定距离,由电池连接。问题是,我很难将 3D 图与 2D 线结合起来。这是我编写的代码:

\documentclass[border=2mm,12pt,tikz]{standalone}
\usepackage{tikz-3dplot} 
\usetikzlibrary{3d,calc, backgrounds, patterns, circuits.ee.IEC}

\begin{document}
\def\R{1}
\def\hc{4}
\tdplotsetmaincoords{60}{60}
\begin{tikzpicture}[tdplot_main_coords, rotate=-90,
                    transform shape, circuit ee IEC]

    \begin{scope}[canvas is xy plane at z=-\hc/2]
        \draw (0,0) arc(\tdplotmainphi+180:\tdplotmainphi-180:\R);
    \end{scope}

    \begin{scope}[canvas is xy plane at z=\hc/2]
        \draw (0,0) arc(\tdplotmainphi+180:\tdplotmainphi-180:\R);
    \end{scope}

    \begin{scope}[canvas is xz plane at y=-\R]
        \draw (0, \hc/2) to [battery={info={$V_0$}}] (0, -\hc/2) {};
    \end{scope}

    \begin{scope}[canvas is xz plane at y=2*\R]
        \draw [|-|] (0, \hc/2) node[below] {$d(t)$} -- (0, -\hc/2);
    \end{scope}

\end{tikzpicture}
\end{document} 

这导致了这种令人憎恶的事情:

在此处输入图片描述

我不明白为什么这些线会画在那些地方,为什么距离的注释看起来如此奇怪。我想这和 3D 轴的旋转有关,但我不知道如何解决这个问题才能显示二维线。此外,标签看起来是倒置的……虽然这不是什么大问题(我只是还没想出如何解决它)。主要问题是这些线太奇怪了。

如何才能正确绘制此图?

答案1

符号坐标在访问已绘制的坐标时非常有用。此外,我认为tdplot_screen_coords对于 2d 部分使用符号坐标更简洁(但并非绝对必要)。

\documentclass[border=2mm,12pt,tikz]{standalone}
\usepackage{tikz-3dplot} 
\usetikzlibrary{circuits.ee.IEC}

\begin{document}
\tdplotsetmaincoords{60}{60}
\begin{tikzpicture}[tdplot_main_coords, rotate=-90,
                    transform shape, circuit ee IEC,
                    declare function={R=1;hc=4;}]
    \begin{scope}[canvas is xy plane at z=-hc/2]
        \draw circle[radius=R];
        \path (\tdplotmainphi+180:R) coordinate (tl)
        (\tdplotmainphi:R) coordinate (bl);
    \end{scope}
    \begin{scope}[canvas is xy plane at z=hc/2]
        \draw circle[radius=R];
        \path (\tdplotmainphi+180:R) coordinate (tr)
        (\tdplotmainphi:R) coordinate (br);
    \end{scope}
    \begin{scope}[tdplot_screen_coords]
     \draw (tl) to [battery={info={$V_0$}}] (tr);
     \draw[|-|] (bl) -- (br);
    \end{scope}
\end{tikzpicture}
\end{document} 

在此处输入图片描述

答案2

当用户没有最小工作示例时,我建议使用一个名为 Mathcha在线导出TikZ。显然这不是一个好方法,但有时,如果一些用户喜欢画画,你可以得到一些好的结果。试着相信 :-)

\documentclass[12pt]{article}
\usepackage{tikz}
\begin{document} 
\tikzset{every picture/.style={line width=0.75pt}} %set default line width to 0.75pt        
\begin{tikzpicture}[x=0.75pt,y=0.75pt,yscale=-1,xscale=1]
%uncomment if require: \path (0,300); %set diagram left start at 0, and has height of 300

%Shape: Ellipse [id:dp14965629917587342] 
\draw   (152.36,86.31) .. controls (174.91,86.37) and (192.73,118.41) .. (192.14,157.88) .. controls (191.55,197.35) and (172.79,229.3) .. (150.24,229.24) .. controls (127.68,229.18) and (109.87,197.14) .. (110.45,157.67) .. controls (111.04,118.2) and (129.8,86.25) .. (152.36,86.31) -- cycle ;
%Shape: Ellipse [id:dp6565453485959398] 
\draw   (400.64,87.69) .. controls (423.2,87.75) and (441.01,119.79) .. (440.43,159.25) .. controls (439.84,198.72) and (421.08,230.67) .. (398.52,230.61) .. controls (375.97,230.55) and (358.15,198.51) .. (358.74,159.04) .. controls (359.33,119.58) and (378.09,87.63) .. (400.64,87.69) -- cycle ;
%Straight Lines [id:da09296239339147117] 
\draw    (152.36,86.31) -- (236.5,87) ;
%Shape: Battery [id:dp027393344698937616] 
\draw  [fill={rgb, 255:red, 0; green, 0; blue, 0 }  ,fill opacity=1 ] (316.5,87.2) -- (280.5,87.11) (272.43,117.09) -- (272.57,57.09) (272.5,87.09) -- (236.5,87) (283.66,102.12) -- (280.46,102.11) -- (280.54,72.11) -- (283.74,72.12) -- (283.66,102.12) -- cycle ;
%Straight Lines [id:da5155708033133359] 
\draw    (316.5,87) -- (400.64,87.69) ;
%Straight Lines [id:da2329334269181791] 
\draw    (150.24,229.24) -- (398.52,230.61) ;
%Straight Lines [id:da4881709177101803] 
\draw    (150.74,219.24) -- (150.24,236.24) ;
%Straight Lines [id:da9330360338163168] 
\draw    (397.74,220.24) -- (397.24,237.24) ;

% Text Node
\draw (265,30.4) node [anchor=north west][inner sep=0.75pt]  [font=\Large]  {$V_{0}$};
\end{tikzpicture}
\end{document} 

您可以在这里找到输出的屏幕截图:

在此处输入图片描述

相关内容