延伸线至 x 轴

延伸线至 x 轴

我使用以下代码从定义的节点绘制2条相关线。

是否可以修改此代码来延长线,以便 L 和 S 点到达 x 轴,而无需定义它们的长度。

\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{tikz}
\begin{document}
\begin{frame}[t]
\frametitle{Line to x axis}
\begin{tikzpicture}[scale=.9, transform shape]
\draw [thick](0,0) -- (11,0) node [black, xshift=.2cm, yshift=-.2cm] {Y};
\draw [thick](0,0) -- (0,8) node [black, xshift=-.2cm, yshift=0cm] {r};
\draw [very thick, blue] (5.5,4) node (er1){} +(-40:5cm) node [blue, xshift=.2cm, yshift=-.2cm] {S} -- +(140:5cm)  +(40:5.5cm) node [blue, xshift=.2cm, yshift=.2cm] {M} -- +(-140:4cm) node [blue, xshift=-.2cm, yshift=.2cm] {L};
\end{tikzpicture}
\end{frame}
\end{document}

在此处输入图片描述

答案1

您可以通过以下语法找到这些交点:

(intersection of A--B and C--D) % for example

一个完整的例子如下。假设我们知道点 A、B 和 M(后者是两条线相交的地方)。

\documentclass[border=2mm]{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\coordinate (O) at (0,0);
\coordinate (X) at (5,0);
\coordinate (Y) at (0,5);
\coordinate (A) at (1,4);
\coordinate (B) at (4,5);
\coordinate (M) at (2,2);
\coordinate (C) at (intersection of A--M and O--X); % <-- We find here an intersection point...
\coordinate (D) at (intersection of B--M and O--X); %     and here the other one
\draw[latex-latex] (Y) node [above] {$y$} |- (X) node [right] {$x$};
\draw (A) node [above] {$A$} -- (C) node [below] {$C$};
\draw (B) node [above] {$B$} -- (D) node [below] {$D$};
\fill (M) circle (1pt) node [right] {$M$};
\end{tikzpicture}
\end{document}

在此处输入图片描述

编辑:将上面的例子应用到 OP 图中,我们得到:

\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{tikz}
\begin{document}
\begin{frame}[t]
\frametitle{Line to x axis}
\begin{tikzpicture}[scale=.9, transform shape]
\draw [thick](0,0) coordinate (O) -- (11,0) coordinate (Y) node
      [xshift=.2cm, yshift=-.2cm] {Y}; % added coordinates (O), (Y), removed 'black' (not necessary)
\draw [thick](0,0) -- (0,8) node [xshift=-.2cm] {r}; % removed 'black' and 'yshift' (not necessary)
\path (5.5,4) node (er1){} +(-40:5cm) node [blue, xshift=.2cm, yshift=-.2cm] {} --
  +(140:5cm) coordinate (N) +(40:5.5cm) coordinate (M) node [blue, xshift=.2cm, yshift=.2cm] {M} --
  +(-140:4cm) node [blue, xshift=-.2cm, yshift=.2cm] {}; % added coordinates (M), (N), changed \draw for \path, removed labels L and S
% new code
\coordinate (L) at (intersection of O--Y and M--er1);
\coordinate (S) at (intersection of O--Y and N--er1);
\draw [very thick, blue] (M) -- (L) node [below] {L};
\draw [very thick, blue] (N) -- (S) node [below] {S};
\end{tikzpicture}
\end{frame}
\end{document}

在此处输入图片描述

相关内容