\section{Intersections}

It is possible to determine the coordinates of the points of intersection between two straight lines, a straight line and a circle, and two circles.

The associated commands have no optional arguments and the user must determine the existence of the intersection points himself.

\subsection{Intersection of two straight lines}
\begin{NewMacroBox}{tkzInterLL}{\parg{$A,B$}\parg{$C,D$}}%
Defines the intersection point \tkzname{tkzPointResult} of the two lines $(AB)$ and $(CD)$. The known points are given in pairs (two per line) in brackets, and the resulting point can be retrieved with the macro \tkzcname{tkzDefPoint}.
\end{NewMacroBox}

\subsubsection{Example of intersection between two straight lines}

\begin{tkzexample}[latex=7cm,small]
\begin{tikzpicture}[rotate=-45,scale=.75]
  \tkzDefPoint(2,1){A}   
     \tkzDefPoint(6,5){B}
  \tkzDefPoint(3,6){C}   
     \tkzDefPoint(5,2){D}
  \tkzDrawLines(A,B C,D)
  \tkzInterLL(A,B)(C,D)  
     \tkzGetPoint{I}
  \tkzDrawPoints[color=blue](A,B,C,D)
   \tkzDrawPoint[color=red](I)
\end{tikzpicture}
\end{tkzexample}

\subsection{Intersection of a straight line and a circle}

As before, the line is defined by a couple of points. The circle
 is also defined by a couple:
\begin{itemize}
\item $(O,C)$ which is a pair of points, the first is the centre and the second is any point on the circle.
\item $(O,r)$  The $r$ measure is the radius measure. The unit can be the \emph{cm} or \emph{pt}.
\end{itemize}

\begin{NewMacroBox}{tkzInterLC}{\oarg{options}\parg{$A,B$}\parg{$O,C$} or \parg{$O,r$} or \parg{$O,C,D$}}%
So the arguments are two couples. 

\medskip
\begin{tabular}{lll}%
\toprule
options            & default & definition                         \\ 
\midrule
\TOline{N}         {N}    { (O,C) determines the circle}
\TOline{R}         {N}    { (O, 1 cm) or (O, 120 pt)}  
\TOline{with nodes}{N}    { (O,C,D) CD is a radius}  
\bottomrule
\end{tabular}

\medskip   
The macro defines the intersection points $I$ and $J$ of the line $(AB)$ and the center circle $O$ with radius $r$ if they exist; otherwise, an error will be reported in the |.log| file.
\end{NewMacroBox}

\subsubsection{Simple example of a line-circle intersection}

In the following example, the drawing of the circle uses two points and the intersection of the straight line and the circle uses two pairs of points:

\begin{tkzexample}[latex=7cm,small]
\begin{tikzpicture}[scale=.75]
 \tkzInit[xmax=5,ymax=4]
 \tkzDefPoint(1,1){O} 
 \tkzDefPoint(0,4){A} 
 \tkzDefPoint(5,0){B} 
 \tkzDefPoint(3,3){C}
 \tkzInterLC(A,B)(O,C)  \tkzGetPoints{D}{E}  
 \tkzDrawCircle(O,C)
 \tkzDrawPoints[color=blue](O,A,B,C)
 \tkzDrawPoints[color=red](D,E)
 \tkzDrawLine(A,B)
 \tkzLabelPoints[above right](O,A,B,C,D,E)
\end{tikzpicture} 
\end{tkzexample}

