3

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,

zwerg4
  • 320
  • 3
  • 5
  • 12

3 Answers3

3

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

pchaigno
  • 11,313
  • 2
  • 29
  • 54
2

You don't need to define a new coordinate but you can use the projection identifiers from calc library.

In the last line you just need

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

This mean along A--B take the point which S1 is projected onto A--B.

percusse
  • 3,006
  • 1
  • 14
  • 28
2

Your syntax is nearly correct, but the tee operators |- and -| take the x coordinate from one side and the y coordinate from other. When you write A -| B you get the y coordinate of A and the x coordinate of B, but in your code A and B have the same x coordinate so this gives you the point A again. Instead you want A -| S1, or equivalently 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}
Andrew Swann
  • 876
  • 16
  • 25