# How can I shrink a path to the center?

I'm not quite sure if I formulated the title correctly.

I would like to get a result similar to the hand-drawn graph and I got the right one:

Here is the code:

\documentclass{article}
\usepackage[pdftex,active,tightpage]{preview}
\setlength\PreviewBorder{2mm}

\usepackage{xcolor}
\definecolor{pink}{HTML}{FF00FF}
\definecolor{purple}{HTML}{800080}

\usepackage{tikz}
\usetikzlibrary{arrows,positioning, calc,lindenmayersystems,decorations.pathmorphing}
\tikzstyle{vertex}=[draw,fill=black,circle,minimum size=10pt,inner sep=0pt]
\tikzstyle{selected edge} = [draw,line width=5pt,-,red!50]
\tikzstyle{markedCircle}=[line width=1pt,rotate=90,decorate,decoration={snake, segment length=2mm, amplitude=0.4mm}]

\begin{document}
\pgfdeclarelayer{background}
\pgfsetlayers{background,main}

\begin{preview}
\begin{tikzpicture}  [scale=1.2]
\node (a)[vertex] at (3,1) {a};
\node (b)[vertex] at (5.5,2.5) {b};
\node (c)[vertex] at (0.5,3) {c};
\node (d)[vertex] at (3.5,4.5) {d};
\node (e)[vertex] at (6,5.5) {e};
\node (f)[vertex] at (0,6.5) {f};
\node (g)[vertex] at (3,7) {g};
\node (h)[vertex] at (4.5,7.5) {h};
\node (i)[vertex] at (6,7.5) {i};
\node (j)[vertex] at (1.5,8.5) {j};
\node (k)[vertex] at (4,9) {k};

\foreach \from/\to in {a/b,a/b,b/d,b/e,c/f,d/f,d/g,f/g,g/h,h/e,h/i,e/i,f/j,g/j,j/k,k/h,k/i}
\draw[line width=2pt] (\from) -- (\to);

\begin{pgfonlayer}{background}
\draw (a.center) edge[selected edge] (c.center);
\draw (c.center) edge[selected edge] (f.center);
\draw (f.center) edge[selected edge] (g.center);
\draw (g.center) edge[selected edge] (j.center);
\draw (g.center) edge[selected edge] (h.center);
\draw (h.center) edge[selected edge] (k.center);
\draw (g.center) edge[selected edge] (d.center);
\draw (d.center) edge[selected edge] (b.center);
\draw (h.center) edge[selected edge] (i.center);
\draw (h.center) edge[selected edge] (e.center);
\end{pgfonlayer}

% Can those be shrinked?
\draw[color=black!80, markedCircle] (a) -- (c) -- (f) -- (g) -- (d) -- (b) -- (a);
\draw[color=purple,   markedCircle, fill=purple!10] (f) -- (g) -- (d) -- (f);
\draw[color=red,      markedCircle] (b) -- (d) -- (g) -- (h) -- (e) -- (b);
\draw[color=yellow,   markedCircle] (g) -- (h) -- (k) -- (j) -- (g);
\draw[color=pink,     markedCircle] (f) -- (g) -- (j) -- (f);
\draw[color=pink,     markedCircle] (f) -- (g) -- (j) -- (f);
\draw[color=orange,   markedCircle] (h) -- (k) -- (i) -- (h);
\draw[color=blue,     markedCircle] (h) -- (i) -- (e) -- (h);
\end{tikzpicture}
\end{preview}
\end{document}


I don't know how to make two (or three) things:

• shrink the areas to the center so that the lines don't overlap
• write the numbers in the center of the area
• (perhaps find a more random solution - one that looks more like handwriting - for drawing the lines than snake)

(The current sources are on GitHub. I will include the solution there, as soon as it is available.)

