TikZ:当箭头位于矩形后面时,如何制作虚线?

TikZ:当箭头位于矩形后面时,如何制作虚线?

我有以下代码:

\documentclass{article}
\usepackage[free-standing-units]{siunitx}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{arrows}

\begin{document}
\pgfmathsetmacro\xx{1/sqrt(2)}
\pgfmathsetmacro\xy{1/sqrt(6)}
\pgfmathsetmacro\zz{sqrt(2/3)}
\tikzset{isometric/.style={x={(-\xx cm,-\xy cm)},y={(\xx cm,-\xy cm)},z={(0cm,\zz cm)}}}
\tikzset
{
  inner/.style={fill=gray!30},
  outer/.style={fill=gray!10},
  cogs/.style= {fill=gray!20},
  right/.style= {fill=gray!15},
  top/.style=  {fill=gray!20},
  cut/.style=  {color=red!60, densely dashed, line width=0.2mm},
}

\begin{tikzpicture}
\pgfmathsetmacro{\cubex}{6}
\pgfmathsetmacro{\cubey}{0}
\pgfmathsetmacro{\cubez}{5}
\pgfmathsetmacro{\cognum}{27}
\pgfmathsetmacro{\cog}{\cubex/((2*\cognum)+1)}
\pgfmathsetmacro{\cogsize}{\cubey/(2)}
\pgfmathsetmacro{\cogstep}{\cog*\cognum}


\draw[top] (0,0,0) -- ++(\cubex,0,0) -- ++(0,0,-\cubez) -- ++(-\cubex,0,0) -- cycle;
\draw[-stealth, red, line width=1.5mm] (1,-2,-1) --++(0,4,0);
\draw[-stealth, red, line width=1.5mm] (1,-2,-3) --++(0,4,0);
\draw[-stealth, red, line width=1.5mm] (3,-2,-1) --++(0,4,0);
\draw[-stealth, red, line width=1.5mm] (3,-2,-3) --++(0,4,0);
\draw[-stealth, red, line width=1.5mm] (5,-2,-1) --++(0,4,0);
\draw[-stealth, red, line width=1.5mm] (5,-2,-3) --++(0,4,0);
\end{tikzpicture}

\end{document}

在此处输入图片描述

当矢量位于矩形后面时,如何将其变为虚线,如下图所示? 在此处输入图片描述

答案1

只需按顺序绘制所有内容:首先是虚线红线,然后是平面,然后是绿色箭头,最后是平面顶部的红色箭头。

我删除了与本示例无关的所有代码,并添加了一条\foreach语句以避免重复。我还更改了平面不透明度,这样看起来更好(至少我是这么认为的)。

像这样:

\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{3d} % for 'canvas is...' options
\tikzset{top/.style={fill=gray!40,fill opacity=0.8}}

\begin{document}
\begin{tikzpicture}
\pgfmathsetmacro{\cubex}{6}
\pgfmathsetmacro{\cubez}{5}

% bottom part of the arrows
\foreach\x in {1,3,5} \foreach\z in {-1,-3}
  \draw[red, dash pattern=on 6pt off 2pt,line width=1.5mm] (\x,-2,\z) --++(0,2,0);
% plane
\draw[top] (0,0,0) -- ++(\cubex,0,0) -- ++(0,0,-\cubez) -- ++(-\cubex,0,0) -- cycle;
% top part of the arrows
\foreach\x in {1,3,5} \foreach\z in {-1,-3}
{
  \draw[canvas is xz plane at y=0,green!50!black,thick,->] (\x,\z) + (90:0.4) arc (90:-180:.4);
  \draw[-stealth, red, line width=1.5mm] (\x,0,\z) --++(0,2,0);
}
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

最简单的方法是将箭头分为三部分:平面上方和下方的实线,以及平面下边界和箭头突出点之间的虚线(点线)。平面的填充应为半透明(或具有其他透明度)。简化示例(针对一个箭头)如下:

\documentclass[border=3.141592]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}

\begin{document}
    \begin{tikzpicture}
\draw[red, ultra thick, dotted] (1,0) -- (1,1); % arrow below the plane
\draw[fill=gray!30, semitransparent]
    (0,0) -- ++ (4,0) -- ++ (1,2) -- ++ (-4,0) -- cycle;
\draw[red, ultra thick, -{Straight Barb[scale=0.8]}] 
    (1,1) -- ++ (0,2);
\draw[red, ultra thick]
    (1,0) -- ++ (0,-1);
    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容