在坐标中使用 PGF 数学函数时出现语法错误

在坐标中使用 PGF 数学函数时出现语法错误

我希望避免过于死板地为下图设置过多的值。例如,我希望能够设置点的位置A,并且此后能够检索从其他点到A\path ... let ... in ...结构的距离。

这是我的 MWE:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\pagestyle{empty}
\setlength{\parindent}{0pt}
\begin{document}

\begin{tikzpicture}[x=0.5cm,y=0.5cm]
    \draw[help lines,blue!20,step=1] (0,0) grid (12,12);

    \draw[fill]  (0,0) coordinate [label=180:Z] (Z) circle (2pt);           %% center of the picture
    \draw[fill]  (5,5) coordinate [label=135:Q] (Q) circle (2pt);           %% center of the circle
    \draw[fill]  (Q) -- +(  0:7)   coordinate [label=0:A] (A) circle (2pt); %% first point on the circle
    %% drawing the circle
    \draw[blue]  (A) 
                 let \p1 = ($ (A) - (Q) $) in
                 arc(0:360:{veclen(\x1,\y1)});

    %% these lines do work, but I don't want to explicitly state the radius as "7"
    %% BEGIN <remove these lines>
    \draw  [line width=0.4pt,red]           
           (Q) -- +(320:7) 
           coordinate (B) circle (2pt);
    %% END <remove these lines>

    %% after removing the above lines, uncomment the following lines to get error.
    %% no matter how I try to tweak these line, I can't get it to work
    %% \draw [line width=0.4pt,red]
    %%       let \p1 = ($(A) - (Q)$) in
    %%       (Q) -- +(320:{veclen(\x1,\y1)}) 
    %%       coordinate (B) circle (2pt);

    \draw[purple,line width=0.4pt] 
          (B) -- +($  (0,0) ! 2em ! 0 : ($(B)-(Q)$)  $)  
          coordinate [label=center:B] (Bl) circle (6pt);

    \draw[blue]   
          ($ (B) ! 0.45 ! (Q) $) 
          coordinate (tC) circle (2pt);

    \draw[line width=1.5em,->]
          (tC) 
          let \p1 = ($(tC) - (Q)$) in
              arc ({atan2(\x1,\y1)}:{atan2(\x1,\y1)+90}:{veclen(\x1,\y1)});

\end{tikzpicture}

\end{document}

在此处输入图片描述

删除我标记为要删除的行并取消注释以下代码块后,出现以下错误:

! Package tikz Error: Giving up on this path. Did you forget a semicolon?.

See the tikz package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.30               (Q) -- +(320:{veclen(\x1,\y1)})

? 

如果我不清楚要删除什么以及要取消注释什么,这里是产生此错误的 MWE。

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\pagestyle{empty}
\setlength{\parindent}{0pt}
\begin{document}

\begin{tikzpicture}[x=0.5cm,y=0.5cm]
    \draw[help lines,blue!20,step=1] (0,0) grid (12,12);

    \draw[fill]  (0,0) coordinate [label=180:Z] (Z) circle (2pt);           %% center of the picture
    \draw[fill]  (5,5) coordinate [label=135:Q] (Q) circle (2pt);           %% center of the circle
    \draw[fill]  (Q) -- +(  0:7)   coordinate [label=0:A] (A) circle (2pt); %% first point on the circle
    %% drawing the circle
    \draw[blue]  (A) 
                 let \p1 = ($ (A) - (Q) $) in
                 arc(0:360:{veclen(\x1,\y1)});

    %% PROBLEMATIC LINES
    \draw [line width=0.4pt,red]
          let \p1 = ($(A) - (Q)$) in
          (Q) -- +(320:{veclen(\x1,\y1)}) 
          coordinate (B) circle (2pt);

    \draw[purple,line width=0.4pt] 
          (B) -- +($  (0,0) ! 2em ! 0 : ($(B)-(Q)$)  $)  
          coordinate [label=center:B] (Bl) circle (6pt);

    \draw[blue]   
          ($ (B) ! 0.45 ! (Q) $) 
          coordinate (tC) circle (2pt);

    \draw[line width=1.5em,->]
          (tC) 
          let \p1 = ($(tC) - (Q)$) in
              arc ({atan2(\x1,\y1)}:{atan2(\x1,\y1)+90}:{veclen(\x1,\y1)});

\end{tikzpicture}

\end{document}

为什么只有这一部分\path ... let ... in失败了?

顺便

我不喜欢箭头的方向。最近,这个网站上有一篇文章解释了如何纠正这种箭头。但无论我搜索多少次,似乎都找不到它。有人知道链接吗?

答案1

您可以使用

\draw [line width=0.4pt,red]
      let \p1 = ($(A) - (Q)$) in
      (Q) -- ([shift=(320:{veclen(\x1,\y1)})] Q) 
      coordinate (B) circle (2pt);

或者

\draw [line width=0.4pt,red]
      let \p1 = ($(A) - (Q)$), \n1={veclen(\x1,\y1)} in
      (Q) -- ++(320:\n1)
      coordinate (B) circle (2pt);

我得到了你的例子

\draw [line width=0.4pt,red]
      let \p1 = ($(A) - (Q)$) in
      (Q) -- ++(320:({veclen(\x1,\y1)})
      coordinate (B) circle (2pt);

请注意,有两个左括号(,但只有一个右)括号(不包括来自的括号)veclen。对我来说,这看起来像是一个错误。

相关内容