2

I have points with irrational coordinates, because I'm mixing polar and Cartesian coordinates. I'd like to specify a coordinate as the x-value of one thing and the y-value of another thing.

In this specific example, I want the two lines on the left to have the same left endpoints.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}

  \begin{tikzpicture}
    \coordinate (left) at (155:2);
    \coordinate (top) at (65:2);
    \coordinate (bottom) at (245:2);
    \coordinate (right) at (335:2);

    \coordinate (leftEdge) at ($ (left) + (-2,0) $);
    \coordinate (bottomEdge) at ($ (bottom) + (0,-2) $);

    \path[draw=black] (left) -- (top) -- (right) -- (bottom) -- cycle;
    \path[draw=blue] (left) -- (leftEdge);
    \path[draw=black] (bottom) -- (bottomEdge);
    \path[draw=red] (bottom) -- ++(-2,0);
  \end{tikzpicture}

\end{document}

I think there's a way to do this with something like (leftEdge.x,bottom.y), but I've been unsuccessful in getting it to work.

enter image description here

How can I get the red edge to go as far left as the blue edge?

3

In your example, you all you need to do is to say \path[draw=red] (bottom) -- (bottom-|leftEdge);. This great answer provides you with a very nce discussion of this syntax.

\documentclass[tikz]{standalone}
\usetikzlibrary{calc}

\begin{document}

  \begin{tikzpicture}
    \coordinate (left) at (155:2);
    \coordinate (top) at (65:2);
    \coordinate (bottom) at (245:2);
    \coordinate (right) at (335:2);

    \coordinate (leftEdge) at ($ (left) + (-2,0) $);
    \coordinate (bottomEdge) at ($ (bottom) + (0,-2) $);

    \path[draw=black] (left) -- (top) -- (right) -- (bottom) -- cycle;
    \path[draw=blue] (left) -- (leftEdge);
    \path[draw=black] (bottom) -- (bottomEdge);
    \path[draw=red] (bottom) -- (bottom-|leftEdge);
  \end{tikzpicture}

\end{document}

enter image description here

  • Thanks! Follow-up question: suppose I want to specify a direction and a line to end on. For example, draw a line at 225 degrees from (right), and make it long enough to reach the bottom border of the image. Is there a similarly quick way to do that? – Pi Fisher Mar 1 at 15:00
  • 1
    @PiFisher Yes, with the calc library, which you are already loading : \draw[purple] (right) -- (intersection cs:first line={(right)--($(right)+(225:3)$)},second line={(bottomEdge)--($(bottomEdge)+(3,0)$)});. – marmot Mar 1 at 15:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.