使用 TikZ 散布图形

使用 TikZ 散布图形

从与以下 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}

在里面

有没有一种简单的方法可以自动生成类似的东西散射

也就是说,我想将中间连接在一起的黑线分开的三个部分聚集在一起,然后最终将它们彼此分开。如果我考虑使用http://www.texample.net/tikz/examples/puzzle/但我不知道如何将其应用到我的情况中,因为这三个部分不一样。谢谢。

附言:大形状的生成方式是可以改变的,这只是为了让您了解我在寻找什么。


更新:这是我目前的位置,有没有办法使外部路径弯曲,并使切线在每个端点匹配?

\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}

更新


更新 2:我认为我现在很好,参见下面的结果。

\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}

最终的

答案1

您可以使用剪辑和移位,每次重新绘制相同的形状,但剪辑到相关部分。

使用transform canvas而不是简单的shift允许在移动时使用节点名称。

\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}

“散乱”的身影

相关内容