相互重叠的不透明箭头

相互重叠的不透明箭头

我画了一个圆,圆的上方有两个箭头形状,现在我想让箭头相互重叠,即蓝色箭头的头部应该位于红色箭头尾部的上方(事实确实如此),而红色箭头的头部应该位于蓝色箭头尾部的上方(事实并非如此)。我该如何实现这一点?

梅威瑟:

\documentclass{minimal}

\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{shapes.arrows}

\tikzset{mainstyle/.style={circle,draw,fill=gray!40,minimum size=20}}
\tikzset{spinarrow/.style={single arrow,draw,opacity=0.8,minimum height=2cm,minimum width=0.5cm,scale=0.6}}

\begin{document}

\begin{tikzpicture}
  \node[mainstyle] (a) at (0,0) {\(x\)};

  \foreach \angle in {20,40,...,360}
  {
    \draw [black,arrows={-latex[black]}] (a.\angle) -- +(\angle:1cm);
  }

  \node [spinarrow,fill=red!50,shape border rotate=90] at (-0.2,0) {\(+\)};
  \node [spinarrow,fill=blue!50,shape border rotate=270] at (0.2,0) {\(-\)};

\end{tikzpicture}
\end{document}

在此处输入图片描述

答案1

一个选项是使用transparency group并在绘制蓝色箭头后重新绘制红色箭头提示:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{shapes.arrows}

\tikzset{mainstyle/.style={circle,draw,fill=gray!40,minimum size=20}}
\tikzset{spinarrow/.style={single arrow,draw,minimum height=2cm,minimum width=0.5cm,scale=0.6}}

\begin{document}

\begin{tikzpicture}
  \node[mainstyle] (a) at (0,0) {\(x\)};

  \foreach \angle in {20,40,...,360}
  {
    \draw [black,arrows={-latex[black]}] (a.\angle) -- +(\angle:1cm);
  }

\begin{scope}[opacity=0.8,transparency group]
  \node [spinarrow,fill=red!50,shape border rotate=90] at (-0.2,0) (plus) {\(+\)};
  \node [spinarrow,fill=blue!50,shape border rotate=270] at (0.2,0) {\(-\)};
  \draw[fill=red!50] 
    (plus.after head) --
    (plus.after tip) --
    (plus.tip) --
    (plus.before tip) --
    (plus.before head);
\end{scope}
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

另一种使用较少编码的尝试,即clip再次使用重新绘制红色头部。

在此处输入图片描述

代码

\documentclass{minimal}

\usepackage{tikz}
%\usetikzlibrary{meta}
\usetikzlibrary{shapes.arrows}

\tikzset{mainstyle/.style={circle,draw,fill=gray!40,minimum size=20}}
\tikzset{spinarrow/.style={single arrow,draw,opacity=0.8,minimum height=2cm,minimum width=0.5cm,scale=0.6}}

\begin{document}

OP's solution:

\begin{tikzpicture}
  \node[mainstyle] (a) at (0,0) {\(x\)};

  \foreach \angle in {20,40,...,360}
  {
    \draw [black,arrows={-latex}] (a.\angle) -- +(\angle:1cm);
  }

  \node [spinarrow,fill=red!50,shape border rotate=90] at (-0.2,0) {\(+\)};
  \node [spinarrow,fill=blue!50,shape border rotate=270] at (0.2,0) {\(-\)};

\end{tikzpicture}

Proposed solution:

\begin{tikzpicture}
  \node[mainstyle] (a) at (0,0) {\(x\)};

  \foreach \angle in {20,40,...,360}
  {
    \draw [black,arrows={-latex}] (a.\angle) -- +(\angle:1cm);
  }

\node [spinarrow,fill=red!50,shape border rotate=90] at (-0.2,0) {\(+\)};
\node [spinarrow,fill=blue!50,shape border rotate=270] at (0.2,0) {\(-\)};
\begin{scope}          %  new code here
\clip (-0.5,0) rectangle (0.2,1);
\node [spinarrow,fill=red!50,shape border rotate=90] at (-0.2,0) {\(+\)};
\end{scope}            % new code here
\end{tikzpicture}
\end{document}

相关内容