\documentclass[tikz, border=1cm]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\coordinate (O) at (0, 0);
\coordinate (A) at (-3, -3);
\draw (O) node[right] {$O$} --(A) node[right] {$A$};
\draw (A)--++(110:3) coordinate (X);
\draw[red] (O)--($(X)!(O)!(A)$);
\end{tikzpicture}
\end{document}
问题
假设我有坐标 (O) 和 (A)。进一步假设我知道从 (A) 开始的线的方向,我将从 (O) 画一条垂直线到该线。在上面的代码中,我只需选择任意值,就足以构建图表。
是否有一种 Tikz 方法可以从 (A) 画出一条到交点的线?
答案1
\documentclass[tikz, border=1cm]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\coordinate (O) at (0, 0);
\coordinate (A) at (-3, -3);
\draw (O) node[right] {$O$} --(A) node[right] {$A$};
\path[overlay] (A) --++ (110:1) coordinate (X);% invisible line
\draw[red] (O) -- ($(X)!(O)!(A)$) coordinate (B);% added new coordinate B
\draw[thick] (A) -- (B) node [left] {B};
\end{tikzpicture}
\end{document}