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 draw a line upto a curve. Something like extend...

I do not know to get the pont on the curve to stop the line.

\documentclass{standalone}
\usepackage{tikz}

\begin{document}
%
\begin{tikzpicture}
%grid
\draw [step=1.0,thin,gray!40]  
      (0,0) grid (6,5);
\coordinate (C) at (1.5,1.5);
\coordinate (D) at (1.2,3);
\fill[blue] (C) circle (2pt);
\fill[blue] (D) circle (2pt);
\draw (C)--(D);
\draw [red,thick](C)--++(3,0);
\draw [blue,thick](D)--++(3,0);
%
\coordinate (A2) at (5,1);
\coordinate (B2) at (3.0,4);
%
\draw (A2) to [bend left=20] (B2);
%
\end{tikzpicture}
%
\end{document} 

enter image description here

Red and blue lines must stop exactly on the curve.

share|improve this question
1  
I believe there is some intersection functionality in TikZ that has been discussed on this site. That might help. –  Dylan Moreland Jun 2 '12 at 5:41

1 Answer 1

up vote 5 down vote accepted

You can use the intersections library for this, as Dylan suggested.

First, you'll need to name the paths you want to find the intersections for, using name path=<name>. Then you can find the intersections within a draw command using name intersections={of=<first path> and <second path>}. By default, they'll be named intersection-<number>.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
%
\begin{tikzpicture}
%grid
\draw [step=1.0,thin,gray!40]  
      (0,0) grid (6,5);
\coordinate (C) at (1.5,1.5);
\coordinate (D) at (1.2,3);
\fill[blue] (C) circle (2pt);
\fill[blue] (D) circle (2pt);
\draw (C)--(D);
%
\coordinate (A2) at (5,1);
\coordinate (B2) at (3.0,4);
%
\draw [name path=curve] (A2) to [bend left=20] (B2);
\path [name path=lineA](C)--++(3,0);
\path [name path=lineB](D)--++(3,0);
\draw [name intersections={of=curve and lineA}, red, thick] (C) -- (intersection-1);
\draw [name intersections={of=curve and lineB}, blue, thick] (D) -- (intersection-1);
%
\end{tikzpicture}
%
\end{document} 
share|improve this answer
    
Thank you... Jake –  sandu Jun 2 '12 at 7:55
    
Is it possible to name the intersection point as A or B etc... so that this point can be used in another places. –  sandu Jun 2 '12 at 8:01
    
Yes. Just add a node afterwards, such as ... (intersection-1) node (E) {};. Then try \draw (C) -- (E);. –  GregH Jun 2 '12 at 10:53
    
@sandu: It's better to use coordinate instead of node, because even empty nodes take up some space, which will cause trouble when you try to use them later on. –  Jake Jun 2 '12 at 20:19

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.