3

I want to draw some irregular convex shape with a basestation in the center.

Here is the code what I have try. But I cannot keep it convexity.

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

\begin{document}
   \begin{tikzpicture}
   \fill[blue!24] plot[domain=0:360, smooth cycle] (\x:5+rnd*4);

   \end{tikzpicture}
 \end{document}
2
  • 3
    Would drawing the convex hull of points help? tex.stackexchange.com/questions/249860/… There is no reason for random points to keep convexity
    – percusse
    Apr 8, 2018 at 12:45
  • One irregular convex shape is a polygon whose vertices are arbitrarily-spaced points on some ellipse. Not too difficult to calculate, either.
    – Davislor
    Apr 8, 2018 at 19:46

2 Answers 2

2

It is not clear what is the meaning of "random", but if you want it to look like "random" you can start with convex polygon and then smooth it.

For this you can use rounded corners, but be careful, the parameter of rounded corners should not be bigger than the half of the shortest side.

\documentclass[tikz,border=7pt]{standalone}
\begin{document}
  \begin{tikzpicture}
    \fill[blue!24, rounded corners=5mm] plot coordinates{(0,0) (1,0) (2,1) (1,3) (-1,1)}--cycle;
    \draw[red!10] plot coordinates{(0,0) (1,0) (2,1) (1,3) (-1,1)}--cycle;
  \end{tikzpicture}
 \end{document}

Another possibility is to use filldraw in combination with line join=round and custom line width.

\documentclass[tikz,border=7pt]{standalone}
\begin{document}
  \begin{tikzpicture}
    \filldraw[blue!24, line join=round, line width=1cm] plot coordinates{(0,0) (1,0) (2,1) (1,3) (-1,1)}--cycle;
    \draw[red!10] plot coordinates{(0,0) (1,0) (2,1) (1,3) (-1,1)}--cycle;
  \end{tikzpicture}
 \end{document}

enter image description here enter image description here

And if you want a random smoothing you can do this :

\documentclass[tikz,border=7pt]{standalone}
\begin{document}
  \begin{tikzpicture}[rr/.style={rounded corners=rnd*1cm}]
    \fill[blue!24] (0,0) foreach \c in {(1,0),(2,1),(1,3),(-1,1)}{[rr]--\c}[rr]--cycle;
    \draw[red!10] plot coordinates{(0,0) (1,0) (2,1) (1,3) (-1,1)}--cycle;
  \end{tikzpicture}
\end{document}

enter image description here

Note : this can be combined with a convex hull of random set of points.

2

I'm guessing a bit here, but I'm assuming that you want a smooth path through your random points. A bit like the dark blue line here perhaps?

enter image description here

This is done with Metapost, and the approach follows the comments to the OP.

\documentclass[border=5mm]{standalone}
\usepackage{luatex85}
\usepackage{luamplib}
\begin{document}
\begin{mplibcode}
beginfig(1);
    path e, r, s;
    e = fullcircle xscaled 89 yscaled 55;
    r = for i=1 upto 8: point i + 1/8 normaldeviate of e -- endfor cycle;
    s = for i=1 upto 8: point i of r {point i+1 of r - point i-1 of r} .. endfor cycle;
    draw r withcolor 3/4 white;
    draw s withcolor 2/3 blue;
endfig;
\end{mplibcode}
\end{document}
  1. Define an ellipse
  2. Define a path r that joins some random points on the ellipse with straight lines.
  3. Define a smooth path through all of these points, by ensuring that at point p the path is travelling in the direction of point p-1 towards point p+1. (This is what MP's {direction} notation does).

So long as you make sure the randomness is not too much so that the points are reasonably far apart, this should usually give you something convex.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .