我想画一条线,与给定的线具有相同的角度(计算)。这是我尝试做的
\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{decorations.markings,calc,angles,quotes}
\begin{document}
\begin{tikzpicture}
\coordinate (O) at (-1,0);
\coordinate (P) at ($ (O) + (0,1) $);
\coordinate (A) at (-4,0);
\draw ($ (A) + (-0.5,0) $) -- ($ (O) + (0.5,0) $);
\draw [->, ultra thick] (O) -- (P);
\draw [thick, dashed] (A) -- (P);
\begin{scope}[shift=(A)]
\draw [thick] let \p=(P), \n={atan2(\y,\x)} in (P) -- (\n:3);
\end{scope}
\end{tikzpicture}
\end{document}
但它给了我这个消息:“无法解析此坐标”(问题出在“\draw ... let ... in ...”行。我做错了什么?我想要做的是这样的:
我无法使用“缩短”作为 \draw 命令的选项,因为线条有两种不同的样式(例如,一个是虚线,另一个是粗线)。
答案1
欢迎光临!喜欢吗?
\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\coordinate (O) at (-1,0);
\coordinate (P) at ($ (O) + (0,1) $);
\coordinate (A) at (-4,0);
\draw ($ (A) + (-0.5,0) $) -- ($ (O) + (0.5,0) $);
\draw [->, ultra thick] (O) -- (P);
\draw [thick, dashed] (A) -- (P);
\begin{scope}[shift={(A)}]
\draw [thick] let \p1=(P), \n1={atan2(\y1,\x1)} in (P) -- ++(\n1:3);
\end{scope}
\end{tikzpicture}
\end{document}
答案2
对于老用户,在 etc. 诞生之前let
\n
\p
,我们使用了一些这样的技巧
\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{decorations.markings,calc,angles,quotes}
\begin{document}
\begin{tikzpicture}
\coordinate (O) at (-1,0);
\coordinate (P) at ($ (O) + (0,1) $);
\coordinate (A) at (-4,0);
\draw ($ (A) + (-0.5,0) $) -- ($ (O) + (0.5,0) $);
\draw [->, ultra thick] (O) -- (P);
\draw[thick, dashed] (A) -- (P) \pgfextra{\pgfinterruptpath\draw [red](P) -- ($(A)!1.5!(P)$);\endpgfinterruptpath} ;
\end{tikzpicture}
\end{document}