# How to draw a irregular circle(shape)?

I want to draw some irregular circle(shape) in my wireless scenario.

with a basestation in the center.

around is some irregular circle(shape).

I find something(could be used) in this web(but I feel it's size is too large)

Now my teacher want me use this circle as small as possible, but I find when I turn the radius smaller, the irregularcicle's round isn't clear so much. Is there any idea to solve this problem?

• I don't understand your latest request. What is the problem with small irregular circle? Can you show a picture? – Paul Gaborit Aug 1 '13 at 11:47

With PSTricks (just for typing exercise).

## Single

• Verbose:

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-node,pst-plot}
\pstVerb{realtime srand}
\psset{plotpoints=50}
\def\points{}

\begin{document}
\begin{pspicture}(-2,-2)(2,2)
\multido{\i=0+1}{\Xnodecount}{\xdef\points{\points (X\i)}}
\expandafter\psccurve\points
\end{pspicture}
\end{document}

• Compact:

\psnccurve is a new macro (among others) in pst-node to pass an array of nodes to \psccurve without creating the concatenating macro \points (as used in the code above). Now I can save more keystrokes.

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-node,pst-plot}
\pstVerb{realtime srand}
\psset{plotpoints=50}

\begin{document}
\begin{pspicture}(-2,-2)(2,2)
\psnccurve(0,\Xnodecount){X}
\end{pspicture}
\end{document}


## Multiple

• Verbose:

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-node,pst-plot}
\pstVerb{realtime srand}
\psset{plotpoints=50}

\begin{document}
\psLoop{10}{%
\begin{pspicture}(-2,-2)(2,2)
\def\points{}% empty for each iteration
\multido{\i=0+1}{\Xnodecount}{\xdef\points{\points (X\i)}}
\expandafter\psccurve\points
\end{pspicture}}
\end{document}

• Compact:

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-node,pst-plot}
\pstVerb{realtime srand}
\psset{plotpoints=50}

\begin{document}
\psLoop{10}{%
\begin{pspicture}(-2,-2)(2,2)
\psnccurve(0,\Xnodecount){X}
\end{pspicture}}
\end{document}


## Notes

\psnline, \psncurve, and \psnccurve are available but \psnpolygon is not.

## Attention

Note that Rand no longer produces a random real number between 0 and 0.5 inclusive. Its definition had been tacitly changed. Now it produces a random real number between 0 and 1 inclusive. It is not documented, nor announced, but it is still fun!

The code given above has not been updated yet so it will produce different output. I have no time to update it right now. Sorry for this inconvenience.

• I think you misunderstand my means. I still hope the second answer's function. But still thanks a lot!! – Felix Chang Aug 1 '13 at 17:52
• @facebook-703000782: I still don't understand your question even though I have read it multiple times. My answer was created based on the output given by other answers. – kiss my armpit Aug 1 '13 at 22:32
• The correct code is \psnccurve(0,\numexpr\Xnodecount-1){X} because Xnodecount=plotpoints-1, the first and last points have the same coordinates in a closed curve, so \psnccurve only needs the first plotpoints-2=Xnodecount-1 points. – Money Oriented Programmer Dec 11 '17 at 23:20

Using the rand function, you can write the \irregularcircle macro:

\documentclass[tikz]{standalone}

