\section{Straight lines}

It is of course essential to draw straight lines, but before this can be done, it is necessary to be able to define certain particular lines such as mediators, bisectors, parallels or even perpendiculars. The principle is to determine two points on the straight line. 


\subsection{Definition of straight lines}

\begin{NewMacroBox}{tkzDefLine}{\oarg{local options}\parg{pt1,pt2} or \parg{pt1,pt2,pt3}}%
The argument is a list of two or three points. Depending on the case, the macro defines one or two points necessary to obtain the line sought. Either the macro \tkzcname{tkzGetPoint} or the macro \tkzcname{tkzGetPoints} must be used.
I used the term "mediator" to designate the perpendicular bisector line at the middle of a line segment.

\medskip
\begin{tabular}{lll}%
\toprule
arguments           & example & explanation                         \\
\midrule
\TAline{\parg{pt1,pt2}}{\parg{A,B}} {[mediator](A,B)}
\TAline{\parg{pt1,pt2,pt3}}{\parg{A,B,C}} {[bisector](B,A,C)}
\end{tabular}

\medskip
\begin{tabular}{lll}%
\toprule
options             & default & definition                         \\ 
\TOline{mediator}{}{perpendicular bisector of a line segment}  
\TOline{perpendicular=through\dots}{mediator}{perpendicular to a straight line passing through a point} 
\TOline{orthogonal=through\dots}{mediator}{see above }
\TOline{parallel=through\dots}{mediator}{parallel to a straight line passing through a point}
\TOline{bisector}{mediator}{bisector of an angle defined by three points}
\TOline{bisector out}{mediator}{Exterior Angle Bisector}
\TOline{K}{1}{coefficient for the perpendicular line}
\TOline{normed}{false}{normalizes the created segment}
\end{tabular}
\end{NewMacroBox}  

\subsubsection{Example with \tkzname{mediator}}  
\begin{tkzexample}[latex=5 cm,small]
\begin{tikzpicture}[rotate=25]
 \tkzDefPoints{-2/0/A,1/2/B}
 \tkzDefLine[mediator](A,B)          \tkzGetPoints{C}{D}
 \tkzDefPointWith[linear,K=.75](C,D) \tkzGetPoint{D}
 \tkzDefMidPoint(A,B)                \tkzGetPoint{I}
 \tkzFillPolygon[color=teal!20](A,C,B,D)
 \tkzDrawSegments(A,B C,D)
 \tkzMarkRightAngle(B,I,C) 
 \tkzDrawSegments(D,B D,A)
 \tkzDrawSegments(C,B C,A)
\end{tikzpicture}
\end{tkzexample}  

\subsubsection{Example with \tkzname{bisector} and \tkzname{normed}} 
\begin{tkzexample}[latex=7 cm,small] 
\begin{tikzpicture}[rotate=25,scale=.75]
 \tkzDefPoints{0/0/C, 2/-3/A, 4/0/B}
 \tkzDefLine[bisector,normed](B,A,C) \tkzGetPoint{a}
 \tkzDrawLines[add= 0 and .5](A,B A,C)
 \tkzShowLine[bisector,gap=4,size=2,color=red](B,A,C)
 \tkzDrawLines[new,dashed,add= 0 and 3](A,a)
\end{tikzpicture}
\end{tkzexample} 

