填充由 `\node` 命令定义的多边形

填充由 `\node` 命令定义的多边形

我使用 TikZ 绘制一个多边形\node,并且我想填充该多边形。

当我使用方法,但它显然失败了,因为我没有用它\coordinate创建多边形。

有没有办法用\node而不是来填充绘制的多边形\coordinate

梅威瑟:

\documentclass[11pt]{article}
\usepackage{amsthm,tikz,subcaption}

\begin{document}
\begin{figure}[t]
        \centering
        \begin{tikzpicture}[scale=8]
        \tikzstyle{every node}=[draw, fill=white, shape=circle, minimum size=3pt,inner sep=1pt];
        \tikzstyle{every path}=[draw, line width=0.3mm, color=red];
        \node (v1) at (2.2,1) {};
        \node (v2) at (2.8,1.3) {};
        \node (v3) at (2.8,1.5) {};
        \node (v4) at (2.2,1.6) {};
        \node (v5) at (1.8,2) {};
        \node (v6) at (1.8,1.5) {};
        \node (v7) at (2.1,1.4) {};
        \draw (v1)--(v2)--(v3)--(v4)--(v5)--(v6)--(v7)--(v1);

        \fill [opacity=0.5,gray]
            (v1) \foreach \i in {2,...,7}{ -- (v\i) } -- cycle;     
        \end{tikzpicture}
        \caption{A simple polygon.}
        \label{fig:vgPoints}
    \end{figure}

\end{document}

输出:

在此处输入图片描述

答案1

只是想法:使用节点创建的点的中心,并使用绘制命令和fill=yourColor不透明度来连接它们。

\documentclass[11pt]{article}
\usepackage{amsthm,tikz,subcaption}

\begin{document}
\begin{figure}[t]
        \centering
        \begin{tikzpicture}[scale=8]
        \tikzstyle{every node}=[draw, fill=white, shape=circle, minimum size=3pt,inner sep=1pt];
        \tikzstyle{every path}=[draw, line width=0.3mm, color=red];
        \node (v1) at (2.2,1) {};
        \node (v2) at (2.8,1.3) {};
        \node (v3) at (2.8,1.5) {};
        \node (v4) at (2.2,1.6) {};
        \node (v5) at (1.8,2) {};
        \node (v6) at (1.8,1.5) {};
        \node (v7) at (2.1,1.4) {};
        \draw[opacity=0.5,fill=gray] (v1.center)--(v2.center)--(v3.center)--(v4.center)--(v5.center)--(v6.center)--(v7.center)--(v1.center);

        \fill [opacity=0.5,gray]
            (v1) \foreach \i in {2,...,7}{ -- (v\i) } -- cycle;     
        \end{tikzpicture}
        \caption{A simple polygon.}
        \label{fig:vgPoints}
    \end{figure}

\end{document}

在此处输入图片描述

相关内容