我怎么也得不到两个坐标点和 x 轴之间的角度。最终我尝试动态连接两个具有稍微分散的路径的节点。
\begin{tikzpicture}
\usetikzlibrary{calc}
\tikzset{roundnode/.style={circle, draw=black, fill=white, thick, minimum size=0.1mm}}
\coordinate (X) at (8,4);
\coordinate (Y) at (8,1);
\def\r{3}
\begin{scope}
\coordinate (A) at (Y);
\coordinate (E) at (X);
\pgfmathanglebetweenpoints{A}{E}
\def\angleAE{\pgfmathresult}
\foreach \x in {-2, ..., 2}
\draw[red!50, ultra thick, dotted] (A) .. controls ($(A) + ({\r*cos(\angleAE + \x*5)}, {\r*sin(\angleAE + \x*5)})$) and ($(E) - ({\r*cos(\angleAE + \x*5)}, {-\r*sin(\angleAE + \x*5)})$) .. (V);
\draw (A) node[roundnode] (A) {\angleAE};
\draw (E) node[roundnode] (E) {\angleAE};
\end{scope}
\end{tikzpicture}
由于某种原因,无论 X 和 Y 坐标的位置如何,角度始终为 0.8。这当然也会弄乱曲线
为什么它不能正确计算 AE 和 x 轴之间的角度?
答案1
代码中似乎有两个问题
- tikz 还使用 pgfmath 进行自己的计算。因此,\pgfmathresult 在使用前会被覆盖。您可以使用 \edef 而不是 \def 来强制评估和保存。
\pgfmathanglebetweenpoints
需要坐标而不是节点名称。请参阅:pgfmathanglebetweenpoints 总是返回 90
因此这似乎有效:
\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\usetikzlibrary{calc}
\tikzset{roundnode/.style={circle, draw=black, fill=white, thick, minimum size=0.1mm}}
\coordinate (X) at (0,0);
\coordinate (Y) at (4,4);
\def\r{3}
\begin{scope}
\coordinate (A) at (Y);
\coordinate (E) at (X);
\pgfmathanglebetweenpoints{\pgfpointanchor{A}{center}}{\pgfpointanchor{E}{center}1}
\edef\angleAE{\pgfmathresult}
\foreach \x in {-2, ..., 2}
\draw[red!50, ultra thick, dotted] (A) .. controls ($(A) + ({\r*cos(\angleAE + \x*5)}, {\r*sin(\angleAE + \x*5)})$) and ($(E) - ({\r*cos(\angleAE + \x*5)}, {-\r*sin(\angleAE + \x*5)})$) .. (E);
\draw (A) node[roundnode] (A) {\angleAE};
\draw (E) node[roundnode] (E) {\angleAE};
\end{scope}
\end{tikzpicture}
\end{document}
顺便说一句:第三个错误是关于房子的 ;-)(V)
弧线末端有一个,没有定义。我认为这应该是(E)
。