将 \pgfmathresult 分配给 \pgf@x/\pgf@xa 或 \pgf@xb

将 \pgfmathresult 分配给 \pgf@x/\pgf@xa 或 \pgf@xb

在为 TikZ 编写运算符时,to我遇到了以下问题,如何为\pgf@x或其亲属分配值\pgf@xa\pgf@xb\pgf@xc

我原本以为会是这样的

...
% Determine the center of the chord connecting the co-ordinates
\pgfmathparse{#1*sin(\tikz@angle@c)}%
\pgf@xc=\pgfmathresult%
\pgfmathparse{#1*cos(\tikz@angle@c)}%
\pgf@yc=\pgfmathresult%
...

可以工作,但是我尝试使用这个和许多变体\let,甚至\relax无法正确分配。

在下面的工作代码中,我用来\pgfsetmacro分配临时值\ctr@x和,\ctr@y然后分别将其重新分配给\pgf@x\pgf@y

\documentclass[tikz]{standalone}

\usetikzlibrary{calc}

\makeatletter
\tikzset{%
 arc over/.style={
  to path={%
   \pgfextra{%
    % Retrieve and assign the source co-ordinate
    \tikz@scan@one@point\pgf@process(\tikztostart)%
    \pgf@xa=\pgf@x\pgf@ya=\pgf@y%
    % Retrieve and assign the target co-ordinate
    \tikz@scan@one@point\pgf@process(\tikztotarget)%
    \pgf@xb=\pgf@x\pgf@yb=\pgf@y
    % Determine the slope of the chord connecting the co-ordinates
%    \pgfmathanglebetweenpoints{\tikztostart}{\tikztotarget}% This gave funny results
    \advance\pgf@x by-\pgf@xa%
    \advance\pgf@y by-\pgf@ya%
    \pgfmathatantwo{\the\pgf@y}{\the\pgf@x}%
%     \pgfmathparse{\pgfmathresult + pi/2}% This behaves wierdly
    \pgfmathMod@{\pgfmathresult}{360}%
    \pgfmathparse{\pgfmathresult - 90}% Perhaps one should account for sign e.g. +/- 90.
    \let\tikz@angle@c=\pgfmathresult%
    % Determine the center of the chord connecting the co-ordinates
    \pgfmathsetmacro{\ctr@x}{(\pgf@xa+\pgf@xb)/2}
    \pgfmathsetmacro{\ctr@y}{(\pgf@ya+\pgf@yb)/2}
    \pgf@xc=-\ctr@x\pgf@yc=-\ctr@y%
    % Offset the center by the assigned amount
    \pgfmathsetmacro{\ctr@x}{#1*sin(\tikz@angle@c)}
    \pgfmathsetmacro{\ctr@y}{#1*cos(\tikz@angle@c)}
    \advance\pgf@xc by\ctr@x pt%
    \advance\pgf@yc by\ctr@y pt%
    % Normalize the co-ordinates
    \advance\pgf@xa by-\pgf@xc%
    \advance\pgf@ya by-\pgf@yc%
    \advance\pgf@xb by-\pgf@xc%
    \advance\pgf@yb by-\pgf@yc%
    % Determine the start and end angles
    \pgfmathatantwo{\the\pgf@ya}{\the\pgf@xa}%
    \pgfmathMod@{\pgfmathresult}{360}%
    \let\tikz@angle@a=\pgfmathresult%
    \pgfmathatantwo{\the\pgf@yb}{\the\pgf@xb}%
    \pgfmathMod@{\pgfmathresult}{360}%
    \let\tikz@angle@b=\pgfmathresult%
    % Determine the radius of the arc to be drawn
    \pgfmathveclen{\pgf@xa}{\pgf@ya}%
    \let\tikz@radius=\pgfmathresult%
    % Define the arc that is to be drawn
    \edef\tikz@to@arc@path{ arc(\tikz@angle@a:\tikz@angle@b:\tikz@radius pt) }%\show\tikz@to@arc@path
   }%
   \tikz@to@arc@path
  }
 }
}
\makeatother

\begin{document}
\begin{tikzpicture}
\draw (9pt,0) to[arc over= 0.5em] (0,9pt)
      (9pt,0) -- (0,9pt)
      (  0,0) circle (10 pt);
\end{tikzpicture}
\end{document}

这似乎是一种不好的形式,我想知道是否有更好的方法来实现这一点。

巧合的是,如果有人愿意提供某种代码审查,我将不胜感激,我对较低级别的 TeX 内容并不完全熟悉,希望这是一个我可以从中学习的小例子。

我的代码改编自马克·维布洛斯循环空间这个问题有些相关,但没有解决我的问题。

答案1

代替

\pgfmathsetmacro{\ctr@x}{(\pgf@xa+\pgf@xb)/2}
\pgfmathsetmacro{\ctr@y}{(\pgf@ya+\pgf@yb)/2}
\pgf@xc=-\ctr@x\pgf@yc=-\ctr@y%

经过

\pgfmathsetlength\pgf@xc{-(\pgf@xa+\pgf@xb)/2}
\pgfmathsetlength\pgf@yc{-(\pgf@ya+\pgf@yb)/2}

顺便说一下,第三行\pgf@xc=-\ctr@x\pgf@yc=-\ctr@y才是痛苦的来源:它实际上分配\pgf@xc-\ctr@x\pgf@yc并打印=-\ctr@y到某个 hbox 中。

相关内容