Latex / Tikz:绘制一条直线的垂直线

时间:2017-11-21 18:33:30

标签: math latex draw pdflatex tikz

也许你可以帮助我,我尝试从点/坐标绘制直线到直线。我用Tikz画画。

      \begin{tikzpicture}
      \coordinate [label=left:$A$] (A) at (-5,-5){};
      \coordinate [label=right:$B$] (B) at (5,-5) {};
      \coordinate [label=right:$C$] (C) at (5,1) {};
      \coordinate [label=left:$D$] (D) at (-5,1) {};

      \draw [thick] (A) -- node[midway] {$\parallel$} (B) -- node[sloped]{$\parallel$} (C) -- (D) -- cycle;

      \coordinate (S1) at ($(D)!0.66!(C)$);
      \coordinate (S2) at ($(A)!0.11!(B)$);
      \draw [very thick] (S1) -- node[above]{x} (S2);
      \draw [red!100, thick] (S1) -- node[above]{T} (A -| B );
      \end{tikzpicture}

This where the red line should go

红线应垂直从坐标(S1)到直线(A - B)。 我试着把它画成这样:

     \draw [red!100, thick] (S1) -- node[above]{T} (A -| B );

但是他画了一条线来协调A

谢谢,

3 个答案:

答案 0 :(得分:3)

你可以通过为AB上的点定义一个新坐标(比如说S3)来做到这一点:

\begin{tikzpicture}
\coordinate [label=left:$A$] (A) at (-5,-5){};
\coordinate [label=right:$B$] (B) at (5,-5) {};
\coordinate [label=right:$C$] (C) at (5,1) {};
\coordinate [label=left:$D$] (D) at (-5,1) {};

\draw [thick] (A) -- node[midway] {$\parallel$} (B) -- node[sloped]{$\parallel$} (C) -- (D) -- cycle;

\coordinate (S1) at ($(D)!0.66!(C)$);
\coordinate (S2) at ($(A)!0.11!(B)$);
\coordinate (S3) at ($(A)!0.66!(B)$);
\draw [very thick] (S1) -- node[above]{x} (S2);
\draw [red!100, thick] (S1) -- node[left]{T} (S3);
\end{tikzpicture}

enter image description here

答案 1 :(得分:2)

您无需定义新坐标,但可以使用calc库中的投影标识符。

在最后一行中你只需要

\draw [red!100, thick] (S1) -- node[left]{T} ($(A)!(S1)!(B)$);

沿着A-B的平均值取S1投射到A-B上的点。

答案 2 :(得分:2)

您的语法几乎正确,但是发球台操作员|--|从一侧获取x坐标,从另一侧获取y坐标。当你写作 A -| B得到A的y坐标和B的x坐标,但是在代码A和B中有相同的x坐标,这样就可以再次得到A点。相反,您需要A -| S1,或等效S1 |- A

 \draw [red!100, thick] (S1) --   node[left]{T} (S1 |- A);

Sample output

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
     \begin{tikzpicture}
      \coordinate [label=left:$A$] (A) at (-5,-5){};
      \coordinate [label=right:$B$] (B) at (5,-5) {};
      \coordinate [label=right:$C$] (C) at (5,1) {};
      \coordinate [label=left:$D$] (D) at (-5,1) {};

      \draw [thick] (A) -- node[midway] {$\parallel$} (B) -- node[sloped]{$\parallel$} (C) -- (D) -- cycle;

      \coordinate (S1) at ($(D)!0.66!(C)$);
      \coordinate (S2) at ($(A)!0.11!(B)$);
      \draw [very thick] (S1) -- node[above]{x} (S2);
      \draw [red!100, thick] (S1) --   node[left]{T} (S1 |- A);
      \end{tikzpicture}
\end{document}