Quantcast
Channel: Question and Answer » tikz-arrows
Viewing all articles
Browse latest Browse all 33

3D arrows with TikZ

$
0
0

Asymptote does give 3D arrows when drawing three dimensional figures (they even have shade!). Could we fake it with TikZ? Here’s an example, manually written, with just one arrow worked:

documentclass{scrartcl}
usepackage{tikz}
usetikzlibrary{arrows.meta}
begin{document}
begin{tikzpicture}[->,scale=2]
  draw[>={Triangle[width=3pt,length=5pt]}] (0,0,0) -- (1,0,0);
  draw[>={Triangle[width=3pt,length=5pt]}] (0,0,0) -- (0,1,0);
  draw[>={Circle[sep=-.9pt,width=3.08pt,length=2pt]Triangle[width=3pt,length=5pt]}] (0,0,0) -- (0,0,1);
end{tikzpicture}
end{document}

enter image description here

But that’s (wrongly) manually calculated by trial and error (apart from the fact that it’s not perfect, seeing how the other two axis —x and y— are oriented, it should have certain slant). It would be nice to have an interface like the other arrows

>={3D[length=⟨real length⟩,width=⟨real width of the base⟩]}

Which would then calculate from those values (and, of course, also taking into account x=⟨x vect⟩,y=⟨y vect⟩,z=⟨z vect⟩)

Circle[sep=⟨value⟩,width=⟨value⟩,length=⟨value⟩,slant=⟨value⟩]
Triangle[width=⟨value⟩,length=⟨value⟩] % And I'm not sure if `slant=⟨value⟩`
                                       % is necessary in this Triangle case

Example

Using the code from the answer (thanks to Symbol1), for instance, this code (taking the idea from another question, link in the comments)

begin{tikzpicture}[x={(0cm,1cm)},
                    y={({cos(30)*1cm},{sin(30)*-1cm})},
                    z={({cos(20)*1cm},{sin(20)*1cm})},
                    thick,
                    scale=3]
  pgfmathsetmacro{ax}{.4}
  pgfmathsetmacro{ay}{.6}
  pgfmathsetmacro{az}{-.6}
  pgfmathsetmacro{bx}{.4}
  pgfmathsetmacro{by}{-.7}
  pgfmathsetmacro{bz}{-.8}
  draw[densely dotted,thin] (ax,ay,az) -- (ax,0,az);
  draw[densely dotted,thin] (ax,ay,az) -- (0,ay,az);
  draw[densely dotted,thin] (ax,0,0) -- (ax,0,az) -- (0,0,az);
  draw[densely dotted,thin] (0,0,az) -- (0,ay,az) -- (0,ay,0);
  draw[densely dotted,thin] (bx,by,bz) -- (bx,0,bz);
  draw[densely dotted,thin] (bx,by,bz) -- (0,by,bz);
  draw[densely dotted,thin] (bx,0,0) -- (bx,0,bz) -- (0,0,bz);
  draw[densely dotted,thin] (0,0,bz) -- (0,by,bz) -- (0,by,0);
  draw[-{Cone3}] (0,0,0) -- (1,0,0) node[right] {$x$};
  draw[-{Cone3}] (0,0,0) -- (0,1,0) node[above right] {$y$};
  draw[-{Cone3}] (0,0,0) -- (0,0,1) node[below right] {$z$};
  draw[-{Cone3}] (0,0,0) -- (0,0,-1) node[above left] {$-z$};
  draw[thin] (0,0,0) -- (0,-.9,0);
  draw[-{Cone3}] (0,0,0) -- (ax,ay,az) node[below left] {source};
  draw[-{Cone3}] (0,0,0) -- (bx,by,bz) node[above right] {sim};
end{tikzpicture}

gives this figure

enter image description here


Viewing all articles
Browse latest Browse all 33

Trending Articles