如何标记路径上的单点?

如何标记路径上的单点?

我想将线和点都包含在一条路径中。我的问题是该\draw命令不笔触一个点,而只有一组坐标跟随该点。即\draw (0,0);没有产生可见效果。

代码:

\documentclass{standalone}
\usepackage{tikz}
\usepackage{xstring}
\usetikzlibrary{shadows}

\pgfkeys{
    /glow settings/.is family,
    /glow settings,
    layers/.store in=\opacitysteps,
    width/.store in=\glowwidth,
    color/.store in=\linecolor,
    default/.style={
        layers=20,
        width=6pt,
        color=black
    }
}
\newcommand\drawglow[2][]{%
    \pgfkeys{/glow settings,default,#1}
    \foreach \w in {1,...,\opacitysteps}{
        \pgfmathparse{10/\opacitysteps*(1-pow(\w/\opacitysteps,0.25))}
        \edef\layeropacity{\pgfmathresult}
        \pgfmathparse{\glowwidth*\w/\opacitysteps}
        \edef\layerwidth{\pgfmathresult}
        \draw [opacity=\layeropacity,line width=\layerwidth,color=\linecolor] #2;
    }
}

\begin{document}
\begin{tikzpicture}[line cap=round,line join=round]
\drawglow[width=15mm]{(0,0) -- (1,1) (2,2) (0,1) -- (1,0) (0,1.3) (2,2.1)}
\end{tikzpicture}
\end{document}

一开始我尝试去适应此解决方案获取字符串(0,0) -- (1,1) (2,2) -- ++(0,0) (0,1) -- (1,0) (0,1.3) -- ++(0,0) (2,2.3) -- ++(0,0),但没有成功。

我想获得以下结果:

在此处输入图片描述

编辑:我正在考虑 LaTeX 解决方案 - 而不是对每个对象进行单独调整。因此,相同的选项应该会修改路径和点的 stoking 样式。在我的问题中,传递给宏的参数具有统一的样式 - 点和线都是如此。所以让我们将它修复为(0,0) -- (1,1) (2,2) (0,1) -- (1,0) (0,1.3) (2,2.1)。我找到了一个类似问题,但实际上并未得到解答。

答案1

原始答案:circle[radius=.1pt]手动附加

在下面的例子中,单个坐标对应于前 n-1move-to路径操作在一连串连续的 nmove-to个圆(n >= 2)中,被逐个转换成小圆(<coordinate> circle[radius=.1pt])。

其他 power tikz 播放器可能会提供更先进、更自动化的解决方案,例如使用装饰和/或软路径操作spath3

\documentclass{standalone}
%\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shadows}

\pgfkeys{
    /glow settings/.is family,
    /glow settings,
    layers/.store in=\opacitysteps,
    width/.store in=\glowwidth,
    color/.store in=\linecolor,
    default/.style={
        layers=20,
        width=6pt,
        color=black
    }
}
\newcommand\drawglow[2][]{%
    \pgfkeys{/glow settings,default,#1}
    \foreach \w in {1,...,\opacitysteps}{
        \pgfmathparse{10/\opacitysteps*(1-pow(\w/\opacitysteps,0.25))}
        \edef\layeropacity{\pgfmathresult}
        \pgfmathparse{\glowwidth*\w/\opacitysteps}
        \edef\layerwidth{\pgfmathresult}
        \draw[opacity=\layeropacity,line width=\layerwidth,color=\linecolor] #2;
    }
}

\begin{document}
\begin{tikzpicture}[line cap=round,line join=round]
  \drawglow[width=15mm]{
    (0,0) -- (1,1)
    (2,2) circle[radius=.1pt]
    (0,1) -- (1,0)
    (0,1.3) circle[radius=.1pt]
    (2,2.1) circle[radius=.1pt]
  }
\end{tikzpicture}
\end{document}

在此处输入图片描述

更新、circle[radius=.1pt]自动插入

一些 tikz 内部被修补以允许在连续的 s 之间插入任意路径操作,包括 final和move-to之间的位置。move-to;

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning, shadows}

