23

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
9

With PSTricks (just for typing exercise).

Single

enter image description here

  • 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)
        \curvepnodes{0}{360}{Rand 1.50 add t PtoC}{X}
        \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)
        \curvepnodes{0}{360}{Rand 1.50 add t PtoC}{X}
        \psnccurve(0,\Xnodecount){X}
    \end{pspicture}
    \end{document}
    

Multiple

enter image description here

  • 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)
        \curvepnodes{0}{360}{Rand 1.50 add t PtoC}{X}
        \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)
        \curvepnodes{0}{360}{Rand 1.50 add t PtoC}{X}
        \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.

| improve this answer | |
  • 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. – Too Fat Man No Neck Dec 11 '17 at 23:20
34

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

enter image description here

\documentclass[tikz]{standalone}

\newcommand\irregularcircle[2]{% radius, irregularity
  \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}
\newcommand\irregularcircle[2]{% radius, irregularity
  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}
| improve this answer | |
  • 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
30

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}

enter image description here

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}

enter image description here

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

| improve this answer | |
  • 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
9

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.

enter image description here

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}
| improve this answer | |
  • I have tried this solution for ellipse and it also works. I have also tried different amplitudes but the ellipse results with spikes and I would like more rounded random variations in the ellipse shape. Do you know how to get more rounded variations? – user1993416 May 15 at 9:49
  • Did you make this ellipse with plot and used the smooth cycle option? In order to get the smooth variations in radius you need to plot the ellipse with that option. This works for me: \draw plot[domain=0:350, smooth cycle] (\x:2+rnd*0.5 and 1+rnd*0.5) (2 is the x radius while 1 is the y radius) – Guilherme Zanotelli May 15 at 13:18
  • Thank you it works form me. I did not know about smooth cycle option. – user1993416 May 15 at 17:16

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.