![在坐标中使用 PGF 数学函数时出现语法错误](https://linux22.com/image/263158/%E5%9C%A8%E5%9D%90%E6%A0%87%E4%B8%AD%E4%BD%BF%E7%94%A8%20PGF%20%E6%95%B0%E5%AD%A6%E5%87%BD%E6%95%B0%E6%97%B6%E5%87%BA%E7%8E%B0%E8%AF%AD%E6%B3%95%E9%94%99%E8%AF%AF.png)
我希望避免过于死板地为下图设置过多的值。例如,我希望能够设置点的位置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
。对我来说,这看起来像是一个错误。