\usepackage{xpatch}

\pgfkeys{
    /glow settings/.is family,
    /glow settings,
    layers/.store in=\opacitysteps,
    width/.store in=\glowwidth,
    color/.store in=\linecolor,
    default/.style={
        layers=20,
        width=6pt,
        color=black
    }
}
\newcommand\drawglow[2][]{%
    \pgfkeys{/glow settings,default,#1}
    \foreach \w in {1,...,\opacitysteps}{
        \pgfmathsetmacro\layeropacity{10/\opacitysteps*(1-pow(\w/\opacitysteps,0.25))}
        \pgfmathsetmacro\layerwidth{\glowwidth*\w/\opacitysteps}
%        \pgfwarning{line width=\layerwidth}
        \draw[opacity=\layeropacity,line width=\layerwidth,color=\linecolor] #2;
    }
}


\makeatletter
\def\mytikz@text@moveto{moveto}

\xpatchcmd\tikz@handle
  % relax the match pattern from `\tikz@resetexpandcount\pgfutil@next`
  % to `\tikz@resetexpandcount`, to gain backward compatibility
  {\tikz@resetexpandcount}
  {%
    \let\mytikz@pathop@last=\mytikz@pathop@current
    \let\mytikz@pathop@current=\pgfutil@empty
    % specially handle the case when the last path operation before ";" is moveto
    \ifx\pgfutil@next\tikz@finish
      \mytikz@drawcoord@prepare
        {\let\pgfutil@next=\mytikz@drawcoord@drawfinish}%
    \fi
    \tikz@resetexpandcount
  }
  {}{\PatchFailed}

\xpatchcmd\tikz@moveto
  {\tikz@scan@one@point{\tikz@@moveto}}
  {%
    \let\mytikz@pathop@current=\mytikz@text@moveto
    \def\pgfutil@next{\tikz@scan@one@point{\tikz@@moveto}}%
    \mytikz@drawcoord@prepare
      {\let\pgfutil@next=\mytikz@drawcoord@drawbetween}%
    \pgfutil@next
  }
  {}{\PatchFailed}

\def\mytikz@drawcoord@prepare#1{%
  \ifx\mytikz@pathop@last\mytikz@text@moveto
    \unless\ifx\mytikz@drawcoord@code\pgfutil@empty
      #1%
    \fi
  \fi
}

\def\mytikz@drawcoord@drawbetween{%
  \expandafter\tikz@scan@next@command\mytikz@drawcoord@code}
\def\mytikz@drawcoord@drawfinish{%
  \expandafter\tikz@scan@next@command\mytikz@drawcoord@code;}

% user interface
\tikzset{
  draw coordinate/.store in=\mytikz@drawcoord@code,
  draw coordinate=% init to an empty value
}
\makeatother

\begin{document}
\begin{tikzpicture}[line cap=round,line join=round]
  \drawglow[width=15mm]{
    (0,0) -- (1,1) 
    (2,2)
    (0,1) -- (1,0)
    (0,1.3)
    (2,2.1)
  }
  \node[below=of current bounding box] {before};
\end{tikzpicture}

\begin{tikzpicture}[line cap=round,line join=round]
  \drawglow[width=15mm]{
    (0,0) -- (1,1)
    (2,2) circle[radius=.1pt]
    (0,1) -- (1,0)
    (0,1.3) circle[radius=.1pt]
    (2,2.1) circle[radius=.1pt]
  }
  \node[below=of current bounding box] {manual solution};
\end{tikzpicture}

\begin{tikzpicture}[
  line cap=round,
  line join=round,
  draw coordinate={circle[radius=.1pt]}
]
  \drawglow[width=15mm]{
    (0,0) -- (1,1) 
    (2,2)
    (0,1) -- (1,0)
    (0,1.3)
    (2,2.1)
  }
  \node[below=of current bounding box] {auto solution};
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容