4

I have the following code:

\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}

enter image description here

How can I put the vectors dashed when they are behind the rectangle, like the following figure? enter image description here

2 Answers 2

5

Just draw everything in order: first the dashed red lines, then the plane, then the green arrows and last the red arrows on top of the plane.

I removed all your code not relevant for this example and added a \foreach statement to avoid repetitions. I also changed the plane opacity, it looks better this way (or so I think).

Like this:

\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}

enter image description here

2

The simples way is draw your arrows in three parts: as solid line above and below plane, and as dashed (dotted) between lower border of plane and point where arrow protrude it. Fill of the plane should be semitransparent (or has some other transparency). A Simplified axample (for one arrow) is:

\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}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.