Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Starting with a shape similar to the one generated with the following MWE :

\documentclass[11pt]{article}

\usepackage{tikz}
\usepackage{pgf}
\usepackage{pgffor}
\usepgfmodule{shapes}
\usepgfmodule{plot}
\usetikzlibrary{decorations}
\usetikzlibrary{arrows}
\usetikzlibrary{snakes}

\begin{document}
\begin{center}
\begin{tikzpicture}
\node[inner sep=0, outer sep=0] at (-2.5,0.5) (a) {};
\node[inner sep=0, outer sep=0] at (-1.5,2) (b) {};
\node[inner sep=0, outer sep=0] at (0.5,2) (c) {};
\node[inner sep=0, outer sep=0] at (2,0) (d) {};
\node[inner sep=0, outer sep=0] at (0.5,-2.5) (e) {};
\node[inner sep=0, outer sep=0] at (0,0) (y) {};

\draw [cyan, xshift=4cm] plot [smooth cycle, tension=0.95] coordinates { (a) (b) (c) (d) (e) };
\draw (a) -- (y);
\draw (c) -- (y);
\draw (e) -- (y);
\end{tikzpicture}
\begin{tikzpicture}
\end{tikzpicture}
\end{center}
\end{document}

init

Is there an easy way to automatically generate something like this scattering

That is, I want to cluster the three parts split by the black lines joining in the middle, then eventually shift them apart from one another. If was thinking of using http://www.texample.net/tikz/examples/puzzle/ but I have no idea of how I can apply that to my case, since the three parts are not the same. Thanks.

PS: how the big shape is generated can be changed, it was just to give you an idea of what I'm looking for.


Update: here is where I'm at, is there a way to make the outter path curved, and make the tangent match at each end points ?

\documentclass[11pt]{article}
\usepackage{ifthen}
\usepackage{tikz}
\usepgfmodule{shapes}
\usepgfmodule{plot}
\usetikzlibrary{decorations}
\usetikzlibrary{arrows}
\usetikzlibrary{snakes}

\begin{document}
\begin{center}
\begin{tikzpicture}
\node[inner sep=0, outer sep=0] at (-2.5,0.5) (a) {};
\node[inner sep=0, outer sep=0] at (-1.5,2) (b) {};
\node[inner sep=0, outer sep=0] at (0.5,2) (c) {};
\node[inner sep=0, outer sep=0] at (2,0) (d) {};
\node[inner sep=0, outer sep=0] at (0.5,-2.5) (e) {};
\node[inner sep=0, outer sep=0] at (0,0) (y) {};
\coordinate (Y) at (y);
\newdimen{\centerX}
\newdimen{\centerY}
\pgfextractx\centerX{\pgfpointanchor{Y}{center}}
\pgfextracty\centerY{\pgfpointanchor{Y}{center}}

\foreach \x/\y in {a/c, c/e, e/a} {
    \coordinate (A) at (\x);
    \newdimen{\tempAX}
    \newdimen{\tempAY}
    \pgfextractx\tempAX{\pgfpointanchor{A}{center}}
    \pgfextracty\tempAY{\pgfpointanchor{A}{center}}

    \coordinate (C) at (\y);
    \newdimen{\tempBX}
    \newdimen{\tempBY}
    \pgfextractx\tempBX{\pgfpointanchor{C}{center}}
    \pgfextracty\tempBY{\pgfpointanchor{C}{center}}

    \pgfmathparse{\tempAX-\centerX} \let\deltaY\pgfmathresult
    \pgfmathparse{\tempAY-\centerY} \let\deltaX\pgfmathresult

    \pgfmathparse{sqrt(\deltaX*\deltaX+\deltaY*\deltaY)} \let\r\pgfmathresult
    \pgfmathparse{\deltaX/\r} \let\NormeddeltaX\pgfmathresult
    \pgfmathparse{\deltaY/\r} \let\NormeddeltaY\pgfmathresult

    \node at ([yshift=0.15*\deltaX,xshift=0.15*\deltaY]\x)  (extra) {};
    \draw (extra) -- (y);

    \pgfmathparse{\tempBX+\tempAX-\centerX} \let\deltaY\pgfmathresult
    \pgfmathparse{\tempBY+\tempAY-\centerY} \let\deltaX\pgfmathresult

    \pgfmathparse{sqrt(\deltaX*\deltaX+\deltaY*\deltaY)} \let\r\pgfmathresult
    \pgfmathparse{\deltaX/\r} \let\NormeddeltaX\pgfmathresult
    \pgfmathparse{\deltaY/\r} \let\NormeddeltaY\pgfmathresult

    \pgfmathparse{\centerY+10.*\NormeddeltaX} \let\YR\pgfmathresult
    \pgfmathparse{\centerX+10.*\NormeddeltaY} \let\XR\pgfmathresult
%   \draw [cyan] plot coordinates { ([xshift=\XR, yshift=\YR]\x) ([xshift=\XR, yshift=\YR]y) ([xshift=\XR, yshift=\YR]\y) };
    \ifthenelse{\equal{\x}{a}}{
        \draw [cyan] plot coordinates { ([xshift=\XR, yshift=\YR]a) ([xshift=\XR, yshift=\YR]b) ([xshift=\XR, yshift=\YR]c) ([xshift=\XR, yshift=\YR]y) ([xshift=\XR, yshift=\YR]a) };
    }{
        \ifthenelse{\equal{\x}{c}}{
            \draw [cyan] plot coordinates { ([xshift=\XR, yshift=\YR]c) ([xshift=\XR, yshift=\YR]d) ([xshift=\XR, yshift=\YR]e) ([xshift=\XR, yshift=\YR]y) ([xshift=\XR, yshift=\YR]c) };}{
            \draw [cyan] plot coordinates { ([xshift=\XR, yshift=\YR]e) ([xshift=\XR, yshift=\YR]a) ([xshift=\XR, yshift=\YR]y) ([xshift=\XR, yshift=\YR]e) };
        }
    }
}
\end{tikzpicture}
\begin{tikzpicture}
\end{tikzpicture}
\end{center}
\end{document}