\subsubsection{Example with \tkzname{orthogonal} and \tkzname{parallel}}    
\begin{tkzexample}[latex=5 cm,small]
\begin{tikzpicture}
   \tkzDefPoints{-1.5/-0.25/A,1/-0.75/B,-0.7/1/C}
   \tkzDrawLine(A,B)
   \tkzLabelLine[pos=1.25,below left](A,B){$(d_1)$}
   \tkzDrawPoints(A,B,C)
   \tkzDefLine[orthogonal=through C](B,A) \tkzGetPoint{c}
   \tkzDrawLine(C,c) 
   \tkzLabelLine[pos=1.25,left](C,c){$(\delta)$}
   \tkzInterLL(A,B)(C,c) \tkzGetPoint{I}
   \tkzMarkRightAngle(C,I,B) 
   \tkzDefLine[parallel=through C](A,B) \tkzGetPoint{c'}
   \tkzDrawLine(C,c') 
   \tkzLabelLine[pos=1.25,below left](C,c'){$(d_2)$}
   \tkzMarkRightAngle(I,C,c')   
\end{tikzpicture}
\end{tkzexample}

\subsubsection{An envelope}
Based on a figure from O. Reboux with pst-eucl by D Rodriguez.

\begin{tkzexample}[vbox,small]
\begin{tikzpicture}[scale=.75]
 \tkzInit[xmin=-6,ymin=-4,xmax=6,ymax=6] % necessary
 \tkzClip
 \tkzDefPoint(0,0){O} 
 \tkzDefPoint(132:4){A}
 \tkzDefPoint(5,0){B}
 \foreach \ang in {5,10,...,360}{%
  \tkzDefPoint(\ang:5){M}
  \tkzDefLine[mediator](A,M)
  \tkzDrawLine[color=magenta,add= 3 and 3](tkzFirstPointResult,tkzSecondPointResult)}
\end{tikzpicture}
\end{tkzexample}

\subsubsection{A parabola}
Based on a figure from O. Reboux with pst-eucl by D Rodriguez.
It is not necessary to name the two points that define the mediator.

\begin{tkzexample}[vbox,small]
\begin{tikzpicture}[scale=.75]
 \tkzInit[xmin=-6,ymin=-4,xmax=6,ymax=6] 
 \tkzClip
 \tkzDefPoint(0,0){O} 
 \tkzDefPoint(132:5){A}
 \tkzDefPoint(4,0){B}
 \foreach \ang in {5,10,...,360}{%
  \tkzDefPoint(\ang:4){M}
  \tkzDefLine[mediator](A,M) 
  \tkzDrawLine[color=teal,add= 3 and 3](tkzFirstPointResult,tkzSecondPointResult)}
\end{tikzpicture}
\end{tkzexample}

%<---------------------------------------------------------------------------->
\subsection{Specific lines:  Tangent to a circle}
Two constructions are proposed. The first one is the construction of a tangent to a circle at a given point of this circle and the second one is the construction of a tangent to a circle passing through a given point outside a disc. 

\begin{NewMacroBox}{tkzDefTangent}{\oarg{local options}\parg{pt1,pt2} or \parg{pt1,dim}}%
The parameter in brackets is the center of the circle or the center of the circle and a point on the circle or the center and the radius. This macro replaces the old one: \tkzcname{tkzTangent}.

\medskip
\begin{tabular}{lll}%
\toprule
arguments           & example & explanation                         \\
\midrule
\TAline{\parg{pt1,pt2 or \parg{pt1,dim}} }{\parg{A,B} or \parg{A,2cm}} {$[AB]$ is radius $A$ is the center}
\bottomrule
\end{tabular} 

\medskip
\begin{tabular}{lll}%
options             & default & definition                         \\ 
\midrule
\TOline{at=pt}{at}{tangent to a point on the circle} 
\TOline{from=pt} {at}{tangent to a circle passing through a point}
\TOline{from with R=pt} {at}{idem, but the circle is defined by center = radius}  
\bottomrule
\end{tabular}

The tangent is not drawn. With option \tkzname{at}, a  point of the tangent is given by \tkzname{tkzPointResult}.  With option \tkzname{from} you get two points of the circle with \tkzname{tkzFirstPointResult} and \tkzname{tkzSecondPointResult}.  You can choose between these two points by comparing the angles formed with the outer point, the contact point and the center. The two possible angles have different directions. Angle counterclockwise refers to \tkzname{tkzFirstPointResult}.
\end{NewMacroBox}

\subsubsection{Example of a tangent passing through a point on the circle } 
\begin{tkzexample}[latex=7cm,small]
\begin{tikzpicture}[scale=.75]
  \tkzDefPoint(0,0){O}
  \tkzDefPoint(6,6){E}
  \tkzDefRandPointOn[circle=center O radius 3]
  \tkzGetPoint{A}
  \tkzDrawSegment(O,A)
  \tkzDrawCircle(O,A)
  \tkzDefTangent[at=A](O)
  \tkzGetPoint{h}
  \tkzDrawLine[add = 4 and 3](A,h)
  \tkzMarkRightAngle[fill=teal!30](O,A,h)
\end{tikzpicture}
\end{tkzexample}

\subsubsection{Choice of contact point with tangents passing through an external point} 
\begin{tkzexample}[latex=7cm,small]
\begin{tikzpicture}[scale=1,rotate=-30]
\tkzDefPoints{ %x    y   name
                0    /0   /Q,
                0    /2   /A,
                6    /-1   /O}
\tkzDefTangent[from = O](Q,A)  \tkzGetPoints{R}{S} 
\tkzInterLC[near](O,Q)(Q,A)    \tkzGetPoints{M}{N}
\tkzDrawCircle(Q,M)
\tkzDrawSegments[new,add = 0 and .2](O,R O,S)
\tkzDrawSegments[gray](N,O R,Q S,Q)
\tkzDrawPoints(O,Q,R,S,M,N)
\tkzMarkAngle[gray,-stealth,size=1](O,R,Q)
\tkzFindAngle(O,R,Q)   \tkzGetAngle{an}
\tkzLabelAngle(O,R,Q){$\pgfmathprintnumber{\an}^\circ$}
\tkzMarkAngle[gray,-stealth,size=1](O,S,Q)
\tkzFindAngle(O,S,Q)   \tkzGetAngle{an}
\tkzLabelAngle(O,S,Q){$\pgfmathprintnumber{\an}^\circ$}
\tkzLabelPoints(Q,O,M,N,R)
\tkzLabelPoints[above,text=red](S)
\end{tikzpicture}
\end{tkzexample}




\subsubsection{Example of tangents passing through an external point } 
\begin{tkzexample}[latex=7cm,small]
\begin{tikzpicture}[scale=.8] 
\tkzDefPoints{0/0/c,1/0/d,3/0/a0}
\def\tkzRadius{1}
\tkzDrawCircle(c,d) 
 \foreach \an in {0,10,...,350}{
  \tkzDefPointBy[rotation=center c angle \an](a0)  
  \tkzGetPoint{a}
  \tkzDefTangent[from = a](c,d) 
  \tkzGetPoints{e}{f}
  \tkzDrawLines(a,f a,e)
  \tkzDrawSegments(c,e c,f)}
\end{tikzpicture} 
\end{tkzexample}

\subsubsection{Example of Andrew Mertz}
\begin{tkzexample}[latex=6cm,small]
 \begin{tikzpicture}[scale=.5] 
 \tkzDefPoint(100:8){A}\tkzDefPoint(50:8){B}  
 \tkzDefPoint(0,0){C} \tkzDefPoint(0,-4){R} 
 \tkzDrawCircle(C,R)
 \tkzDefTangent[from = A](C,R)  \tkzGetPoints{D}{E}
 \tkzDefTangent[from = B](C,R)  \tkzGetPoints{F}{G}
 \tkzDrawSector[fill=teal!20,opacity=0.5](A,E)(D)
 \tkzFillSector[color=teal,opacity=0.5](B,G)(F)
 \end{tikzpicture}
\end{tkzexample}
\url{http://www.texample.net/tikz/examples/}  

\subsubsection{Drawing a tangent option \tkzimp{from}}
\begin{tkzexample}[latex=6cm,small]
\begin{tikzpicture}[scale=.5] 
 \tkzDefPoint(0,0){B} 
 \tkzDefPoint(0,8){A} 
 \tkzDefSquare(A,B)
 \tkzGetPoints{C}{D}
 \tkzDrawSquare(A,B)
 \tkzClipPolygon(A,B,C,D)
 \tkzDefPoint(4,8){F}
 \tkzDefPoint(4,0){E}
 \tkzDefPoint(4,4){Q}
 \tkzFillPolygon[color = green](A,B,C,D)
 \tkzDrawCircle[fill = orange](B,A)
 \tkzDrawCircle[fill = purple](E,B)  
 \tkzDefTangent[from=B](F,A)
 \tkzInterLL(F,tkzSecondPointResult)(C,D)
 \tkzInterLL(A,tkzPointResult)(F,E) 
 \tkzDrawCircle[fill = yellow](tkzPointResult,Q)  
 \tkzDefPointBy[projection= onto B--A](tkzPointResult)
 \tkzDrawCircle[fill = blue!50!black](tkzPointResult,A)
\end{tikzpicture}
\end{tkzexample}

\endinput