\pgfextra {\pgfmathsetmacro\len{(#1)+rand*(#2)}}
+(0:\len pt)
\foreach \a in {10,20,...,350}{
\pgfextra {\pgfmathsetmacro\len{(#1)+rand*(#2)}}
-- +(\a:\len pt)
} -- cycle
}

\begin{document}
\begin{tikzpicture}
\coordinate (c) at (0,0);
\coordinate (d) at (1,2);
\draw[blue,rounded corners=1mm] (c) \irregularcircle{1cm}{1mm};
\draw[red,rounded corners=1mm] (d) \irregularcircle{1cm}{1mm};
\end{tikzpicture}
\end{document}


Edit: a variant using let operations (from the calc library):

\documentclass[tikz]{standalone}
\usetikzlibrary{calc}
let \n1 = {(#1)+rand*(#2)} in
+(0:\n1)
\foreach \a in {10,20,...,350}{
let \n1 = {(#1)+rand*(#2)} in
-- +(\a:\n1)
} -- cycle
}

\begin{document}
\begin{tikzpicture}
\coordinate (c) at (0,0);
\coordinate (d) at (1,2);
\draw[blue,rounded corners=.5mm] (c) \irregularcircle{1cm}{1mm};
\draw[red,rounded corners=.5mm] (d) \irregularcircle{1cm}{1mm};
\end{tikzpicture}
\end{document}

• Paul, your answer is exactly I want. THX a lot!!! – Felix Chang Jul 31 '13 at 10:47
• This is very interesting. I have asked a related question and a follow-up question regarding how the definition of the macro \irregularcircle works. – Jack Mar 23 '17 at 1:32

You can use plot:

  \documentclass{scrbook}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw  plot[smooth, tension=.7] coordinates {(-3.5,0.5) (-3,2.5) (-1,3.5) (1.5,3) (4,3.5) (5,2.5) (5,0.5) (2.5,-2) (0,-0.5) (-3,-2) (-3.5,0.5)};
\end{tikzpicture}

\begin{tikzpicture}
\draw  plot[smooth, tension=.8] coordinates {(-2.5,-0.5) (-3.5,0) (-2.5,0.5) (-3,1) (-2,1.5) (-2,3) (-1,2.5) (1,4.5) (2.5,3) (3,3.5) (3.5,3) (3,2) (4.5,2) (4.5,0) (3,1) (2.5,-0.5) (3.5,-1.5) (1.5,-1) (0.5,-2) (-2,-2.5) (-1.5,-1) (-2.5,-1.5) (-2.5,-0.5)};
\end{tikzpicture}
\end{document}


Using the same points as above the curve can be drawn using the excellent hobby package:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{hobby}
\begin{document}
\begin{tikzpicture}[use Hobby shortcut,closed=true]
\draw (-3.5,0.5) .. (-3,2.5) .. (-1,3.5).. (1.5,3).. (4,3.5).. (5,2.5).. (5,0.5) ..(2.5,-2).. (0,-0.5).. (-3,-2).. (-3.5,0.5);
\end{tikzpicture}

\begin{tikzpicture}[use Hobby shortcut,closed=true]
\draw (-2.5,-0.5).. (-3.5,0).. (-2.5,0.5).. (-3,1).. (-2,1.5).. (-2,3).. (-1,2.5).. (1,4.5).. (2.5,3).. (3,3.5).. (3.5,3).. (3,2).. (4.5,2).. (4.5,0).. (3,1).. (2.5,-0.5).. (3.5,-1.5).. (1.5,-1).. (0.5,-2).. (-2,-2.5).. (-1.5,-1).. (-2.5,-1.5).. (-2.5,-0.5);
\end{tikzpicture}
\end{document}


Choose points as you wish and leave the rest to hobby. For more details, use texdoc hobby or texdoc.net.

• Nice :-) Where is the hobby library documented? – Tobi Jul 31 '13 at 10:10
• @Tobi texdoc hobby :) – cgnieder Jul 31 '13 at 10:15
• Thank. I thought TikZ libraries can’T be found via texdoc and are documented as part of the pgfmanual. Btw. hobby seems to be not yet listed in tex.stackexchange.com/q/42611/4918 – Tobi Jul 31 '13 at 10:28
• @Tobi hobby is not an official part of pgf, i.e., it is not in tex/generic/pgf/libraries/ or tex/generic/pgf/frontendlayer/tikz/libraries/ but is distributed as a package of its own (in tex/latex/hobby/). – cgnieder Jul 31 '13 at 10:37

Paul Gaborit's answer is a bit outdated. Now the rand function is rnd and there's the decorations library which can be used to make irregular circles with sharp irregularities.

For smooth irregularities the plot path specifier (used by user11232) can be used along with the rnd function too, removing the necessity to create coordinates. The below MWE presents both solutions.

## MWE

\documentclass[margin=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}

\begin{document}
\begin{tikzpicture}
\draw plot[domain=0:350, smooth cycle] (\x:2+rnd*0.5);

\draw[decoration={random steps, amplitude=2mm}, decorate] (4.5,0) circle (2);
\end{tikzpicture}
\end{document}