5

I'm trying to show that the dependence between two nodes in a tikz picture is not smooth. I thought I would add a crazy arrow like the following: Crazy arrow

Of course my drawing is not the best, but you get the idea. I would like the arrow to have varying amplitudes and frequencies to show that the path from node A to node B is quite rough. Is there a way to do this using tikz? (or a better crazy arrow, more symmetric and periodic?)

aaragon
  • 3,041
  • see http://tex.stackexchange.com/questions/60216/how-to-create-a-squiggle-arrow-with-some-text-on-it-in-tikz – CroCo Oct 14 '15 at 17:55
  • A squiggle arrow is not that crazy, is it? – aaragon Oct 14 '15 at 17:56
  • Then define crazy. – CroCo Oct 14 '15 at 17:57
  • 1
    I did, look at the picture... – aaragon Oct 14 '15 at 17:57
  • Of course my drawing is not the best? Well, this doesn't seem a definition. – CroCo Oct 14 '15 at 17:58
  • You also said "or a better crazy arrow, more symmetric and periodic?" ... symmetric and periodic does not seem crazy to me. That seems ordered. Again, I think you should define crazy. Do you mean random amplitude and varying frequency? – Chris Chudzicki Oct 14 '15 at 17:58
  • Yeah, that would be crazy enough, random amplitude and frequency. Like an seismograph plot. – aaragon Oct 14 '15 at 18:00
  • Do you want ppl duplicate your drawing? – CroCo Oct 14 '15 at 18:03
  • Of course not, the drawing is terrible. I would like to have an arrow whose paths has varying amplitudes and frequencies. That would convey that going from A to B is not that smooth. But the arrow in the end, even chaotic, needs to look good (not like my awful drawing). – aaragon Oct 14 '15 at 18:05
  • You might want to edit your question to make it clear so that people don't need to read 20 comments. – Chris Chudzicki Oct 14 '15 at 18:11

2 Answers2

15

TikZ has a path decoration called random steps. You should be able to get sufficiently crazy paths by adjusting the segment length and amplitude values. For something periodic (and much less crazy), you can use the snake decoration, which has similar adjustable parameters. See section 24 in the TikZ documentation.

\documentclass[border=2pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}

\begin{document}
\begin{tikzpicture}
\draw[-stealth,decorate,decoration={random steps,segment length=3pt,amplitude=4pt,pre length=2pt,post length=3pt}] (0,0) -- (2,0);
\draw[-stealth,decorate,decoration={snake,amplitude=3pt,pre length=2pt,post length=3pt}] (0,-0.5) -- ++(2,0);
\end{tikzpicture}
\end{document}

enter image description here

erik
  • 12,673
  • Great! This is sort of what I'm looking for and I will definitely use it if I don't get the type of arrow I would like to have. Any ideas on how I can get something that looks more "periodic"? – aaragon Oct 14 '15 at 18:18
  • @aaragon Please see my edited answer. – erik Oct 14 '15 at 18:25
  • Your second option, though periodic, it doesn't look that crazy. Gonzalo's option is what I am looking for. But I appreciate your effort a lot erik, I wish I could give two correct answers here. – aaragon Oct 14 '15 at 18:30
  • is it perhaps possible to make the random steps only go forwards and not backwards? – intStdu Mar 07 '23 at 10:11
  • @intStdu This may answer your question https://tex.stackexchange.com/a/477495/24974 – erik Mar 08 '23 at 15:03
13

This is another option, using the sin and cos operations:

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\draw[ultra thick,cyan,->,>=latex] 
  (-2,0) -- 
  (0,0) sin (0.5,3) cos (1,0) sin (1.5,-3) cos (2,0) 
  sin (2.5,2) cos (3,0) sin (3.5,-2) cos (4,0)
  sin (4.5,4) cos (5,0) sin (5.5,-4) cos (6,0)
  sin (6.25,1.5) cos (6.5,0) sin (6.75,-1.5) cos (7,0)
  -- ++(1.5,0);
\end{tikzpicture}

\end{document}

enter image description here

A variation on the same theme, but using plot:

\documentclass[border=2pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}

\begin{document}

\begin{tikzpicture}
\begin{scope}[cyan,ultra thick]
\draw
  (-1,0) -- (0,0);
\draw[domain=0:2*pi,x=10pt] 
  (0,0) plot (\x,{sin(\x r)}) coordinate (end1);
\draw[shift={(end1)},domain=0:2*pi,x=10pt,smooth] 
  (end1) plot (\x,{2*sin(\x r)}) coordinate (end2);
\draw[shift={(end2)},domain=0:2*pi,x=10pt,smooth] 
  (end2) plot (\x,{5*sin(\x r)}) coordinate (end3);
\draw[shift={(end3)},domain=0:2*pi,x=3pt,smooth] 
  (end3) plot (\x,{0.5*sin(2*\x r)}) coordinate (end4);
\draw[->,>=latex] (end4) -- ++(1,0);  
\end{scope}
\end{tikzpicture}

\end{document}

enter image description here

Gonzalo Medina
  • 505,128