旋转一圈

旋转一圈

我正在尝试重新绘制两根光纤之间的错位情况,因此我使用下面的代码,但第一个圆柱形的末端似乎倾斜了,我该如何修复它在此处输入图片描述

\documentclass[border=10pt]{standalone}
\usepackage{xcolor}
\definecolor{lava}{rgb}{0.81, 0.06, 0.13}
\definecolor{myblue}{rgb}{0.0, 0.30, 0.60}   
\usepackage    {ifthen}
\usepackage    {tikz}
\usetikzlibrary{calc}
           

  \newcommand{\cylinder}[5]             % center, radius (y-axis), height (to the right), color, opacity
{
  \pgfmathsetmacro\r {0.5*#2}                     % radius (x-axis)
  \coordinate (C1)  at #1;                                % center, left ellipse
  \coordinate (N1)  at ($(C1)+(0,#2)$);          % north, left ellipse  
  \coordinate (NW1) at ($(C1)+(-\r,#2)$);    % north west, left ellipse
  \coordinate (W1)  at ($(C1)-(\r,0)$);            % west, left ellipse  
  \coordinate (S1)  at ($(C1)-(0,#2)$);             % south, left ellipse 
  \coordinate (P1)  at ($(W1)!0.1!(NW1)$);    % point for shading
  \coordinate (Q1)  at ($(W1)!0.2!(NW1)$);   % another point for shading
  \coordinate (C2)  at ($(C1)+(#3,0)$);           % center, right ellipse
  \coordinate (N2)  at ($(N1)+(#3,0)$);    % ...
  \coordinate (S2)  at ($(S1)+(#3,0)$);
  \coordinate (P2)  at ($(P1)+(#3,0)$);
  \ifthenelse
    {\equal{#3}{0}} % if height is 0
    {} % then do nothing
    {  % else...
      \begin{scope}
        \clip (N1) arc (90:270:\r cm and #2 cm) -- (S2) -- (S2) arc (270:90:\r cm and #2 cm) -- cycle;
        \shade[top color=white, bottom color=#4!65,fill opacity=#5] (S2) rectangle (P1);
        \shade[top color=#4!55, bottom color=white,fill opacity=#5] (N2) rectangle (Q1);
        \fill[white, opacity=#5] (P2) rectangle (Q1);
        \end{scope}
      \draw[#4] (N2) -- (N1) arc (90:270:\r cm and #2 cm) -- (S2);
    }
  \draw[#4,fill=myblue,opacity=#5] (C2) ellipse (\r cm and #2 cm);
}

\begin{document}
\begin{tikzpicture}[scale=2,line cap=round,line join=round]
  \cylinder{(0,0)}{0.1}{2}{myblue} {1};
  \cylinder{(0,0)}{0.5}   {2}{black}{0.5};
  
    \cylinder{(2.1,0.1)}{0.1}{2}{myblue} {1};
  \cylinder{(2.1,0.1)}{0.5}   {2}{black}{0.5};

  \fill(3,0) circle (0.25pt);

\end{tikzpicture}  
\end{document}

相关内容