update


Update 2: I think I'm good for now, c.f. results below.

\documentclass[11pt]{article}
\usepackage{ifthen}
\usepackage{etex}
\usepackage{tikz}
\usepgfmodule{shapes}
\usepgfmodule{plot}
\usetikzlibrary{decorations}
\usetikzlibrary{arrows}
\usetikzlibrary{snakes}
\begin{document}
\begin{center}
\begin{tikzpicture}
\coordinate (a) at (-2.5,0.5);
\coordinate (b) at (-1.5,2);
\coordinate (c) at (0.5,2);
\coordinate (d) at (2,0);
\coordinate (f) at (1,-1.0);
\coordinate (e) at (0.5,-2.5);
\coordinate (y) at (0,0);
\newdimen{\centerX}
\newdimen{\centerY}
\pgfextractx\centerX{\pgfpointanchor{y}{center}}
\pgfextracty\centerY{\pgfpointanchor{y}{center}}

\foreach \x/\y in {a/c, c/d, d/e, e/a} {
    \newdimen{\tempAX}
    \newdimen{\tempAY}
    \pgfextractx\tempAX{\pgfpointanchor{\x}{center}}
    \pgfextracty\tempAY{\pgfpointanchor{\x}{center}}

    \newdimen{\tempBX}
    \newdimen{\tempBY}
    \pgfextractx\tempBX{\pgfpointanchor{\y}{center}}
    \pgfextracty\tempBY{\pgfpointanchor{\y}{center}}

    \pgfmathparse{\tempAX-\centerX} \let\deltaY\pgfmathresult
    \pgfmathparse{\tempAY-\centerY} \let\deltaX\pgfmathresult

    \pgfmathparse{sqrt(\deltaX*\deltaX+\deltaY*\deltaY)} \let\r\pgfmathresult
    \pgfmathparse{\deltaX/\r} \let\NormeddeltaX\pgfmathresult
    \pgfmathparse{\deltaY/\r} \let\NormeddeltaY\pgfmathresult

    \node at ([yshift=0.15*\deltaX,xshift=0.15*\deltaY]\x) (extra-\x) {};
    \draw (extra-\x) -- (y);
}
\foreach \x/\y in {a/c, c/d, d/e, e/a} {
    \newdimen{\tempAX}
    \newdimen{\tempAY}
    \pgfextractx\tempAX{\pgfpointanchor{\x}{center}}
    \pgfextracty\tempAY{\pgfpointanchor{\x}{center}}

    \newdimen{\tempBX}
    \newdimen{\tempBY}
    \pgfextractx\tempBX{\pgfpointanchor{\y}{center}}
    \pgfextracty\tempBY{\pgfpointanchor{\y}{center}}

    \pgfmathparse{\tempBX+\tempAX-\centerX} \let\deltaY\pgfmathresult
    \pgfmathparse{\tempBY+\tempAY-\centerY} \let\deltaX\pgfmathresult

    \pgfmathparse{sqrt(\deltaX*\deltaX+\deltaY*\deltaY)} \let\r\pgfmathresult
    \pgfmathparse{\deltaX/\r} \let\NormeddeltaX\pgfmathresult
    \pgfmathparse{\deltaY/\r} \let\NormeddeltaY\pgfmathresult

    \pgfmathparse{\centerY+10.*\NormeddeltaX} \let\YR\pgfmathresult
    \pgfmathparse{\centerX+10.*\NormeddeltaY} \let\XR\pgfmathresult
    \node[overlay] at ([xshift=1000.*\XR, yshift=1000.*\YR]y) (extra-\x-clip) {};
    \draw[black] plot coordinates { ([xshift=\XR, yshift=\YR]\x) ([xshift=\XR, yshift=\YR]y) ([xshift=\XR, yshift=\YR]\y) };
    \begin{scope}
    \clip[overlay] plot coordinates { ([xshift=\XR, yshift=\YR]extra-\x) ([xshift=\XR, yshift=\YR]y) ([xshift=\XR, yshift=\YR]extra-\y) (extra-\x-clip) };
    \fill[draw, fill=black!20]  plot [smooth cycle, tension=0.95] coordinates { ([xshift=\XR, yshift=\YR]a) ([xshift=\XR, yshift=\YR]b) ([xshift=\XR, yshift=\YR]c) ([xshift=\XR, yshift=\YR]d) ([xshift=\XR, yshift=\YR]f)  ([xshift=\XR, yshift=\YR]e) };
    \end{scope}
}
\end{tikzpicture}
\end{document}

