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.

I have drawn a circle and its horizontal and vertical line.

\begin{tikzpicture}

  \draw (0,0) node [above left] {O} circle (3); % circle of radius 3
  \draw (0,3) node [above] {A} -- (0,-3) node [below] {B}; % vertical diameter
  \draw (-3,0) node [left] {P} -- (3,0) node [right] {Q}; % hotizontal diameter

\end{tikzpicture}

Now, I want a line parallel to AB passing through (-2,0) and ending on the circumference of the circle at both ends.

share|improve this question
    
Welcome to TeX.sx! A tip: If you indent lines by 4 spaces or enclose words in backticks `, they'll be marked as code, as can be seen in my edit. You can also highlight the code and click the "code" button (with "{}" on it). –  zeroth Mar 20 '13 at 10:16
    
Your question doesn't suit its title. The line parallel to AB through (-2,0) doesn't touch the circumference but crosses it. Where you stop to draw it, has no influence on that. –  Toscho Mar 20 '13 at 11:18
    
@Toscho: I guess he meant line segment? –  Matthew Leingang Mar 20 '13 at 11:50
    
Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. –  Jubobs Apr 12 '13 at 9:45
add comment

5 Answers 5

Two different approaches:

Clipping

You can draw a line longer than required, but clipping it to the circle:

\begin{tikzpicture}
  \draw (0,0) node [above left] {O} circle (3); % circle of radius 3
  \draw (0,3) node [above] {A} -- (0,-3) node [below] {B}; % vertical diameter
  \draw (-3,0) node [left] {P} -- (3,0) node [right] {Q}; % hotizontal diameter
\clip (0,0) circle (3);
\draw[green] (-2,3) -- (-2,-3);
\end{tikzpicture}

Clip

Calc

You can use trigonometry to calculate the coordinates of the starting and ending points of the line. Using polar coordinates, what you have to find are the angles of those points with respect of the center of the circle. In this case it is easy, since the radius r and the x distance are known, the angle will be acos(x/r). This calculation can be made in a let..in construct.

With this approach you have also the coordinates (in polar form) of the end points of the line, so you can label them also if you need to (as shown in the following example).

\usetikzlibrary{calc}
\begin{tikzpicture}
  \draw (0,0) node [above left] {O} circle (3); % circle of radius 3
  \draw (0,3) node [above] {A} -- (0,-3) node [below] {B}; % vertical diameter
  \draw (-3,0) node [left] {P} -- (3,0) node [right] {Q}; % hotizontal diameter

\draw[red] 
   let \n1 = {acos(2/3)}        % \n1 is the angle
   in (180-\n1:3) node[above left] {A'} -- 
      (180+\n1:3) node[below left] {B'};
   % Polar form uses the syntax (angle:radius)
\end{tikzpicture}

Calc

share|improve this answer
    
Accordig to OP, the line should be parallel to AB and go trough (-2,0). –  Toscho Mar 20 '13 at 11:19
    
@Toscho Right! Thanks for noticing it. Updated answer. –  JLDiaz Mar 20 '13 at 11:37
add comment

You can avoid the math with the intersections library of tikz:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}

\begin{tikzpicture}
  \draw[name path=circle] (0,0) circle (3) node [above left] {$O$};  % circle of radius 3
  \draw (0,3) node [above] {$A$} -- (0,-3) node [below] {$B$}; % vertical diameter
  \draw (-3,0) node [left] {$P$} -- (3,0) node [right] {$Q$}; % horizontal diameter
  \path[name path=transversal] (-2,-3) -- ++(0,6);
  \draw[name intersections={of=circle and transversal,by={Q',P'}}] 
     (P') node[below] {$P'$} -- (Q') node[above] {$Q'$};
\end{tikzpicture}

\end{document}

sample output

This is a pretty flexible approach because the paths can be really anything—circles, lines, Bézier curves, etc.

share|improve this answer
    
Accordig to OP, the line should be parallel to AB and go trough (-2,0) –  Toscho Mar 20 '13 at 11:20
    
Ha! I think all three answerers read that wrong initially. Will fix. –  Matthew Leingang Mar 20 '13 at 11:38
    
@MatthewLeingang Now that only happens very rarely. I should have made a print screen of that :) –  hpesoj626 Mar 20 '13 at 13:23
    
I think purcusse's right. His post was first and had the initial misread. JLDiaz and I focused on other ways to produce the same picture rather than the original post. –  Matthew Leingang Mar 20 '13 at 13:46
    
@MatthewLeingang Well, in my case I wrote my answer without seeing percusses' one (we wrote them concurrently), so my error was genuine :-) –  JLDiaz Mar 21 '13 at 8:00
add comment

With a little computation, you can get the angle and then get the symmetrical point.

\begin{tikzpicture}

  \draw (0,0) node [above left] {O} circle (3); % circle of radius 3
  \draw (0,3) node [above] {A} -- (0,-3) node [below] {B}; % vertical diameter
  \draw (-3,0) node [left] {P} -- (3,0) node [right] {Q}; % hotizontal diameter

\draw ({asin(-2/3)}:3) -- ({-180-asin(-2/3)}:3);
\end{tikzpicture}

enter image description here

share|improve this answer
    
Accordig to OP, the line should be parallel to AB and go trough (-2,0) –  Toscho Mar 20 '13 at 11:38
    
@Toscho Haha, nice catch! I think it's my fault that other answers did the same. The correct line then reads \draw ({180-asin(2/3)}:3) -- ({-180-asin(-2/3)}:3);. –  percusse Mar 20 '13 at 12:14
2  
Thanks all for the help.. Anyways, I needed to draw lines both ways and by chance got answers for both.. I am new to Latex and the more I work on it, the more I like it.. –  Divya Mar 20 '13 at 13:36
add comment

Good job for tkz-euclide. You have a lot of solutions with tikz, the choice depends of what you want to do after this. The solution with tkz-euclide is interesting if you want to avoid some calculations, if you want to draw a lot of pictures like this. The only problem comes from my macro \tkzInterLC because in some cases the result is not accurate enough. Interesting too : you can easily adapt the solution for different radius.

\documentclass{article}
\usepackage{tkz-euclide}
\usetkzobj{all}

\begin{document}
\begin{tikzpicture}
 \tkzInit[ymin=-4,ymax=4,xmin=-4,xmax=4]
% definitions
 \tkzDefPoints{ 0  / 0 /O, %blank spaces are fine for numbers 
                3  / 0 /P, % but not for the names of nodes
                3  / 0 /Q,
                0  / 3 /A,
                0  /-3 /B,
               -2  / 0 /I}
\tkzDefPointWith[orthogonal](I,O) \tkzGetPoint{H} % IH perp IO
\tkzInterLC(I,H)(O,A)         \tkzGetPoints{E}{F} % inter circle and line
% drawings
\tkzDrawCircle[R](O,3 cm)
\tkzDrawSegments(A,B P,Q)
\tkzDrawSegment[color=red](E,F)
\tkzDrawPoints(E,F)
% labels
\tkzLabelPoints(O,P,Q,A,B,I)
\end{tikzpicture}
\end{document}  

If you want only a line parallel and through a point, possible is

\tkzDefLine[parallel=through I](A,B) \tkzGetPoint{J}

enter image description here

share|improve this answer
    
Remark. I prefer to organize the code with three parts : definition, drawing, label. I create the macros to be able to do this. Sometimes, the code needs a lot of lines but I think it's more easy to understand. –  Alain Matthes Mar 21 '13 at 8:01
add comment

With PSTricks.

Intersection

enter image description here

\documentclass[pstricks,border=15pt]{standalone}
\usepackage{pst-eucl}

\psset{CurveType=polyline}

\begin{document}
\begin{pspicture}(-3,-3)(3,3)
    \pstGeonode[PosAngle={135,0,180}]{O}(3,0){Q}(-3,0){P}
    \pstGeonode[PosAngle={90,-90}](0,3){A}(0,-3){B}
    \pnode(-2,0|A){A'}
    \pnode(-2,0|B){B'}
    \pstInterLC[PosAngleA=90,PosAngleB=-90]{A'}{B'}{O}{A}{Q'}{P'}
    \pstCircleOA{O}{A}
    \psline(Q')(P')
\end{pspicture}
\end{document}

Warning: I just knew that

    \pstInterLC[PosAngle={90,-90}]{A'}{B'}{O}{A}{Q'}{P'}

will not work!

Inverse Trigonometry

As PostScript only provides sin, cos, and atan, we need to define a new RPN operator acos as

\pstVerb{/acos {dup 2 exp 1 exch sub sqrt exch atan} bind def}

The complete code is as follows.

\documentclass[pstricks,border=15pt]{standalone}
\usepackage{pst-eucl}

\pstVerb{/acos {dup 2 exp 1 exch sub sqrt exch atan} bind def}

\psset{CurveType=polyline}

\begin{document}
\begin{pspicture}(-3,-3)(3,3)
    \pstGeonode[PosAngle={135,0,180}]{O}(3,0){Q}(-3,0){P}
    \pstGeonode[PosAngle={90,-90}](0,3){A}(0,-3){B}
    \pstGeonode[PosAngle={90,-90}]
        (!3 -2 3 div acos PtoC){Q'}
        (!3 -2 3 div acos neg PtoC){P'}
    \pstCircleOA{O}{A}
\end{pspicture}
\end{document}

Clipping

Using clipping (for this problem) should be avoided because it makes us difficult to place the P' and Q' labels (and the dots if needed).

The following example uses node P' and Q' (used in the second method above) to circumvent the difficulty but it will look so funny because of

    \pstGeonode[PosAngle={90,-90},CurveType=none]
        (!3 -2 3 div acos PtoC){Q'}
        (!3 -2 3 div acos neg PtoC){P'
    \psclip{\pstCircleOA{O}{A}}
        \psline([offset=1]Q')([offset=-1]P')
    \endpsclip

which can actually be written as

    \pstGeonode[PosAngle={90,-90}]
        (!3 -2 3 div acos PtoC){Q'}
        (!3 -2 3 div acos neg PtoC){P'}

OK, here is the complete code!

\documentclass[pstricks,border=15pt]{standalone}
\usepackage{pst-eucl}

\pstVerb{/acos {dup 2 exp 1 exch sub sqrt exch atan} bind def}

\psset{CurveType=polyline}

\begin{document}
\begin{pspicture}(-3,-3)(3,3)
    \pstGeonode[PosAngle={135,0,180}]{O}(3,0){Q}(-3,0){P}
    \pstGeonode[PosAngle={90,-90}](0,3){A}(0,-3){B}
    \pstGeonode[PosAngle={90,-90},CurveType=none]
        (!3 -2 3 div acos PtoC){Q'}
        (!3 -2 3 div acos neg PtoC){P'}
    \psclip{\pstCircleOA{O}{A}}
        \psline([offset=1]Q')([offset=-1]P')
    \endpsclip
    %\pstCircleOA{O}{A} <-- not needed!
\end{pspicture}
\end{document}

The latest edit:

Apparently, pstricks.pro has added or defined Acos as follows,

/Acos {dup dup mul neg 1 add dup 0 lt {% arc cos, returns 0 when negative root
  pop pop 0 }{ sqrt exch atan} ifelse } def

so more keystrokes can be reduced.

\documentclass[pstricks,border=15pt]{standalone}
\usepackage{pst-eucl}
\psset{CurveType=polyline}

\begin{document}
\begin{pspicture}(-3,-3)(3,3)
    \pstGeonode[PosAngle={135,0,180}]{O}(3,0){Q}(-3,0){P}
    \pstGeonode[PosAngle={90,-90}](0,3){A}(0,-3){B}
    \pstGeonode[PosAngle={90,-90}]
        (!3 -2 3 div Acos PtoC){Q'}
        (!3 -2 3 div Acos neg PtoC){P'}
    \pstCircleOA{O}{A}
\end{pspicture}
\end{document}
share|improve this answer
add comment

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.