7

I'm trying to draw a diagram in TikZ that helps visually explain an analogy I'm trying to make in a paper. Basically, I want to start with a plane that contains many random paths of different lengths, such as that below. I created that diagram by compiling the code below in LuaLaTeX, which combines two other answers on the site (at Drawing random paths and Drawing in random locations -- you will need to use the poisson disc sampling library the latter refers to).

I want to make a few tweaks to the output. Firstly, to tidy it up, I don't want the paths to be able to turn back on themselves so easily, so as to eliminate the sharp kinks and arrowheads pointing the 'wrong' direction in some of the paths. Secondly, if possible, I want some of the paths to be loosely correlated to one another: as if certain paths had a mass that gravitationally attracted the paths around them to some degree. And I want these certain paths to be drawn in a different colour to all the other paths.

Is this possible? I'd be very grateful for any help.

A plane containing many random paths of different lengths

\RequirePackage{luatex85}
\documentclass{standalone}
\usepackage{tikz}
\usepackage{poisson}
\begin{document}
\edef\mylist{\poissonpointslist{10}{5}{0.33}{20}}

\begin{tikzpicture}

\foreach \x/\y in \mylist {
    \draw[->, rounded corners=5pt] (\x,\y)
        \foreach \i in {1,...,3} {
            -- ++(rnd*180:rnd)
        };
}

\end{tikzpicture}
\end{document}
9

Something like this?

\RequirePackage{luatex85}
\documentclass{standalone}
\usepackage{tikz}
\usepackage{poisson}
\begin{document}
\edef\mylist{\poissonpointslist{10}{5}{0.33}{20}}

\begin{tikzpicture}

\foreach \x/\y in \mylist {
    \pgfmathsetmacro{\myrnd}{rnd*360}
    \pgfmathsetmacro{\mydist}{pow(\x*\x+\y*\y,1/3)/4}
    \draw[->, rounded corners=5pt] (\mydist*\x,\mydist*\y)
        \foreach \i in {1,...,3} {
            -- ++(\myrnd+rnd*60:rnd)
        };
}
\end{tikzpicture}
\end{document}

enter image description here

I first compute a main angle and then add fluctuations to it which are between -60 and +60. To make the objects cluster, I add a function that will move things that are close to the clustering point a bit closer to it, and things that are remote even a bit further away.

Here is another proposal in which the directions are correlated, and the sharp corners are gone. They appear above because some segments are super short.

\RequirePackage{luatex85}
\documentclass{standalone}
\usepackage{tikz}
\usepackage{poisson}
\begin{document}
\edef\mylist{\poissonpointslist{10}{5}{0.33}{20}}

\begin{tikzpicture}
\foreach \x/\y in \mylist {
    \pgfmathsetmacro{\myrnd}{(rnd-0.5)*60+veclen(\x,\y)*180}
    %\pgfmathsetmacro{\mydist}{pow(\x*\x+\y*\y,1/3)/4}
    \draw[->, rounded corners=3pt] (\x,\y)
        \foreach \i in {1,...,3} {
            -- ++({\myrnd+(rnd-0.5)*60}:{0.4+0.6*rnd})
        };
}
\end{tikzpicture}
\end{document}

enter image description here

5
  • This is an intriguing approach, thanks. However, I can still see lines with sharp, abrupt kinks in your output. And while you do produce a nice cluster, the behaviour I'm looking for is not so much lines getting closer together as lines nearby a certain line resembling that certain line more (roughly). I may have been unclear about this in the question. – solisoc Nov 6 '18 at 4:50
  • @solisoc I added another option. – user121799 Nov 6 '18 at 5:00
  • This is very close to the desired output. However, I can still spot kinked lines in your output: I've circled two examples at the link below. Is there any way to eradicate them entirely? i.stack.imgur.com/HTbmo.jpg – solisoc Nov 6 '18 at 5:08
  • @solisoc Better now? – user121799 Nov 6 '18 at 5:21
  • 1
    Just as an update, the veclen function appears to loosely arrange the paths in concentric arcs (this is much more evident when the path segments are shortened). I removed this undesirable behaviour by replacing veclen(\x,\y) with veclen(\x*rnd,\y*rnd). Here are two examples of the nice output I eventually obtained: one, two. Cheers! – solisoc Nov 8 '18 at 3:07

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.