Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Is it possible to have a line go through two coordinates and then extend until it intersects with another line? The line in question is not horizontal nor vertical (otherwise I could use the perpendicular coordinate system).

My current code is

\begin{tikzpicture}

\coordinate[label={left:$(x, y, z)$}] (w) at (-6,2);
\coordinate (c) at (0,0);
\coordinate[label={right:$(x,y)$}] (b) at (3,-1);
% I want to avoid hard-coding this coordinate

\draw[ultra thick,-stealth] (w |- c) -- (w);
\draw[ultra thick,-stealth] (c -| b) -- (b);

\draw   (c) +(0,1.5) -- ++(0,-1.5);

\draw[dashed] (w |- c) -- (c -| b);
\draw[dashed] (w) -- (c); % Currently two paths to emulate the result
\draw[dashed] (c) -- (b);

\end{tikzpicture}

So, what I'd like is to specify a path that goes through point w and c and extends until it intersects with the (imaginary) vertical line at (3,y). I don't want to hardcode the position of point b, but have tikz calculate it for me.

share|improve this question
    
You don't need to prefix the title with tikz: because this job has been done by the chosen tags. –  stalking is prohibited Sep 9 '12 at 11:30
1  
@GarbageCollector: whoops. You're right. Thanks for editing. –  knittl Sep 9 '12 at 11:37
    
Don't know if it applies to your complete use case, but have you looked at tkz-euclide? –  Brent.Longborough Sep 9 '12 at 12:31
    
@Brent.Longborough: tkz-euclide looks promising, I will look into it! Is there an English manual as well? My French is a bit rusty. –  knittl Sep 9 '12 at 12:42
    
AFAIK, no, sorry. My French is a bit rusty too, but "I sort of looked at the pictures" –  Brent.Longborough Sep 9 '12 at 13:11

2 Answers 2

You can also use a to path though I didn't test it throughly so It is possible that this breaks down in some very sharp angles or the target is impossible to reach through given coordinate for example, through coordinate is on the left while the target is on the right with respect to the given starting point etc.

\documentclass[]{article}
\usepackage{tikz}
\usetikzlibrary{calc}

\tikzset{
    passthrough/.style={
        to path={ let \p1=($ #1 - (\tikztostart)$),
        \p2=($ (\tikztotarget) - #1 $),
        \n1={atan2(\x1,\y1)},
        \n2={veclen(\x1,\y1) + veclen(\x2,0)/cos(\n1)}
        in (\tikztostart) -- ++(\n1:\n2)
        },
    }
}

\begin{document}
\begin{tikzpicture}

\coordinate[label={left:$(x, y, z)$}] (w) at (-6,2);
\coordinate (c) at (0,0);
\draw   (c) ++(0,1.5) -- ++(0,-3);

\draw[ultra thick,-stealth] (w |- c) -- (w);



\draw[line width=2mm,red] (w) to[passthrough=(c)] (4,0);
\draw[line width=1mm,blue] (w) to[passthrough=(c)] (3,0);
\draw[dashed] (-6,0) -- (3,0);     % Horizontal Test line for blue
\draw[dashed] (-6,-1) -- (4,-1);   % Horizontal Test line for red


\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer

You can solve a (very simple) linear equation with help of \pgfmathsetmacro and calc library:

enter image description here

The code:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
  % initial points: a, b, c
  \fill
  (-6,2) coordinate (a) circle(1pt) node[above]{a}
  (1,-1) coordinate (b) circle(1pt) node[above right]{b}
  (3,0)  coordinate (c) circle(1pt) node[above right]{c};

  % d intersects the line through (a) and (b) and the vertical line through (c)
  \path let \p1=(a), \p2=(b), \p3=(c) in
  \pgfextra{\pgfmathsetmacro{\y}{(\y1-\y2)/(\x1-\x2)*(\x3-\x2)+\y2}}
   (c |- 0,\y pt) coordinate (d) node[below]{d};

  \draw[ultra thick,-stealth] (a |- b) -- (a);
  \draw[ultra thick,-stealth] (b -| d) -- (d);
  \draw   (b) +(0,1.5) -- ++(0,-1.5);
  \draw[dashed] (a |- b) -- (b -| d);
  \draw[dashed] (a) -- (d);
\end{tikzpicture}
\end{document}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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