7

Is it possible to fill a region with randomly allocated dots using TikZ or PSTricks? I can't imagine somebody manually assigning dots coordinate by coordinate.

Trogdor
  • 727
  • 1
    I've seen this kind of figures using Tikz and others using PSTricks. – juanuni May 10 '16 at 04:49
  • 2
    Note that the fill pattern repeats (it is not random). This means that you could define such a pattern in TikZ. – wrtlprnft May 10 '16 at 05:23
  • 7
    random filling patterns: http://tex.stackexchange.com/questions/145969/filling-specified-area-by-random-dots-in-tikz/145975#145975 – Ignasi May 10 '16 at 06:19
  • 2
    Also: http://tex.stackexchange.com/questions/185012/how-to-have-a-real-random-pattern/185158#185158 – Ignasi May 10 '16 at 06:24

2 Answers2

7

Here's a pattern I defined by taking the coordinates from your image. One could probably use some external program such as octave or the scripting capabilities of luatex to generate new points.

Just taking purely random points doesn't really work, because those won't be distributed evenly enough.

\documentclass[tikz,margin=1cm]{standalone}
\usetikzlibrary{patterns}

\pgfmathsetmacro\sprayRadius{.2pt}
\pgfmathsetmacro\sprayPeriod{.5cm}

\pgfdeclarepatternformonly{spray}{\pgfpoint{-\sprayRadius}{-\sprayRadius}}{\pgfpoint{1cm + \sprayRadius}{1cm + \sprayRadius}}{\pgfpoint{\sprayPeriod}{\sprayPeriod}}{
    \foreach \x/\y in {2/53,6/52,11/48,23/49,20/47,32/46,41/47,47/51,56/52,46/44,4/43,16/42,33/41,41/37,49/35,55/31,37/35,44/30,28/37,24/36,17/37,7/38,0/31,8/29,18/31,28/30,37/28,30/27,46/24,51/21,24/23,12/24,4/21,18/19,12/16,31/21,38/18,26/16,46/16,56/12,52/10,45/8,51/4,37/12,35/7,24/9,14/9,2/12,8/6,15/4,27/0,34/1,40/1} {
        \pgfpathcircle{\pgfpoint{(\x + random()) / 57 * \sprayPeriod}{\sprayPeriod - (\y + random()) / 55 * \sprayPeriod}}{\sprayRadius}
    }
    %\foreach \i in {1,...,100} {
    %   \pgfpathcircle{\pgfpoint{1cm * random()}{1cm * random()}}{\sprayRadius}
    %}
    \pgfusepath{fill}
}

\begin{document}
    \begin{tikzpicture}
        \filldraw[pattern=spray] (0,0) -- (3,3) -- (2,3) -- cycle;
    \end{tikzpicture}
\end{document}

result

wrtlprnft
  • 3,859
1
\documentclass[border=4,pstricks]{standalone}
\usepackage{pst-plot}
\begin{document}

\psset{unit=2,arrowscale=2}
\begin{pspicture}(-1,-1)(5,3)
\psaxes[labels=none,ticks=none]{->}(0,0)(-0.5,-0.5)(4.5,2.5)[$x$,-90][$y$,180]
\psset{origin={1,0}}
\psRandom[dotsize=1pt,randomPoints=2000](3,3){%
    \psline[linestyle=none](0,0)(2.5;60)(3;45)(0,0)}
\psline(2.5;60)\psline(3;45)
\pscircle[fillstyle=solid,fillcolor=white](0,0){2mm}
\Large\uput{4mm}[-90](1,0){1}
\psarc[arrows=->](0,0){0.5}{0}{45}\rput(1,0){\rput(0.75;22.5){$\frac{\pi}{4}$}}
\psarc[arrows=->](0,0){1}{0}{60}\rput(1,0){\rput(1.25;30){$\frac{\pi}{3}$}}
\end{pspicture}

\end{document}

enter image description here