Latex / Tikz: draw a vertical line to a straight line

zwerg4 picture zwerg4 · Nov 21, 2017 · Viewed 8.3k times · Source

Maybe you can help me, I try to draw a line from a Point/Coordinate to a straight line. I use Tikz to draw.

      \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

the red line should go from coordinate (S1) to the straight line (A -- B) vertically. I tried it to draw it like this:

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

But then he draw a line to coordinate A

Thank you,

Answer

pchaigno picture pchaigno · Nov 27, 2017

You can do that by defining a new coordinate (say S3) for the point on AB:

\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