-
Well for the first one you could manually move the points so that the lines are inside, the numbers can just be nodes, and yes a hand written style can be added. Are you looking for an automated solutions for the first points? –  Peter Grill Nov 15 '12 at 8:16
adding the numbers could be done manually, but I am looking for an automated solution for moving the points inside. I thought this might be related to the problem of setting the numbers to the center, because if you keep shrinking the area, you will get to the center. –  moose Nov 15 '12 at 9:19
For the automation you should refer to Is there a way to draw TikZ lines on the “inside” or “outside” of a path?. I attempted to work on your solution, but got confused when ($(f)+(-0.1,0.5)$) move the point f to slightly below (y=-0.1), and more to the left (x=-0.5). I did see you doing anything funny with the x and y vectors... Perhaps I am just tired... –  Peter Grill Nov 15 '12 at 9:25
Looking at the picture that Alain Matthes has provided, I don't think that you want to shift each node towards the centre of the shape. I think that you want to shift each node inwards along the bisector of two lines entering the node. This will ensure that each wibbly path is a fixed distance from its true path whereas in Alain's picture then paths are different distances. –  Loop Space Nov 15 '12 at 13:19

You write the number in the center of each area with something like

  \node[text=black] at (barycentric cs:a=1,b=1 ,c=1,d=1,f=1) {\Large 1};
\node[text=magenta] at (barycentric cs:f=1,g=1 ,j=1) {\Large 2};


It's possible to automate with a macro ( vertices = arguments )

A first possibility if you want to avoid overlaping (update with your styles you need to add some arguments )

\begin{tikzpicture}  [scale=1.2]
\node (a)[vertex] at (3,1) {a};
\node (b)[vertex] at (5,2) {b};
\node (c)[vertex] at (0,3) {c};

\node[text=black] (o1) at (barycentric cs:a=1,b=1 ,c=1) {\Large 1};

\path (o1) -- coordinate[pos=.8] (a') (a.90);
\path (o1) -- coordinate[pos=.8] (b') (b.225);
\path (o1) -- coordinate[pos=.8] (c') (c.-45);

\draw[color=blue] (a) -- (b) -- (c) -- (a);
\draw[color=blue,     markedCircle] (a') -- (b') -- (c')--cycle;
\end{tikzpicture}


-

For drawing inside, I recommend using bisectors at each vertex. An inelegant way to compute these is to use the intersections and calc library. Using the calc library, we create (but don't draw) parallel lines to each of the lines in the polygon which are offset by a set amount to the inside of the polygon ("inside" is determined by the orientation in which the polygon is specified in the following - I said it was inelegant!). Then the intersections library computes the intersections of pairs of these lines and sticks a node at each intersection. These are then the inner offsets at each node. (This only works if the polygons are convex, though could be adapted for non-convex polygons.) Once these are established they can be used for drawing the lines. To get a suitable type of line, try combining decorations (see Section 21.2, decorating subpaths, for more on that).

Here's some example code. It would need a bit of polishing to make it automatic.

\documentclass{article}
%\url{http://tex.stackexchange.com/q/82821/86}
\usepackage{tikz}
\usetikzlibrary{calc,decorations.pathmorphing,intersections}

\begin{document}
\begin{tikzpicture}
\coordinate (a) at (0,0);
\coordinate (b) at (3,0);
\coordinate (c) at (5,3);
\draw (b) -- (a) -- (c) -- cycle;
\def\prev{a}
\def\this{b}
\def\offset{2mm}
\foreach \next in {c,a,b} {
\path[name path=first] ($(\prev)!\offset!90:(\this)$) --
($(\this)!\offset!-90:(\prev)$);
\path[name path=second] ($(\this)!\offset!90:(\next)$) --
($(\next)!\offset!-90:(\this)$);
\path[name intersections={of=first and second}] coordinate
(\prev-\this-\next) at (intersection-1);
\global\let\prev=\this
\global\let\this=\next
}
\draw (a-b-c) -- (c-a-b) -- (b-c-a) -- cycle;
%\draw decorate[decoration={coil,aspect=0,amplitude=2pt}] {
decorate[decoration={random steps}] { (a-b-c) -- (c-a-b) -- (b-c-a) --
cycle }};
\end{tikzpicture}
\end{document}


As written, the above produces:

If I swap the commenting on the last \draw commands, I get:

-