\subsubsection{More complex example of a line-circle intersection}
Figure from  \url{http://gogeometry.com/problem/p190_tangent_circle}

\begin{tkzexample}[latex=7cm,small]
\begin{tikzpicture}[scale=.75]
  \tkzDefPoint(0,0){A}  
  \tkzDefPoint(8,0){B}
  \tkzDefMidPoint(A,B)  
  \tkzGetPoint{O}
  \tkzDrawCircle(O,B)
  \tkzDefMidPoint(O,B)  
  \tkzGetPoint{O'}
  \tkzDrawCircle(O',B)
  \tkzDefTangent[from=A](O',B) 
  \tkzGetSecondPoint{E}
  \tkzInterLC(A,E)(O,B)     
  \tkzGetSecondPoint{D}
  \tkzDefPointBy[projection=onto A--B](D)  
   \tkzGetPoint{F}
  \tkzMarkRightAngle(D,F,B)
  \tkzDrawSegments(A,D A,B D,F) 
  \tkzDrawSegments[color=red,line width=1pt,
      opacity=.4](A,O F,B)
  \tkzDrawPoints(A,B,O,O',E,D) 
  \tkzLabelPoints(A,B,O,O',E,D) 
\end{tikzpicture}
\end{tkzexample}

\subsubsection{Circle defined by a center and a measure, and special cases}
Let's look at some special cases like straight lines tangent to the circle.

\begin{tkzexample}[latex=7cm,small]
\begin{tikzpicture}[scale=.5]
  \tkzDefPoint(0,8){A}  \tkzDefPoint(8,0){B}
  \tkzDefPoint(8,8){C}  \tkzDefPoint(4,4){I}
  \tkzDefPoint(2,7){E}  \tkzDefPoint(6,4){F}
  \tkzDrawCircle[R](I,4 cm)
  \tkzInterLC[R](A,C)(I,4 cm)  \tkzGetPoints{I1}{I2}
  \tkzInterLC[R](B,C)(I,4 cm)  \tkzGetPoints{J1}{J2}
  \tkzInterLC[R](A,B)(I,4 cm)  \tkzGetPoints{K1}{K2}
  \tkzDrawPoints[color=red](I1,J1,K1,K2)
  \tkzDrawLines(A,B B,C A,C)
  \tkzInterLC[R](E,F)(I,4 cm)  \tkzGetPoints{I2}{J2}
  \tkzDrawPoints[color=blue](E,F)
  \tkzDrawPoints[color=red](I2,J2)
  \tkzDrawLine(I2,J2)
\end{tikzpicture}
\end{tkzexample}

\subsubsection{More complex example}
\tkzHandBomb\ Be careful with the syntax. First of all, calculations for the points can be done during the passage of the arguments, but the syntax of \tkzname{xfp} must be respected. You can see that I use the term \tkzname{pi} because \NamePack{xfp} can work with radians. You can also work with degrees but in this case, you need to use  specific commands like |sind| or |cosd|. Furthermore, when calculations require the use of parentheses, they must be inserted in a group... \TEX \{ \dots \}.

\begin{tkzexample}[latex=7cm,small]
\begin{tikzpicture}[scale=1.25]
  \tkzDefPoint(0,1){J} 
  \tkzDefPoint(0,0){O}
  \tkzDrawArc[R,line width=1pt,color=red](J,2.5 cm)(180,0)
  \foreach \i in {0,-5,-10,...,-85,-90}{
    \tkzDefPoint({2.5*cosd(\i)},{1+2.5*sind(\i)}){P}
     \tkzDrawSegment[color=orange](J,P)
     \tkzInterLC[R](P,J)(O,1 cm) 
     \tkzGetPoints{M}{N}
     \tkzDrawPoints[red](N)
     }
  \foreach \i in {-90,-95,...,-175,-180}{
     \tkzDefPoint({2.5*cosd(\i)},{1+2.5*sind(\i)}){P}
     \tkzDrawSegment[color=orange](J,P)
     \tkzInterLC[R](P,J)(O,1 cm) 
     \tkzGetPoints{M}{N}
     \tkzDrawPoints[red](M)
     }
\end{tikzpicture}
\end{tkzexample}

\subsubsection{Calculation of radius example 1}
 With \tkzname{pgfmath} and \tkzcname{pgfmathsetmacro}

The radius measurement may be the result of a calculation that is not done within the intersection macro, but before.
A length can be calculated in several ways. It is possible of course,
 to use the module \tkzname{pgfmath} and the macro \tkzcname{pgfmathsetmacro}. In some cases, the results obtained are not precise enough, so the following calculation $0.0002 \div 0.0001$ gives $1.98$ with pgfmath while xfp will give $2$. 

\subsubsection{Calculation of radius example 2}
With \tkzname{xfp} and \tkzcname{fpeval}:

\begin{tkzexample}[latex=7cm,small]
  \begin{tikzpicture}
  \tkzDefPoint(2,2){A}
  \tkzDefPoint(5,4){B}
  \tkzDefPoint(4,4){O}
  \edef\tkzLen{\fpeval{0.0002/0.0001}}
  \tkzDrawCircle[R](O,\tkzLen cm)
  \tkzInterLC[R](A,B)(O, \tkzLen cm)
  \tkzGetPoints{I}{J}
  \tkzDrawPoints[color=blue](A,B)
  \tkzDrawPoints[color=red](I,J)
  \tkzDrawLine(I,J)
\end{tikzpicture}
  \end{tkzexample}

\subsubsection{Calculation of radius example 3}
 With \TEX\ and \tkzcname{tkzLength}.

 This dimension was created with \tkzcname{newdimen}. 2 cm has been transformed into points. It is of course possible to use \TEX\ to calculate.

\begin{tkzexample}[latex=7cm,small]
\begin{tikzpicture}
	\tkzDefPoints{2/2/A,5/4/B,4/4/0}
  \tkzLength=2cm
  \tkzDrawCircle[R](O,\tkzLength)
  \tkzInterLC[R](A,B)(O,\tkzLength)
  \tkzGetPoints{I}{J}
  \tkzDrawPoints[color=blue](A,B)
  \tkzDrawPoints[color=red](I,J)
  \tkzDrawLine(I,J)
\end{tikzpicture}
\end{tkzexample}

\subsubsection{Squares in half a disc}
A Sangaku look! It is a question of proving that one can inscribe in a half-disc, two squares, and to determine the length of their respective sides according to the radius.

\begin{tkzexample}[latex=6cm,small]
\begin{tikzpicture}[scale=.75]
 \tkzDefPoints{0/0/A,8/0/B,4/0/I}
 \tkzDefSquare(A,B) \tkzGetPoints{C}{D}
 \tkzInterLC(I,C)(I,B)\tkzGetPoints{E'}{E}
 \tkzInterLC(I,D)(I,B)\tkzGetPoints{F'}{F}
 \tkzDefPointsBy[projection = onto A--B](E,F){H,G}
 \tkzDefPointsBy[symmetry   = center H](I){J}
 \tkzDefSquare(H,J)\tkzGetPoints{K}{L}
 \tkzDrawSector[fill=brown!30](I,B)(A)
 \tkzFillPolygon[color=red!40](H,E,F,G)
 \tkzFillPolygon[color=blue!40](H,J,K,L)
 \tkzDrawPolySeg[color=red](H,E,F,G) 
 \tkzDrawPolySeg[color=red](J,K,L)
 \tkzDrawPoints(E,G,H,F,J,K,L)
\end{tikzpicture}
\end{tkzexample}

\subsubsection{Option "with nodes"}
\begin{tkzexample}[latex=8cm,small]
\begin{tikzpicture}[scale=.75]
\tkzDefPoints{0/0/A,4/0/B,1/1/D,2/0/E}
\tkzDefTriangle[equilateral](A,B) 
\tkzGetPoint{C}
\tkzDrawCircle(C,A)
\tkzInterLC[with nodes](D,E)(C,A,B) 
\tkzGetPoints{F}{G}
\tkzDrawPolygon(A,B,C)
\tkzDrawPoints(A,...,G)
\tkzDrawLine(F,G)
\end{tikzpicture}
\end{tkzexample}

\subsection{Intersection of two circles}

The most frequent case is that of two circles defined by their center and a point, but as before the option \tkzname{R} allows to use the radius measurements.

\begin{NewMacroBox}{tkzInterCC}{\oarg{options}\parg{$O,A$}\parg{$O',A'$} or \parg{$O,r$}\parg{$O',r'$} or   \parg{$O,A,B$} \parg{$O',C,D$}}%
\begin{tabular}{lll}%
options       & default & definition                         \\
\midrule
\TOline{N}   {N}    {$OA$ and $O'A'$ are radii, $O$ and $O'$ are the centres}
\TOline{R}   {N}    {$r$ and $r'$ are dimensions and measure the radii}
\TOline{with nodes} {N}  { in (A,A,C)(C,B,F) AC and BF give the radii. }
\bottomrule
\end{tabular}

\medskip
This macro defines the intersection point(s) $I$ and $J$ of the two center circles $O$ and $O'$. If the two circles do not have a common point then the macro ends with an error that is not handled. \\
It is also possible to use directly \tkzcname{tkzInterCCN} and \tkzcname{tkzInterCCR}.
\end{NewMacroBox}

\subsubsection{Construction of an equilateral triangle}
\begin{tkzexample}[latex=7cm,small]
\begin{tikzpicture}[trim left=-1cm,scale=.5]
 \tkzDefPoint(1,1){A}
 \tkzDefPoint(5,1){B}
 \tkzInterCC(A,B)(B,A)\tkzGetPoints{C}{D}
 \tkzDrawPoint[color=black](C)
 \tkzDrawCircle[dashed](A,B)
 \tkzDrawCircle[dashed](B,A)
 \tkzCompass[color=red](A,C)
 \tkzCompass[color=red](B,C)
 \tkzDrawPolygon(A,B,C)
 \tkzMarkSegments[mark=s|](A,C B,C)
 \tkzLabelPoints[](A,B)
 \tkzLabelPoint[above](C){$C$}
\end{tikzpicture}
\end{tkzexample}

\subsubsection{Example a mediator}
\begin{tkzexample}[latex=7cm,small]
\begin{tikzpicture}[scale=.5]
  \tkzDefPoint(0,0){A}
  \tkzDefPoint(2,2){B}
  \tkzDrawCircle[color=blue](B,A)
  \tkzDrawCircle[color=blue](A,B)
  \tkzInterCC(B,A)(A,B)\tkzGetPoints{M}{N}
  \tkzDrawLine(A,B)
  \tkzDrawPoints(M,N)
  \tkzDrawLine[color=red](M,N)
\end{tikzpicture}
\end{tkzexample}

\subsubsection{An isosceles triangle.}
\begin{tkzexample}[latex=7cm,small]
\begin{tikzpicture}[rotate=120,scale=.75]
 \tkzDefPoint(1,2){A}
 \tkzDefPoint(4,0){B}
 \tkzInterCC[R](A,4cm)(B,4cm)
 \tkzGetPoints{C}{D}
 \tkzDrawCircle[R,dashed](A,4 cm)
 \tkzDrawCircle[R,dashed](B,4 cm)
 \tkzCompass[color=red](A,C)
 \tkzCompass[color=red](B,C)
 \tkzDrawPolygon(A,B,C)
 \tkzDrawPoints[color=blue](A,B,C)
 \tkzMarkSegments[mark=s|](A,C B,C)
 \tkzLabelPoints[](A,B)
 \tkzLabelPoint[above](C){$C$}
\end{tikzpicture}
\end{tkzexample}


\subsubsection{Segment trisection}
 The idea here is to divide a segment with a ruler and a compass into three segments of equal length.
 
\begin{tkzexample}[latex=9cm,small]
\begin{tikzpicture}[scale=.8]
 \tkzDefPoint(0,0){A}  
 \tkzDefPoint(3,2){B}
 \tkzInterCC(A,B)(B,A) 
 \tkzGetPoints{C}{D}
 \tkzInterCC(D,B)(B,A) 
 \tkzGetPoints{A}{E}
 \tkzInterCC(D,B)(A,B) 
 \tkzGetPoints{F}{B}
 \tkzInterLC(E,F)(F,A) 
 \tkzGetPoints{D}{G}
 \tkzInterLL(A,G)(B,E) 
 \tkzGetPoint{O}
 \tkzInterLL(O,D)(A,B) 
 \tkzGetPoint{J}
 \tkzInterLL(O,F)(A,B) 
 \tkzGetPoint{I}
 \tkzDrawCircle(D,A)    
 \tkzDrawCircle(A,B)
 \tkzDrawCircle(B,A)    
 \tkzDrawCircle(F,A)
 \tkzDrawSegments[color=red](O,G
  O,B O,D O,F)
 \tkzDrawPoints(A,B,D,E,F,G,I,J)  
 \tkzLabelPoints(A,B,D,E,F,G,I,J)
 \tkzDrawSegments[blue](A,B B,D A,D%
  A,F F,G E,G B,E)
 \tkzMarkSegments[mark=s|](A,I I,J J,B)
\end{tikzpicture}
\end{tkzexample}

\subsubsection{With the option \tkzimp{with nodes}}
\begin{tkzexample}[latex=6cm,small]
\begin{tikzpicture}[scale=.5]
 \tkzDefPoints{0/0/a,0/5/B,5/0/C}
 \tkzDefPoint(54:5){F}
 \tkzDrawCircle[color=gray](A,C) 
 \tkzInterCC[with nodes](A,A,C)(C,B,F) 
 \tkzGetPoints{a}{e}
 \tkzInterCC(A,C)(a,e) \tkzGetFirstPoint{b}
 \tkzInterCC(A,C)(b,a) \tkzGetFirstPoint{c}
 \tkzInterCC(A,C)(c,b) \tkzGetFirstPoint{d}
 \tkzDrawPoints(a,b,c,d,e)  
 \tkzDrawPolygon[color=red](a,b,c,d,e)
 \foreach \vertex/\num in {a/36,b/108,c/180,
                          d/252,e/324}{%
 \tkzDrawPoint(\vertex)
 \tkzLabelPoint[label=\num:$\vertex$](\vertex){} 
 \tkzDrawSegment[color=gray,style=dashed](A,\vertex)
 }  
\end{tikzpicture}
\end{tkzexample}

 \endinput 

