4

Given a set of coordinates, I want to generate a bounding "blob" of this set.

The closest I have gotten is this (surprisingly simple):

\documentclass{standalone}
\usepackage{pgfplots}

\begin{document}
  \begin{tikzpicture}
    \node (p1) at (0, 0) {A};
    \node (p2) at (1, 1) {B};
    \node (p3) at (2, 0.5) {C};
    \draw plot [smooth cycle,tension=1] coordinates {(p1) (p2) (p3)};
  \end{tikzpicture}
\end{document}

Which produces:

enter image description here

This has two issues:

  • The plot goes through the nodes instead of around them. I could use modifiers like .north to fix this to some degree, but that is very tedious.
  • I have to specify the boundary coordinates in a proper order to produce the correct result.

How could I use TikZ to compute a bounding blob from a set of unordered coordinates?

1

1 Answer 1

6

There is an extremely easy way to achieve it, if you are willing to specify the order.

\documentclass{standalone}
\usepackage{pgfplots}

\pgfdeclarelayer{background}
\pgfsetlayers{background,main}
\tikzset{
    expand bubble/.style={
        preaction={draw,line width=10.4pt},
        white,fill,draw,line width=10pt,
    },
}

\begin{document}
  \begin{tikzpicture}
    \node (p1) at (0, 0) {A};
    \node (p2) at (1, 1) {B};
    \node (p3) at (2, 0.5) {C};
    \begin{pgfonlayer}{background}
      \path[expand bubble]plot [smooth cycle,tension=1] coordinates {(p1) (p2) (p3)};
    \end{pgfonlayer}
  \end{tikzpicture}
\end{document}

PS. the same trick is used here

PS2. I personally had not seen the convex hull algorithm implemented in TeX. Can you clarify what you meant by unordered coordinates?

3
  • Unordered coordinates was sort of redundant there, it mostly implied that I did not want to express the order of boundary vertices (if I were to just specify those).I will be using some simple external script to generate a convex hull in response to your observation + this to display the result, thanks!
    – Tgys
    Commented Apr 18, 2017 at 10:55
  • @tgys Nice. Because I was about to suggests a convex hull algorithm: simply draw every triangle!
    – Symbol 1
    Commented Apr 18, 2017 at 13:51
  • Through TikZ? It sounds like generating a convex hull that way would make the "blob" shape impossible.
    – Tgys
    Commented Apr 20, 2017 at 11:11

You must log in to answer this question.

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