final

share|improve this question
2  
If I had to do something like this, I'd create the 3 (or whatever) pieces so they match at the seams, and then shift them "outwards" from the center point. My favorite drawing tool is asymptote, where each of the "triangles" would be described by 3 paths (for the sides). Asymptote allows you to make a new path out of separate pieces, or just shift/rotate the origin and draw the figure in the modified coordinates. It is easier done than explained... –  vonbrand Jan 17 '13 at 1:53
    
I was thinking of doing that, however, I don't know how to 1) draw the path piece by piece 2) make the tangent of each pieces of the path align at the points (a), (c) and (e) easily. –  BigDawg Jan 18 '13 at 21:40
    
Lost me with that... (1) is easy, the outer boundary is just a closed curve, and the "spokes" are just curves that meet at the center; where those curves cut the boundary determines the 3 pieces; asymptote allows you to draw the piece between two points. Then you have to draw the boundary pieces and two spokes for each triangle, shifted outwards. –  vonbrand Jan 19 '13 at 0:00
    
I'm sorry, I was still thinking about TikZ, what I wanted to do is split the \draw [cyan, xshift=4cm] plot [smooth cycle, tension=0.95] coordinates { (a) (b) (c) (d) (e) }; into multiple \draw [cyan, xshift=4cm] plot [smooth, tension=0.95] coordinates { (a) (b) (c) }; and so on, but the tangents are not aligned by doing so. I'll have a look at asymptote. –  BigDawg Jan 19 '13 at 11:18
add comment

1 Answer 1

up vote 3 down vote accepted

You can use clip and shift, redrawing the same shape each time, but clipping to the relevant part.

Using transform canvas instead of a simple shift allows the use of node names while shifting.

\documentclass{minimal}
\usepackage{tikz}

\begin{document}
\begin{center}
\begin{tikzpicture}
\coordinate (a) at (-2.5,0.5);
\coordinate (b) at (-1.5,2);
\coordinate (c) at (0.5,2);
\coordinate (d) at (2,0);
\coordinate (e) at (0.5,-2.5);
\coordinate (y) at (0,0);

\begin{scope}[cyan,transform canvas={shift={(-5.4mm,8.5mm)}}]
\clip (-5, 1) -- (0,0) -- (1,4);
\fill plot [smooth cycle, tension=0.95] coordinates { (a) (b) (c) (d) (e) };
\end{scope}
\begin{scope}[cyan,transform canvas={xshift=1cm}]
\clip (1, 4) -- (0,0) -- (1,-5) -- (5,0);
\draw plot [smooth cycle, tension=0.95] coordinates { (a) (b) (c) (d) (e) };
\draw[thick] (c) -- (y) -- (e);
\end{scope}
\begin{scope}[cyan,transform canvas={shift={(-7mm,-7mm)}}]
\clip (1,-5) -- (0,0) -- (-5,1);
\draw plot [smooth cycle, tension=0.95] coordinates { (a) (b) (c) (d) (e) };
\draw[thick] (e) -- (y) -- (a);
\end{scope}
\draw (a) -- (y)  (c) -- (y)  (e) -- (y);
\end{tikzpicture}

\end{center}
\end{document}

"Scattered" figure

share|improve this answer
    
Thanks, I was lazy and didn't give clip a go, but that works quite well actually (c.f. last edit on my original post) –  BigDawg Jan 28 '13 at 11:34
    
It turns out that using transform canvas lets you shift with named nodes - I edited my answer. I'd also like to point out that rather than creating nodes with 0 inner/outer sep, you can create \coordinates, which are like nodes with no shape and no label. If this method did work well for you, would it be presumptuous to ask you to accept it? @BigDawg –  Kundor Jan 29 '13 at 17:38
    
I'll accept your answer because you cared to answer and I thank you for that. If you want a more flexible approach (I guess), you can check my code I just posted in update 2. It automatically handles your transform canvas and there is much less copy/past involved if you want to add/remove points (you just need to change two lists). Thanks again for your inputs ! –  BigDawg Jan 30 '13 at 9:49
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.