【问题标题】:Latex / Tikz: draw a vertical line to a straight lineLatex / Tikz:画一条垂直线到一条直线
【发布时间】:2017-11-21 18:33:30
【问题描述】:

也许你可以帮助我,我尝试从点/坐标画一条直线到一条直线。我用 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

谢谢,

【问题讨论】:

    标签: math latex draw pdflatex tikz


    【解决方案1】:

    您可以通过为 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}
    

    【讨论】:

      【解决方案2】:

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

      在最后一行你只需要

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

      这意味着沿 A--B 取 S1 投影到 A--B 上的点。

      【讨论】:

      • 在这种情况下,您可以像 OP 尝试的那样使用 tee 操作,但使用正确的坐标。
      • @AndrewSwann 只有在这种情况下 A -- B 是水平的。
      • 确实 T 恤仅适用于水平/垂直情况。
      【解决方案3】:

      您的语法几乎是正确的,但是 tee 运算符 |--| 从一侧获取 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);
      

      \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}
      

      【讨论】: