\newpage
\section{Class \tkzClass{circle}}

The \tkzVar{circle}{C} variable is a table reserved for storing circle objects. Although its use is optional and any valid variable name may be used (e.g., \code{Circles}), it is strongly recommended to adopt the standard name \texttt{C} to ensure consistency and readability. If a custom variable is used, it must be initialized manually. The \tkzFct{tkz-elements}{init\_elements()} function will reset the \texttt{circle}{C} table if it has already been defined.


\subsubsection{Creating a circle}
\label{ssub:creating_a_circle}
A circle is defined by two points:
\begin{itemize}
\item the center of the circle,
\item a point lying on the circle.
\end{itemize}
\vspace{0.5em}

To create a circle, use the following syntax:
\begin{mybox}
\code{C.OA = circle(z.O, z.A)}
\end{mybox}

The newly created circle object stores various geometric attributes such as its radius, diameter, and notable points on the circumference (e.g., north, east, south, and west poles).

\subsection{Attributes of a circle}

A circle object stores various geometric attributes that can be accessed for further computation or drawing. These attributes are automatically computed at creation.

\vspace{1em}

\bgroup
\catcode`_=12
\small
  \captionof{table}{Circle attributes.}\label{circle:attributes}
  \begin{tabular}{ll}
  \toprule
  \texttt{Attributes}         & \texttt{Reference}                \\
  \midrule
  \tkzAttr{circle}{type}      &  Type of circle, always "circle"            \\
  \tkzAttr{circle}{center}    &  Center of the circle                       \\
  \tkzAttr{circle}{through}   &  Point through which the circle passes      \\
  \tkzAttr{circle}{radius}    &  [\ref{ssub:example_circle_attributes}]     \\
  \tkzAttr{circle}{north}     &  [\ref{ssub:example_circle_attributes}]     \\
  \tkzAttr{circle}{south}     &  [\ref{ssub:example_circle_attributes}]     \\
  \tkzAttr{circle}{east}      &  [\ref{ssub:example_circle_attributes}]     \\
  \tkzAttr{circle}{west}      &  [\ref{ssub:example_circle_attributes}]     \\
  \tkzAttr{circle}{opp}       &  [\ref{ssub:example_circle_attributes}]     \\
  \tkzAttr{circle}{ct}        &  [\ref{ssub:example_circle_attributes}]     \\
  \tkzAttr{circle}{perimeter} &  [\ref{ssub:attributes_perimeter_and_area}] \\
  \tkzAttr{circle}{area}      &  [\ref{ssub:attributes_perimeter_and_area}] \\
  \bottomrule %
  \end{tabular}
\egroup



\subsubsection{Example: circle attributes}
\label{ssub:example_circle_attributes}

Several attributes of the \tkzNameObj{circle} class are illustrated in the following example.

\medskip

The point diametrically opposite a given point on the circle can be obtained using the method:

\begin{center}
\code{z.Mp = C.OA:antipode(z.M)}
\end{center}


When a circle object is created using \code{circle}, the point diametrically opposite the defining point (the one through which the circle passes) is automatically generated and stored in the attribute \code{opp}.

\medskip

In addition, the line passing through the center and that point is also created and accessible via the attribute \code{ct} (center-to-through). This is particularly useful when dealing with a circle returned by a function, and you don't know in advance which points were used to construct it.

\vspace{1em}

\begin{tkzexample}[latex=7cm]
\directlua{
 init_elements()
 z.a = point(1, 1)
 z.b = point(5, 4)
 C.ab = circle(z.a, z.b)
 z.s = C.ab.south
 z.w = C.ab.west
 r = C.ab.radius
 z.c = C.ab.opp
 z.r,
 z.t = C.ab.ct:ortho_from(z.b):get()}
\begin{center}
\begin{tikzpicture}[scale=.5]
  \tkzGetNodes
  \tkzDrawPoints(a,b,c,s,w)
  \tkzLabelPoints(a,b,c,s,w)
  \tkzDrawCircle(a,b)
  \tkzDrawSegments(a,b r,t b,c)
  \tkzLabelSegment[sloped](a,b){ab = \tkzUseLua{r}}
  \end{tikzpicture}
\end{center}
\end{tkzexample}


\subsubsection{Attributes perimeter and area}
\label{ssub:attributes_perimeter_and_area}

 \pgfkeys{/pgf/number format/.cd,std,precision=4}
 \let\pmpn\pgfmathprintnumber

\begin{mybox}
\begin{verbatim}
  \directlua{
  z.A = point(1, 2)
  z.B = point(4, 3)
  C.AB = circle(z.A, z.B)
  p = C.AB.perimeter
  a = C.AB.area}

Let be two points $A$ and $B$. The circle of center $A$ passing
through $B$ has perimeter \pmpn{\tkzUseLua{p}} $cm$
and area \pmpn{\tkzUseLua{a} }$cm^2$.
\end{verbatim}
\end{mybox}

\directlua{
z.A = point(1, 2)
z.B = point(4, 3)
C.AB =  circle(z.A, z.B)
p = C.AB.perimeter
a = C.AB.area}

Let be two points $A$ and $B$.
The circle of center $A$ passing through $B$ has perimeter \pmpn{\tkzUseLua{p}} $cm$ and area \pmpn{\tkzUseLua{a} }$cm^2$.


\newpage
\subsection{Methods of the class circle}
The circle class offers a wide range of methods, which can be grouped according to the type of value they return: numbers, booleans, strings, points, lines, or circles. These methods allow for computations such as checking inclusion, finding tangents, computing inversions, and more.

\vspace{1em}

\bgroup
\catcode`_=12
\small
\captionof{table}{Circle methods.}\label{circle:methods}
\begin{tabular}{ll}
\toprule
\texttt{Methods} & \texttt{Reference}   \\
\midrule
\texttt{Constructor} & \\
\midrule
\tkzFct{circle}{new(O,A)} & [\ref{ssub:method_circle_new}; \ref{ssub:creating_a_circle}]\\
\tkzFct{circle}{radius(O,r)} & Deprecated; See  [\ref{ssub:method_circle_radius}]\\
\tkzFct{circle}{diameter(A,B)} & Deprecated; See  [\ref{ssub:method_circle_diameter}]\\
\midrule
\texttt{Methods Returning a Real Number} & \\
\midrule
\tkzMeth{circle}{power(pt)}& \ref{ssub:power}] \\
\midrule
\texttt{Methods Returning a String} & \\
\midrule
\tkzMeth{circle}{circles\_position(C1)}  & [\ref{ssub:circles_position}] \\
\tkzMeth{circle}{position(obj)} & [\ref{ssub:circle_position}]\\
\tkzMeth{circle}{lines\_position(L)} & [\ref{ssub:method_circle_lines_position}]\\
\midrule
\texttt{Methods Returning a Boolean} & \\
\midrule
\tkzMeth{circle}{is\_tangent(L)} & [\ref{ssub:method_circle_is_tangent}]  \\
\tkzMeth{circle}{is\_secant(L)} & [\ref{ssub:method_circle_is_secant}]  \\
\tkzMeth{circle}{is\_disjoint(L)} & [\ref{ssub:method_circle_is_disjoint}]  \\
\midrule
\texttt{Methods Returning a Point} & \\
\midrule
\tkzMeth{circle}{get(i)} &     [\ref{ssub:method_circle_get}]   \\
\tkzMeth{circle}{antipode(pt)} & [\ref{ssub:method_circle_antipode}]   \\
\tkzMeth{circle}{midarc(pt,pt)} &  [\ref{ssub:method_circle_midarc}]\\
\tkzMeth{circle}{point(r,<pt>)} & [\ref{ssub:method_circle_point}]\\
\tkzMeth{circle}{random\_pt(<'inside'>)}  & [\ref{ssub:method_imeth_circle_random_inside}]\\
\tkzMeth{circle}{inversion(obj)} & [\ref{ssub:inversion}; \ref{par:inversion_circle} \ref{par:inversion_line}]\\
\tkzMeth{circle}{inversion\_neg(obj)} & [\ref{ssub:inversion_neg}]\\
\tkzMeth{circle}{internal\_similitude(C)}  &  [\ref{ssub:method_circle_internal__similitude}]\\
\tkzMeth{circle}{external\_similitude(C)} &  [\ref{ssub:method_circle_external__similitude}] \\
\tkzMeth{circle}{similitude(mode, C)} &  [\ref{ssub:similitude}] \\

\tkzMeth{circle}{radical\_center(C1<,C2>)} & [\ref{ssub:radical_center}]  \\
\tkzMeth{circle}{pole(L)} & [\ref{ssub:method_circle_pole}]\\
\midrule
\texttt{Methods Returning a Line}  & \\
\midrule
\tkzMeth{circle}{radical\_axis(C)} &   [ \ref{ssub:method_circle_radical__axis_c} ; \ref{par:radical_axis_v1}; \ref{par:radical_axis_v2}; \ref{par:radical_axis_v3}; \ref{par:radical_axis_v4}]  \\
\tkzMeth{circle}{tangent\_at(pt)} &  [\ref{ssub:method_circle_tangent__at_pt}] \\
\tkzMeth{circle}{tangent\_from(pt)}&  [\ref{ssub:method_circle_tangent__from_pt}] \\
\tkzMeth{circle}{tangent\_parallel(L)}&  [\ref{ssub:method_circle_tangent_parallel}] \\
\tkzMeth{circle}{common\_tangent(C)}&  [\ref{ssub:common_tangent}] \\
\tkzMeth{circle}{polar()} & [\ref{ssub:method_circle_polar_pt}] \\
\bottomrule
\end{tabular}
\egroup

\newpage
\bgroup
\catcode`_=12
\small
\captionof{table}{Circle methods}\label{circle:methods 2}
\begin{tabular}{ll}
\toprule
\texttt{Methods Returning a Circle}&\\
\midrule
\tkzMeth{circle}{orthogonal\_from(pt)}  & [\ref{ssub:method_circle_orthogonal_from_pt}]\\
\tkzMeth{circle}{orthogonal\_through(pta,ptb)}&  [\ref{ssub:method_circle_orthogonal_through}]\\
\tkzMeth{circle}{midcircle(C)}  & [\ref{ssub:midcircle}; \ref{midcircle_diameter}] \\
\tkzMeth{circle}{radical\_circle(C1<,C2>)} &  [\ref{ssub:radical_circle}] \\
\tkzMeth{circle}{CPP(pt,pt)} & [\ref{ssub:method_c__c__pp}] \\
\tkzMeth{circle}{CCP(C,pt)} &[\ref{ssub:method_c_cc_p}]  \\
\tkzMeth{circle}{CLP(L,pt,<'inside'>)} & [\ref{ssub:method_c_lc_p}]  \\
\tkzMeth{circle}{CLL}& \ref{ssub:method_c_cll}\\
\tkzMeth{circle}{CCL}(C2, L) & \ref{ssub:CCL}\\
\tkzMeth{circle}{CCC(C2, C3[, opts])} &  \ref{ssub:CCC}\\
\tkzMeth{circle}{CCC\_gergonne}(C2, C3) &  \ref{ssub:CCC_gergonne}\\
\texttt{Methods Returning a Path} &     \\
\tkzMeth{circle}{path(pt,pt,nb)} &[\ref{ssub:circle_path}]  \\
\bottomrule
\end{tabular}
\egroup

\bgroup
\catcode`_=12
\small
\captionof{table}{Auxiliary functions for circle construction.}\label{circle:functions}
\begin{tabular}{ll}
\toprule
\texttt{Functions Returning two Points} &      \\
\midrule
\tkzFct{circle}{through(pt,r,<angle>)} &  See [\ref{ssub:function_code_through_and_code_diameter}] \\

\tkzFct{circle}{diameter(pt,pt,<'swap'> or <angle>)}&  See [\ref{ssub:function_code_through_and_code_diameter}] \\

\bottomrule
\end{tabular}
\egroup



Each method can be called using the dot syntax, such as \code{C.OA:antipode(z.P)} or \code{C.OA:radical\_axis(C1)}. Deprecated methods are retained for compatibility but should be avoided in new code.

\subsubsection{Method \tkzMeth{circle}{new}(pt, pt)}
\label{ssub:method_circle_new}

This method creates a new circle object defined by two points:
\begin{itemize}
\item the \emph{center} of the circle,
\item a \emph{point on the circumference}, referred to as \code{through}.
\end{itemize}
The radius is computed as the Euclidean distance between the two points. Internally, the circle object stores both the center and the defining point, and computes several useful attributes for further geometric constructions.

\vspace{1em}
\texttt{Short form: }

The function \code{circle(center, through)} is equivalent to \code{circle:new(center, through)} and is recommended for ease of use.
\begin{mybox}
\begin{verbatim}
C.OA = circle(z.O, z.A)
-- same as:
C.OA = circle:new(z.O, z.A)
\end{verbatim}
\end{mybox}

\texttt{Derived attributes: }


Once created, the circle object contains:
\begin{itemize}
\item \code{radius} — the distance from the center to the point,
\item \code{diameter} — twice the radius,
\item \code{opp} — the point diametrically opposite to \code{through},
\item \code{ct} — the directed segment from center to through point.
\end{itemize}
These attributes are computed automatically and accessible via dot notation (e.g., \code{C.OA.radius}, \code{C.OA.opp}).


\vspace{1em}

\begin{tkzexample}[latex=.5\textwidth]
\directlua{
  init_elements()
  z.O = point(0, 0)
  z.A = point(2, 1)
  C.OA = circle(z.O, z.A)}
\begin{center}
\begin{tikzpicture}[gridded]
 \tkzGetNodes
 \tkzDrawCircle(O,A)
 \tkzDrawPoints(A,O)
 \tkzLabelPoints[right](A,O)
\end{tikzpicture}
  \end{center}
\end{tkzexample}


\subsubsection{Functions \tkzFct{circle}{through} and \tkzFct{circle}{diameter}}
\label{ssub:function_code_through_and_code_diameter}

These two utility functions assist in defining circles based on minimal data. They do not return a circle object themselves but instead return a pair of points: the \emph{center} and a \emph{point through which the circle passes}. These can be directly passed to \code{circle(...)}, as shown below.

\begin{mybox}
\begin{verbatim}
C.OT = circle(through(z.O, 5))                      -- default angle = 0
C.OT = circle(through(z.O, 5, math.pi / 3))          -- point at 60°
C.OT = circle(diameter(z.A, z.B))                    -- through = B
C.OT = circle(diameter(z.A, z.B, "swap"))            -- through = A
\end{verbatim}
\end{mybox}

\textbf{1. Function \code{through(center, radius, <angle>])}}

Constructs a circle based on:
\begin{itemize}
  \item a center point,
  \item a radius (positive real),
  \item an optional angle (in radians) specifying the position of the point on the circumference.
\end{itemize}
If the angle is omitted, the point lies on the positive \(x\)-axis from the center (i.e., angle = 0).

\textbf{2. Function \code{diameter(A, B, <'swap'> or <angle>)}}

Constructs a circle using two diametrically opposed points. The function returns:

\begin{itemize}
  \item the midpoint of \([AB]\) as the center,
  \item one of the two points as the \code{through} point.
\end{itemize}

By default, the second argument (\code{B}) is returned as the \code{through} point. If the optional third argument \code{"swap"} is provided, the first point (\code{A}) is used instead. The optional angle (in radians) specifying the position of the point "through" on the circumference.

\vspace{1em}

\begin{tkzexample}[latex=6cm]
\directlua{
  z.A = point(0, 0)
  z.B = point(2, 1)
  C.T = circle(through(z.A, math.sqrt(5), math.pi / 2))
  C.a = circle(diameter(z.A, z.B))
  z.T = C.T.through
  C.b = circle(diameter(z.A, z.T, "swap"))
  z.w = C.a.center
  z.t = C.a.through
  z.u = C.b.center
  z.v = C.b.through}
\begin{tikzpicture}[gridded]
\tkzGetNodes
 \tkzDrawCircles(A,T w,t u,v)
 \tkzDrawPoints(A,B,T)
 \tkzLabelPoints[right](A,B,T)
\end{tikzpicture}
\end{tkzexample}

\subsubsection{Method \tkzMeth{circle}{radius(pt,r)}}
\label{ssub:method_circle_radius}

(Deprecated see above [\ref{ssub:function_code_through_and_code_diameter}])

This method has been retained for backward compatibility but is no longer recommended. It has been replaced by a more flexible and construction-oriented approach.

We define a circle with its centre and radius.

\vspace{1em}
\begin{tkzexample}[latex=.5\textwidth]
\directlua{
  init_elements()
  z.O = point(0, 0)
  z.A = point(2, 1)
  C.T = circle:radius(z.A, math.sqrt(5))
  % better
  % C.T = circle(from_radius(z.A, math.sqrt(5)))
  z.T = C.T.through }
\begin{center}
  \begin{tikzpicture}[gridded]
  \tkzGetNodes
  \tkzDrawCircles(A,T)
  \tkzDrawPoints(A,O,T)
  \tkzLabelPoints[right](A,O,T)
\end{tikzpicture}
\end{center}
\end{tkzexample}


\subsubsection{Method \tkzMeth{circle}{diameter(pt,pt)}}
\label{ssub:method_circle_diameter}

(Deprecated see above [\ref{ssub:function_code_through_and_code_diameter}])

This method has been retained for backward compatibility but is no longer recommended. It has been replaced by a more flexible and construction-oriented approach.

A circle is defined by two points at the ends of one of its diameters.

\vspace{1em}
\begin{tkzexample}[latex=.5\textwidth]
\directlua{
  init_elements()
  z.A = point(0, 0)
  z.B = point(2, 1)
  C.T = circle:diameter(z.A, z.B)
  % better C.T = from_diameter(z.A, z.B)
  z.O = C.T.center
  z.T = C.T.through}
\begin{center}
\begin{tikzpicture}[gridded]
 \tkzGetNodes
 \tkzDrawCircles(O,T)
 \tkzDrawPoints(A,B,O,T)
 \tkzLabelPoints[right](A,B,O,T)
\end{tikzpicture}
\end{center}
\end{tkzexample}

\subsection{Returns a boolean value}

\subsubsection{Method \tkzMeth{circle}{is\_tangent(L)}}
\label{ssub:method_circle_is_tangent}

This method checks whether a given line is tangent to the circle. It returns a boolean value: \code{true} if the line is tangent, and \code{false} otherwise.

\medskip

This is useful for logical tests and conditional constructions in Lua. The method uses geometric distance and precision tolerance to determine tangency.

\medskip

Example:

\begin{tkzexample}[latex=.5\textwidth]
\directlua{
  z.A = point(0, 0)
  z.B = point(0, 2)
  C.AB = circle(z.A, z.B)
  z.C = point(2, -2)
  z.D = point(2, 3)
  L.CD = line(z.C, z.D)
  if C.AB:is_tangent(L.CD) then
    tex.print("L.CD tangent to C.AB")
  else
    tex.print("L.CD no tangent to C.AB")
  end}
\begin{tikzpicture}
  \tkzGetNodes
  \tkzDrawCircle(A,B)
  \tkzDrawLines(C,D)
  \tkzDrawPoints(A,B,C,D)
  \tkzLabelPoints[below left](A,C)
  \tkzLabelPoints[above right](B,D)
\end{tikzpicture}
\end{tkzexample}

\subsubsection{Method \tkzMeth{circle}{is\_secant(L)}}
\label{ssub:method_circle_is_secant}
see the example above

\subsubsection{Method \tkzMeth{circle}{is\_disjoint(L)}}
\label{ssub:method_circle_is_disjoint}
see the example above

 \subsubsection{Method \tkzMeth{circle}{power(pt)}}
 \label{ssub:power}

 The \code{power} method computes the \emph{power of a point} with respect to the given circle. It is defined as:

 \[
 \text{power}(P) = |OP|^2 - r^2
 \]

 where $O$ is the center of the circle and $r$ its radius.

 \medskip

 The sign of the result allows us to determine the relative position of the point $P$:
 \begin{itemize}
   \item positive: the point lies outside the circle,
   \item zero: the point lies on the circle,
   \item negative: the point lies inside the circle.
 \end{itemize}

 \medskip

 Here is an example using a function to print this information:

 \vspace{1em}
\begin{minipage}{.65\textwidth}
\begin{verbatim}
\directlua{
 init_elements()
 z.O = point(0, 0)
 z.R = point(2, 0)
 z.A = point(1, 1)
 z.B = point(2, -1)
 C.OR = circle(z.O, z.R)
  function position(pt)
 if C.OR:power(pt) > 0
 then
   return tex.print("out")
  else
   return tex.print("in")
 end
  end}
\begin{tikzpicture}
  \tkzGetNodes
  \tkzDrawCircle(O,R)
  \tkzDrawPoints(A,O,B)
  \tkzLabelPoint(A){\tkzUseLua{position(z.A)}}
  \tkzLabelPoint(B){\tkzUseLua{position(z.B)}}
\end{tikzpicture}
\end{verbatim}
 \end{minipage}
 \begin{minipage}{.35\textwidth}
 \directlua{
 init_elements()
 z.O = point(0, 0)
 z.R = point(2, 0)
 z.A = point(1, 1)
 z.B = point(2, -1)
 C.OR = circle(z.O, z.R)
  function position(pt)
 if C.OR:power(pt)>0
 then
 return tex.print("out")
  else
 return tex.print("in")
  end
  end}
\begin{center}
\begin{tikzpicture}
   \tkzGetNodes
   \tkzDrawCircle(O,R)
   \tkzDrawPoints(A,O,B)
   \tkzLabelPoint(A){\tkzUseLua{position(z.A)}}
   \tkzLabelPoint(B){\tkzUseLua{position(z.B)}}
\end{tikzpicture}
\end{center}
\end{minipage}

%--------------------------------------------------------------------
\subsubsection{Method \tkzMeth{circle}{position(obj)}}
\label{ssub:circle_position}

This method determines the geometric relation between a circle and another object.
An optional argument \code{EPS} may be provided to adjust the numerical tolerance.
By default, \code{EPS} is the global value \tkzVar{tkz}{tkz.epsilon}.

\medskip
\texttt{Syntax:}

\verb|result = C:position(obj [, EPS])|

\medskip
\texttt{Supported object types and return values}

\begin{itemize}

\item \textbf{Point}

Returns one of:
\begin{itemize}
\item \code{"IN"}  — point strictly inside the disk,
\item \code{"ON"}  — point on the circumference,
\item \code{"OUT"} — point outside the disk.
\end{itemize}

\item \textbf{Line}

Returns one of:
\begin{itemize}
\item \code{"DISJOINT"} — no intersection,
\item \code{"TANGENT"}  — exactly one common point,
\item \code{"SECANT"}   — two intersection points.
\end{itemize}

\item \textbf{Circle}

Returns one of:
\begin{itemize}
\item \code{"DISJOINT\_EXT"} — exterior disjoint circles,
\item \code{"TANGENT\_EXT"}  — exterior tangency,
\item \code{"SECANT"}        — two intersections,
\item \code{"TANGENT\_INT"}  — interior tangency,
\item \code{"DISJOINT\_INT"} — one circle strictly inside the other,
\item \code{"CONCENTRIC"}    — same center, different radii,
\item \code{"COINCIDENT"}    — identical circles.
\end{itemize}

\end{itemize}

\medskip
\texttt{Remarks}

\begin{itemize}
\item Returned values are symbolic uppercase strings.
\item Results are tolerance-aware.
\item Unsupported object types raise an error.
\end{itemize}

\vspace{1em}

\begin{tkzexample}[latex=.5\textwidth]
\directlua{
  init_elements()
  z.O = point(0, 0)
  z.A = point(1 ,2)
  C.OA = circle(z.O, z.A)
  z.N = point(-2, 2)
  z.M = point(1, 0)
  z.P = point(2, 1)

  PCm = C.OA:position(z.M)
  PDm = C.OA:position_disk(z.M)
  PCn = C.OA:position(z.N)
  PDn = C.OA:position_disk(z.N)
  PCp = C.OA:position(z.P)
  PDp = C.OA:position_disk(z.P)
}

\def\tkzPosPoint#1#2#3#4{%
  \tkzLabelPoints(O,M,N,P)
  \tkzLabelPoint[below=#4pt,
  font=\scriptsize](#2){%
  \tkzUseLua{#1} on the #3}%
}

\begin{center}
  \begin{tikzpicture}
  \tkzGetNodes
  \tkzDrawSegments[dashed](O,M O,N O,P)
  \tkzDrawCircle(O,A)
  \tkzDrawPoints(O,M,N,P)

  \tkzPosPoint{PCm}{M}{circle}{8}
  \tkzPosPoint{PCn}{N}{circle}{8}
  \tkzPosPoint{PCp}{P}{circle}{8}

  \tkzPosPoint{PDm}{M}{disk}{14}
  \tkzPosPoint{PDn}{N}{disk}{14}
  \tkzPosPoint{PDp}{P}{disk}{14}
  \end{tikzpicture}
\end{center}
\end{tkzexample}


\subsubsection{Method \tkzMeth{circle}{in\_out} for circle and disk; Deprecated}
\label{ssub:in_out_for_circle_and_disk}

The following methods
\code{in\_out()}, \code{in\_out\_disk()},
\code{in\_disk(p)},  \code{in\_out\_disk(p)},
\code{in\_disk\_strict(p)} and
\code{out\_disk\_strict(p)}  have been replaced by \code{position} and  \code{position\_disk}. See [\ref{ssub:circle_position}]

\texttt{Note: } They still exist, but it is preferable to use \code{position}.

\subsubsection{Method \tkzMeth{circle}{line\_position(L)}}
\label{ssub:method_circle_line_position}

\texttt{Purpose: }

This method classifies the position of a line relative to a circle.

It returns whether the line is \texttt{disjoint}, \texttt{tangent} or \texttt{secant}.

\medskip
\texttt{Syntax: } \verb|pos = C.AB:line_position(L.CD)|

\medskip
\texttt{Arguments: }

 \texttt{L} — a \tkzname{line} object to be tested against the circle.

\medskip
\texttt{Return value: }

A string describing the relative position of the line:
\begin{itemize}
  \item \texttt{"DISJOINT"} — no intersection between line and circle,
  \item \texttt{"TANGENT"} — line tangent to the circle (one point of contact),
  \item \texttt{"SECANT"} — line intersecting the circle at two points.
\end{itemize}

\medskip
\texttt{Remarks: }

\begin{itemize}
  \item The radius is computed from the center and the defining point (\texttt{self.through})
        to ensure numerical stability.
  \item The tolerance \tkzVar{tkz}{tkz.epsilon} is used to handle rounding errors near tangency.
\end{itemize}

\medskip
\texttt{Example usage: }

\begin{tkzexample}[latex=.5\textwidth]
\directlua{
  z.A = point(0, 0)
  z.B = point(4, -2)
  L.AB  = line (z.A, z.B )
  z.O = point(2, 2)
  z.X = z.O + point(0,-2)
  C.OX = circle(z.O, z.X)
  tex.print(C.OX:line_position(L.AB))}
\begin{tikzpicture}[gridded]
 \tkzGetNodes
 \tkzDrawLines[blue](A,B)
 \tkzDrawCircle(O,X)
\end{tikzpicture}
\end{tkzexample}

\subsubsection{Method \tkzMeth{circle}{lines\_position(L1, L2, mode)}}
\label{ssub:method_circle_lines_position}

\texttt{Purpose: }

This method determines the relative position of a circle with respect to two lines.
It analyzes which angular or strip sectors are touched by the circle depending on whether the lines are parallel or secant.
The result is returned as a list of integers corresponding to the sectors intersected by the circle.

\texttt{Syntax: } \verb|sectors = C:lines_position(L1, L2 [, mode])|

\texttt{Arguments: }

\begin{itemize}
  \item \texttt{L1}, \texttt{L2} — two \tkzname{line} objects.
  \item \texttt{mode} — an optional string:
    \begin{itemize}
      \item \texttt{"parallel"} — if the lines are known to be parallel;
      \item any other value (or omitted) — default, for secant lines.
    \end{itemize}
\end{itemize}

\texttt{Return value: }

A Lua table (list of integers) representing the indices of the sectors touched by the circle.

\medskip
For secant lines:
\begin{itemize}
  \item sectors are numbered counterclockwise from the first line to the second:
        \texttt{1, 2, 3, 4};
  \item for example, \texttt{\{1\}} means the circle is entirely inside the first sector,
        and \texttt{\{4, 1, 2\}} means the circle touches three adjacent sectors.
\end{itemize}

For parallel lines:
\begin{itemize}
  \item sectors are numbered as:
        \texttt{1} – between the lines,
        \texttt{2} – outside on the side of \texttt{L1},
        \texttt{3} – outside on the side of \texttt{L2};
  \item examples:
        \texttt{\{1\}} → circle entirely between the lines;
        \texttt{\{1,2\}} → tangent to \texttt{L1};
        \texttt{\{1,2,3\}} → circle large enough to cross both lines.
\end{itemize}

\texttt{Remarks: }

\begin{itemize}
  \item The classification is purely geometric and does not compute intersection points.
  \item The tolerance \tkzVar{tkz}{tkz.epsilon} is used to handle numerical approximations in tangency detection.
\end{itemize}

\texttt{Example (secant lines)}

\begin{tkzexample}[latex=.48\textwidth]
\directlua{
  z.A = point(0, 0)
  z.B = point(3, -2)
  L.AB  = line (z.A, z.B)
  z.C = point(-2, 3)
  z.D = point(3, 1)
  L.CD  = line (z.C, z.D)
  z.O = point(2, 4)
  z.X = z.O + point(0, -1)
  C.OX = circle(z.O, z.X)
  tex.print(C.OX:lines_position(L.AB, L.CD))}
\begin{tikzpicture}
 \tkzGetNodes
 \tkzDrawLines[blue](A,B)
 \tkzDrawLines[red](C,D)
 \tkzDrawCircle(O,X)
 \tkzDrawPoints[red,size=4](A,B,C,D)
 \tkzLabelPoints(A,B,C,D)
\end{tikzpicture}
\end{tkzexample}

\texttt{Example (parallel lines)}

\begin{tkzexample}[latex=.48\textwidth]
\directlua{
  z.A = point(0,0)
  z.B = point(4,0)
  L.AB = line(z.A, z.B)
  z.C = point(0,3)
  z.D = point(4,3)
  L.CD = line(z.C, z.D)
  z.O = point(2,1.5)
  z.T = z.O + point(0,1)
  C.OT = circle(z.O, z.T)
  local s = C.OT:lines_position(L.AB,
                    L.CD, "parallel")
  tex.print(s)}
\begin{tikzpicture}
  \tkzGetNodes
  \tkzDrawLines[blue](A,B C,D)
  \tkzDrawCircle(O,T)
\end{tikzpicture}
\end{tkzexample}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Returns a real number}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\subsubsection{Method \tkzMeth{circle}{power(pt)}}
\label{ssub:method_circle_power_pt}

The \emph{power of a point} $A$ with respect to a circle of radius~$r$ and center~$O$ is a classical notion in Euclidean geometry.

\medskip

It is defined as the scalar quantity:

\[
p = \overline{AP} \cdot \overline{AQ} = AM^2 - r^2
\]

where:
\begin{itemize}
  \item $P$ and $Q$ are the points of intersection of the circle with a line passing through $A$,
  \item $M$ is the center $O$ of the circle (so $AM^2 = |AO|^2$),
  \item and $AT$ is a tangent from $A$ to the circle, satisfying $AT^2 = AM^2 - r^2$.
\end{itemize}


Geometrically:
\begin{itemize}
  \item If $A$ lies outside the circle, the power is positive.
  \item If $A$ lies on the circle, the power is zero.
  \item If $A$ lies inside the circle, the power is negative.
\end{itemize}

\medskip

In Lua, this is evaluated by calling:

\begin{center}
\code{p = C.XY:power(z.A)}
\end{center}


This value can be used for algebraic computations or to test point inclusion via its sign.

\vspace{1em}

\begin{minipage}{.5\textwidth}
\begin{verbatim}
  \directlua{
  init_elements()
  z.O = point(5, 0)
  z.A = point(0, 0)
  z.R = point(7, 0)
  C.OR = circle(z.O, z.R)
  z.Q = C.OR:point(0.15)
  L.AQ = line(z.A, z.Q)
  _, z.P = intersection(C.OR,L.AQ)
  L.T = C.OR:tangent_from(z.A)
  z.T = L.T.pb}
  \begin{tikzpicture}
  \tkzGetNodes
  \tkzDrawCircle(O,T)
  \tkzDrawPoints(A,O,P,Q,T)
  \tkzDrawSegments(A,O A,Q A,T)
  \tkzLabelPoints(A,O,P,Q,T)
  \tkzText(2,2){$p =\tkzUseLua{%
    C.OR:power(z.A)} =AT^2=AP * AQ$}
  \end{tikzpicture}
\end{verbatim}

\end{minipage}
\begin{minipage}{.5\textwidth}
  \directlua{
  init_elements()
  z.O = point(5,0)
  z.A = point(0,0)
  z.R = point(7,0)
  C.OR = circle(z.O, z.R)
  z.Q = C.OR:point(0.15)
  L.AQ = line(z.A, z.Q)
  _, z.P = intersection(C.OR,L.AQ)
  L.T = C.OR:tangent_from(z.A)
  z.T = L.T.pb}

  \begin{center}
    \begin{tikzpicture}
    \tkzGetNodes
    \tkzDrawCircle(O,T)
    \tkzDrawPoints(A,O,P,Q,T)
    \tkzDrawSegments(A,O A,Q A,T)
    \tkzLabelPoints(A,O,P,Q,T)
    \tkzText(2,2){$p =\tkzUseLua{%
     C.OR:power(z.A)} =AT^2=AP * AQ$}
    \end{tikzpicture}
  \end{center}
\end{minipage}


\subsection{Returns a string}

\subsubsection{Method \tkzMeth{circle}{circles\_position}}
\label{ssub:circles_position}

This function returns a string indicating the position of the circle in relation to another. Useful for creating a function. Cases are:

\begin{itemize}
   \item \code{outside}
   \item \code{outside tangent}
   \item \code{inside tangent}
   \item \code{inside}
   \item \code{intersect}
\end{itemize}

\begin{minipage}{.55\textwidth}
\begin{verbatim}
\directlua{
init_elements()
   z.A = point(0, 0)
   z.a = point(3, 0)
   z.B = point(2, 0)
   z.b = point(3, 0)
   C.Aa = circle(z.A, z.a)
   C.Bb = circle(z.B, z.b)
   position = C.Aa:circles_position(C.Bb)
   if position == "inside tangent"
   then color = "orange"
   else color = "blue" end}
\begin{tikzpicture}
  \tkzGetNodes
  \tkzDrawCircle(A,a)
  \tkzDrawCircle[color=\tkzUseLua{color}](B,b)
\end{tikzpicture}
\end{verbatim}
\end{minipage}
\begin{minipage}{.45\textwidth}
\directlua{
init_elements()
z.A = point(1, 0)
z.a = point(3, 0)
z.B = point(2, 0)
z.b = point(3, 0)
C.Aa = circle(z.A, z.a)
C.Bb = circle(z.B, z.b)
position = C.Aa:circles_position(C.Bb)
if position == "inside tangent" then color = "orange" else color = "blue" end}


\begin{center}
  \begin{tikzpicture}
  \tkzGetNodes
  \tkzDrawCircle(A,a)
  \tkzDrawCircle[color=\tkzUseLua{color}](B,b)
  \end{tikzpicture}
\end{center}

\end{minipage}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%  Points %%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\subsection{Returns a point}

\subsubsection{Method \tkzMeth{circle}{get()}}
\label{ssub:method_circle_get}

This method retrieves the defining points of a circle.
A circle is determined by its center and one point on its circumference.

\begin{itemize}
  \item \code{C:get()} returns the center and a point through which the circle passes.
  \item \code{C:get(1)} returns the center of the circle.
  \item \code{C:get(2)} returns the point on the circumference.
\end{itemize}

This method is useful whenever the geometric definition of a circle needs to be reused, for instance when constructing tangents, radical axes, or when passing circle data to other constructions.
It provides a simple and consistent way to access the fundamental points that define a circle.



\subsubsection{Method \tkzMeth{circle}{antipode}}
\label{ssub:method_circle_antipode}
This method is used to define a point that is diametrically opposed to a point on a given circle.

\vspace{1em}
\begin{tkzexample}[latex=.5\textwidth]
\directlua{
  init_elements()
  z.A = point(0, 0)
  z.O = point(2, 1)
  C.OA = circle(z.O, z.A)
  z.B = C.OA:antipode(z.A)}
\begin{center}
\begin{tikzpicture}[gridded]
  \tkzGetNodes
  \tkzDrawCircles(O,A)
  \tkzDrawPoints(A,B,O)
  \tkzLabelPoints[right](A,B,O)
\end{tikzpicture}
\end{center}
\end{tkzexample}

\subsubsection{Method \tkzMeth{circle}{midarc}}
\label{ssub:method_circle_midarc}

The classical definition, as found in \href{https://mathworld.wolfram.com/Mid-ArcPoints.html}{MathWorld}, is the following:

\medskip
\begin{quote}
The mid-arc points of a triangle, as defined by Johnson (1929), are the points on the circumcircle of the triangle that lie halfway along each of the three arcs determined by the triangle's vertices. These points arise in the definitions of the Fuhrmann circle and Fuhrmann triangle, and they lie on the extensions of the perpendicular bisectors of the triangle sides drawn from the circumcenter.
\end{quote}

\medskip

In the present context, the definition is generalized. The method returns the point on a circle that divides a given arc into two equal arcs in terms of angular measure. In other words, it computes the midpoint (in angle) of the arc defined by two points on the circle.

\medskip

This method is applicable to any pair of points on a circle, not just those associated with triangle vertices or circumcircles.

\vspace{1em}
\begin{tkzexample}[latex=.5\textwidth]
\directlua{
  init_elements()
  z.A = point(0, 0)
  z.O = point(2, 1)
  C.OA = circle(z.O, z.A)
  z.B = C.OA:point(0.25)
  z.M = C.OA:midarc(z.A, z.B)}
\begin{center}
\begin{tikzpicture}[gridded]
  \tkzGetNodes
  \tkzDrawCircles(O,A)
  \tkzDrawPoints(A,B,O,M)
  \tkzLabelPoints[right](A,B,O,M)
\end{tikzpicture}
  \end{center}
\end{tkzexample}

\subsubsection{Method \tkzMeth{circle}{point(r,<pt>)}}
\label{ssub:method_circle_point}

Let $C$ be a circle with centre $O$ and passing through $A$ such that $z.A = C.through$.

This method defines a point $M$ on the circle such that the ratio of the length of the arc to the circumference of the circle is equal to $r$.

By default, the arc is measured from the reference point $A$.
An optional parameter \texttt{pt} allows the user to specify another starting point on the circle.

Thus, if \texttt{pt} is provided, the point $M$ is defined such that
the ratio of the length of the arc $\widearc{(\texttt{pt})M}$ to the circumference is equal to $r$.

In the next example, $r=\dfrac{1}{6}$ corresponds to $\dfrac{\pi/3}{2\pi}$, so the angle $\widehat{AOB}$ has measure $\pi/3$.

If $r=0.5$, the defined point is diametrically opposite to the reference point.

\vspace{1em}
\begin{tkzexample}[latex=.5\textwidth]
\directlua{
 init_elements()
 z.O = point(0, 0)
 z.A = point(1, 2)
 z.E = point(-1, 2)
 C.OA = circle(z.O, z.A)
 z.B = C.OA:point(1 / 6)
 % from A (default)
 z.C = C.OA:point(0.25)
 z.D = C.OA:point(0.5)
 z.F = C.OA:point(1 / 6, z.E)
 % from E (custom origin)
}
\begin{center}
\begin{tikzpicture}
\tkzGetNodes
\tkzDrawCircle(O,A)
\tkzDrawPoints(A,...,F,O)
\tkzLabelPoints(A,...,F,O)
\end{tikzpicture}
\end{center}
\end{tkzexample}



\subsubsection{Method \tkzMeth{circle}{random(<'inside'>)}}
\label{ssub:method_imeth_circle_random_inside}
Produces a point on the circle or inside the disc with the 'inside' option.

\begin{minipage}{.5\textwidth}
\directlua{
  init_elements()
  z.O = point(0, 2)
  z.A = point(2, 1)
  C.OA = circle(z.O, z.A)
  z.M = C.OA:random()
  z.N = C.OA:random('inside')}
\begin{center}
\begin{tikzpicture}
   \tkzGetNodes
   \tkzDrawCircle(O,A)
   \tkzDrawPoints(O,A,M,N)
   \tkzLabelPoints(O,A,M,N)
\end{tikzpicture}
\end{center}
\end{minipage}
\begin{minipage}{.5\textwidth}
\begin{tkzexample}[code only]
\directlua{
  init_elements()
  z.O = point(0, 2)
  z.A = point(2, 1)
  C.OA = circle(z.O, z.A)
  z.M = C.OA:random()
  z.N = C.OA:random('inside')}
\end{tkzexample}
\end{minipage}

\subsubsection{Method \tkzMeth{circle}{internal\_similitude(C)}}
\label{ssub:method_circle_internal__similitude}

This method computes the \textbf{internal center of similitude} of two given circles.

\medskip

Two circles (in general position) always admit two homothetic centers:
\begin{itemize}
  \item the \textbf{internal center of similitude}, which lies between the two centers and divides the segment joining them internally in the ratio of their radii,
  \item the \textbf{external center of similitude}, which lies outside the segment and divides it externally in the same ratio.
\end{itemize}


These centers lie on the line joining the centers of the two circles, called the \emph{line of centers}.

\medskip

This method returns the internal homothetic center — the point from which the two circles appear in the same direction and proportion, as though one were scaled into the other internally.

\medskip

\emph{Note:} Degenerate cases (e.g., equal centers, equal or zero radii) are handled separately.
\begin{flushright}
\small
\href{https://en.wikipedia.org/wiki/Homothetic_center}{\textit{(See also: Wikipedia — Homothetic center)}}
\end{flushright}

\vspace{1em}


\begin{tkzexample}[latex=.5\textwidth]
\directlua{
  init_elements()
  z.A = point(0, 0)
  z.a = point(2, 2)
  z.B = point(5 , 2)
  z.b = point(6 , 1)
  C.Aa = circle(z.A, z.a)
  C.Bb = circle(z.B, z.b)
  z.I = C.Aa:internal_similitude(C.Bb)
  L.TA1, L.TA2 = C.Aa:tangent_from(z.I)
  z.A1 = L.TA1.pb
  z.A2 = L.TA2.pb}
 \begin{center}
 \begin{tikzpicture}[ scale =.6]
   \tkzGetNodes
   \tkzDrawCircles(A,a B,b)
  \tkzDrawPoints(A,a,B,b,I,A1,A2)
  \tkzDrawLines[add = 1 and 2](A1,I A2,I)
 \end{tikzpicture}
 \end{center}
\end{tkzexample}

\subsubsection{Method \tkzMeth{circle}{external\_similitude(C)}}
\label{ssub:method_circle_external__similitude}


This method computes the \textbf{external center of similitude} of two given circles.

\medskip

As with the internal case, two circles in general position admit two homothetic centers. The external center of similitude lies on the \emph{line of centers}, but outside the segment joining the two centers.

\medskip

It divides this line \emph{externally} in a ratio equal to that of the radii of the circles. This center is the unique point from which the two circles appear as scaled images of each other in opposite orientations.

\medskip

This construction is essential in many geometric transformations (e.g., inversion, similarity, coaxal systems) and in the theory of midcircles and Apollonius circles.

\medskip

\emph{Note:} As with the internal center, degenerate cases such as identical centers or zero radius are handled separately.

\vspace{1em}

\begin{tkzexample}[latex=.5\textwidth]
\directlua{
  init_elements()
  z.A = point (0 , 0 )
  z.a = point (2 , 2)
  z.B = point (3 , 2 )
  z.b = point(3.5, 1 )
  C.Aa = circle(z.A, z.a)
  C.Bb = circle(z.B, z.b)
  z.I = C.Aa:external_similitude(C.Bb)
  L.TA1,L.TA2 = C.Aa:tangent_from(z.I)
  z.A1 = L.TA1.pb
  z.A2 = L.TA2.pb}
\begin{center}
\begin{tikzpicture}[scale = .75]
\tkzGetNodes
\tkzDrawCircles(A,a B,b)
\tkzDrawPoints(A,a,B,b,I,A1,A2)
\tkzDrawLines[add = .25 and .1](A1,I A2,I)
\end{tikzpicture}
\end{center}
\end{tkzexample}

\subsubsection{Method \tkzMeth{circle}{similitude(C,mode)}}
\label{ssub:similitude}

This method unifies the two similitude-center functions.

\begin{itemize}
  \item \code{mode = "internal"} returns the internal center of similitude.
  \item \code{mode = "external"} returns the external center of similitude.
\end{itemize}

\medskip
\noindent\texttt{Example: }
\begin{verbatim}
S  = C1:similitude(C2, "internal")
Se = C1:similitude(C2, "external")
\end{verbatim}


\subsubsection{Method \tkzMeth{circle}{radical\_center(C1, C2)}}
\label{ssub:radical_center}

In classical geometry, the \textbf{radical center} (also called the \emph{power center}) of three circles is the unique point of concurrency of their pairwise radical axes.

\medskip

This fundamental result, attributed to Gaspard Monge (see Dörrie 1965, p.153), states that:
\begin{quote}
The radical axes of any three circles (no two of which have the same center) intersect in a single point — the radical center.
\end{quote}


(See also: \href{https://mathworld.wolfram.com/RadicalCenter.html}{MathWorld — Radical Center})

\medskip

In this implementation, the method \code{radical\_center(C1, C2)} also has a
well-defined meaning when applied to only two circles.
The point returned by
\[
\code{z.P = C1:radical\_center(C2)}
\]
is the intersection of the \emph{radical axis} of the two circles with the line
joining their centres.

This point may be regarded as an \emph{extended radical center}.
It is the centre of a distinguished circle orthogonal to both given circles.
This circle belongs to the coaxial pencil of circles orthogonal to
\code{C1} and \code{C2}; its intersections with the line joining the centres
coincide with the two fixed base points of this pencil.

The construction naturally extends to the case of a circle and a point.
A point $P$ is interpreted as a \emph{circle-point}, that is, a circle of zero
radius:
\[
\code{z.P = point(a,b)}, \qquad \code{C.P = circle(z.P,z.P)}.
\]
In this setting, the radical center is the centre of the unique circle
orthogonal to the given circle and passing through the point $P$.


\medskip

This point is useful for constructions involving inversion, coaxal systems, and special configurations such as the Apollonius circle.

\texttt{Example, with three circles, two circles and one circle and a point}

\begin{tkzexample}[vbox]
\directlua{
 z.A = point(0, 0)
 z.a = z.A + point (1, 0)
 z.B = point (4, 1)
 z.b = z.B + point (2, 0)
 z.C = point (2, 6)
 z.c = z.C + point (3, 0)
 C.Aa = circle(z.A, z.a)
 C.Bb = circle(z.B, z.b)
 C.Cc = circle(z.C, z.c)
 L.rAB = C.Aa:radical_axis(C.Bb)
 L.rAC = C.Aa:radical_axis(C.Cc)
 L.rBC = C.Bb:radical_axis(C.Cc)
 z.w = C.Aa:radical_center(C.Bb, C.Cc)
 z.x1, z.y1 = L.rAB:get()
 z.x2, z.y2 = L.rAC:get()
 z.x3, z.y3 = L.rBC:get()
 z.t = C.Aa:radical_circle(C.Bb, C.Cc).through
 z.w1, z.t1 = C.Aa:radical_circle(C.Bb):get()
 C.B = circle(z.B, z.B)
 z.w2, z.t2 = C.Aa:radical_circle(C.B):get()}
\begin{center}
\begin{tikzpicture}
   \tkzGetNodes
   \tkzDrawCircles[blue](A,a B,b C,c)
   \tkzDrawCircles[red](w,t)
   \tkzDrawCircles[orange](w1,t1)
   \tkzDrawCircles[purple](w2,t2)
   \tkzDrawLines[red](x1,y1 x2,y2 x3,y3)
   \tkzDrawPoints(A,B,C,w,w1,w2)
   \tkzLabelPoints[below right](A,B,C,w,w1,w2)
\end{tikzpicture}
\end{center}
\end{tkzexample}


\subsubsection{Method \tkzMeth{circle}{pole(L)}}
\label{ssub:method_circle_pole}

\texttt{Syntax:}
\begin{verbatim}
P = circle:pole(L)
\end{verbatim}

\texttt{Purpose:}
Compute the \emph{pole} of a line \(L\) with respect to the current circle.
The pole is the point whose polar is exactly the line \(L\).

\medskip
\texttt{Arguments:}
\begin{itemize}
  \item \code{L} --- a line object.
\end{itemize}

\medskip
\texttt{Returns:}
\begin{itemize}
  \item the point \(P\) such that the polar of \(P\) w.r.t.\ the circle is \(L\);
  \item or \code{nil,"INFINITE"} if the line passes through the circle’s center.
\end{itemize}

\medskip
\texttt{Geometric principle:}
Let \(O\) be the center of the circle and \(R\) its radius.
Denote by \(H\) the orthogonal projection of \(O\) onto the line \(L\).
If \(H \neq O\), the inversion of \(H\) in the circle,
satisfying \(OH \cdot OP = R^2\),
is the pole \(P\) of line \(L\).

\[
P = \mathrm{Inv}_{(O,R)}(H),
\qquad \text{with } H = \mathrm{proj}_L(O)
\]

If \(H = O\) (i.e.\ the line passes through the center),
the pole is an \emph{ideal point} on the perpendicular to \(L\) through \(O\).



\medskip
\texttt{Example:}

\directlua{
 init_elements()
 z.A = point(0, 0)
 z.B  = point(-1, 2)
 C.AB = circle(z.A, z.B)
 z.C =  point(0, -4)
 z.D =  point(5, 0)
 L.CD = line(z.C, z.D)
 z.P = C.AB:pole(L.CD)}
\begin{center}
 \begin{tikzpicture}
\tkzGetNodes
\tkzDrawCircles(A,B)
\tkzDrawLines(C,D)
\tkzDrawPoints(A,...,D,P)
\tkzLabelPoints(A,...,D,P)
\end{tikzpicture}
 \end{center}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%  Lines %%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\subsection{Returns a line}

\subsubsection{Method \tkzMeth{circle}{tangent\_at(pt)}}
\label{ssub:method_circle_tangent__at_pt}

This method constructs the tangent to a circle at a given point on its circumference.

\medskip

The result is a straight line segment centered at the point of contact. Its two endpoints are placed symmetrically at equal distances from the contact point, which facilitates drawing and labeling.

\medskip

In the example below, the points \code{Tx} and \code{Ty} are the two endpoints of the tangent segment at the point of contact.

\medskip

This method is useful for highlighting tangency in diagrams, constructing tangent directions, or defining orthogonal projections.

\vspace{1em}


\begin{minipage}{.5\textwidth}
\directlua{
 init_elements()
 z.A = point(0,0)
 z.B = point(1,2)
 C.AB = circle(z.A, z.B)
 L.T = C.AB:tangent_at(z.B)
 z.Tx, z.Ty = L.T:get()}
\begin{tikzpicture}
\tkzGetNodes
\tkzDrawCircle(A,B)
\tkzDrawLines[add =.25 and .25](Tx,Ty)
\tkzDrawSegments[dashed](A,B)
\tkzDrawPoints(A,B)
\tkzLabelPoints[below left](A)
\tkzLabelPoints[above right](B)
\tkzMarkRightAngles(A,B,Tx)
\end{tikzpicture}
\end{minipage}
\begin{minipage}{.5\textwidth}
\begin{tkzexample}[code only]
\directlua{
 init_elements()
 z.A = point(0,0)
 z.B = point(1,2)
 C.AB = circle(z.A, z.B)
 L.T = C.AB:tangent_at(z.B)
 z.Tx, z.Ty = L.T:get()}
\end{tkzexample}
\end{minipage}

\subsubsection{Method \tkzMeth{circle}{tangent\_from(pt)}}
\label{ssub:method_circle_tangent__from_pt}

This method computes the two tangents from a point external to a given circle.

\medskip

Given a point $P$ lying outside the circle, there exist exactly two lines passing through $P$ and tangent to the circle. This method returns these two tangent lines, each defined by $P$ and the point of contact with the circle.

\medskip

The points of contact are also accessible as the endpoints of these lines. These are the unique points where the tangents touch the circle and are orthogonal to the radius.

\medskip

This construction is useful in many classical geometric configurations (radical axis, triangle incircle tangents, etc.).

\vspace{1em}


\begin{minipage}{.5\textwidth}
\directlua{
 init_elements()
 z.A = point(0,0)
 z.B = point(1,2)
 C.AB = circle(z.A, z.B)
 z.C = point(3,-2)
 L.T1,L.T2 = C.AB:tangent_from(z.C)
 z.T1 = L.T1.pb
 z.T2 = L.T2.pb}
\begin{center}
  \begin{tikzpicture}
  \tkzGetNodes
  \tkzDrawCircle(A,B)
  \tkzDrawLines[add =.5 and .5](C,T1 C,T2)
  \tkzDrawSegments[dashed](A,T1 A,T2)
  \tkzDrawPoints(A,...,C,T1,T2)
  \tkzLabelPoints[below left](A,T2,C)
  \tkzLabelPoints[above right](B,T1)
  \tkzMarkRightAngles(A,T1,C A,T2,C)
  \end{tikzpicture}
\end{center}

\end{minipage}
\begin{minipage}{.5\textwidth}
\begin{tkzexample}[code only]
\directlua{
 init_elements()
 z.A = point(0,0)
 z.B = point(1,2)
 C.AB = circle(z.A, z.B)
 z.C = point(3,-2)
 L.T1,L.T2 = C.AB:tangent_from(z.C)
 z.T1 = L.T1.pb
 z.T2 = L.T2.pb}
\end{tkzexample}
\end{minipage}

\subsubsection{Method \tkzMeth{circle}{tangent\_parallel(line)}}
\label{ssub:method_circle_tangent_parallel}
This method constructs the two tangents to a circle that are \emph{parallel} to a given direction (provided as a line).
\medskip

Each tangent is returned as a straight line segment centered at its point of contact with the circle. For convenience of drawing and labeling, the two endpoints of every tangent segment are placed symmetrically at equal distances from the contact point.
\medskip


\begin{verbatim}
 L1, L2 = C:tangent_parallel(Ldir)
\end{verbatim}

\begin{tkzexample}[latex = .5\textwidth]
\directlua{
 init_elements()
 z.A = point(0, 0)
 z.B = point(4, 4)
 L.AB = line(z.A, z.B)
 z.O = point(3, -2)
 z.T = point(3, 0)
 C.OT = circle(z.O, z.T)
 L.T1, L.T2 = C.OT:tangent_parallel(L.AB)
 z.x, z.y = L.T1:get()
 z.u, z.v = L.T2:get()
 z.M = L.T1.mid
 z.N = L.T2.mid}
\begin{center}
\begin{tikzpicture}[scale=.5]
\tkzGetNodes
\tkzDrawCircle(O,T)
\tkzDrawLines(A,B x,y u,v)
\tkzDrawPoints(O,A,B,M,N)
\tkzLabelPoints(O,A,B,M,N)
\end{tikzpicture}
\end{center}
\end{tkzexample}


\subsubsection{Method \tkzMeth{circle}{commun\_tangent(C)}}
\label{ssub:common_tangent}

This method constructs a \textbf{common tangent} to two circles.
It used to return only external tangents; the new version supports three options for \verb|mode|:
\verb|"external"| (default), \verb|"internal"|, and \verb|"both"|.
The number of solutions depends on the relative position of the circles and ranges from 0 to 4.
\medskip

Typical cases:
\begin{itemize}
\small
\item \textbf{Disjoint (separate) circles:} 4 tangents (2 external, 2 internal).
\item \textbf{Externally tangent circles (touch at one point):} 3 tangents (2 external, 1 internal).
\item \textbf{Intersecting circles (two crossings):} 2 tangents (both external).
\item \textbf{Internally tangent circles (one inside, touching):} 1 tangent (external).
\item \textbf{One circle strictly contained in the other (no contact):} 0 tangents.
\end{itemize}

Notes and conventions:
\begin{itemize}
\item \verb|mode="external"| returns the external common tangents; \verb|mode="internal"| returns the internal ones.
\item Degenerate cases are handled explicitly: coincident circles yield infinitely many common tangents (undefined), concentric circles with distinct radii yield none.
\item When radii are equal and circles are disjoint, there are still 4 tangents; the external homothety center is at infinity, which may influence the construction method but not the result.
\end{itemize}

\medskip


\begin{tkzexample}[latex=.45\textwidth]
\directlua{
 init_elements()
 z.A = point(0, 0)
 z.a = point(4, 0)
 z.B = point(6, 0)
 z.b = point(5, 0)
 C.Aa = circle(z.A, z.a)
 C.Bb = circle(z.B, z.b)
 L.Tx, L.Ty = C.Aa:
    common_tangent(C.Bb,"external")
 z.x, z.y = L.Tx:get()
 z.xp, z.yp = L.Ty:get()
 L.Tu, L.Tv = C.Aa:
    common_tangent(C.Bb,"internal")
 z.u, z.v = L.Tu:get()
 z.up, z.vp = L.Tv:get()}
\begin{center}
\begin{tikzpicture}[scale =.5]
  \tkzGetNodes
  \tkzDrawCircles(A,a B,b)
  \tkzDrawLines[red](x,y x',y' u,v u',v')
  \tkzDrawPoints(x,y,x',y',u,v,u',v')
\end{tikzpicture}
\end{center}
\end{tkzexample}


\texttt{Application: }
\medskip

Let $T$ and $T'$ be the points of tangency of a common external tangent to two circles, chosen such that $T$ lies on the first circle and $T'$ on the second, both on the same side. Consider a secant parallel to this tangent passing through a fixed point $C$ (typically the center of one of the circles).

\medskip

In this configuration, the segment $[TT']$ is seen from the other intersection point $D$ (of the secant with the second circle) under an angle equal to \emph{half the angle between the two given circles}.

\medskip

This elegant geometric relationship is used in the construction of tangents and angle bisectors associated with pairs of circles.

\vspace{1em}


\begin{minipage}{.55\textwidth}
\directlua{
init_elements()
z.A = point(0 , 0 )
z.B = point(5 , 2 )
L.AB = line(z.A, z.B)
z.C = point(1, 2)
C.AC = circle(z.A, z.C)
C.BC = circle(z.B, z.C)
L.TTp = C.AC:common_tangent(C.BC)
z.T, z.Tp = L.TTp:get()
z.M = C.AC:point(0.45)
L.MC =line(z.M, z.C)
z.Mp = intersection(L.MC, C.BC)
L.mm = L.TTp:ll_from(z.C)
_, z.M = intersection(L.mm, C.AC)
z.Mp = intersection(L.mm, C.BC)
_, z.D = intersection(C.AC,C.BC)}
\begin{center}
  \begin{tikzpicture}[scale =.75]
  \tkzGetNodes
  \tkzDrawCircles(A,C B,C)
  \tkzDrawSegments(M,M' A,D B,D A,B C,D
    T,C T',C)
  \tkzDrawSegments[gray](D,M D,M' T,T'
    D,T D,T')
  \tkzDrawPoints(A,B,C,D,M,M',T,T')
  \tkzLabelPoints(A,B,D,M)
  \tkzLabelPoints[above](C,M',T,T')
  \tkzMarkAngles[mark=|,size=.75](T,C,M C,T,T'
       C,D,T T,D,M)
  \tkzMarkAngles[mark=||,size=.75](M',C,T'
  T,T',C T',D,C M',D,T')
\end{tikzpicture}
\end{center}
\end{minipage}
\begin{minipage}{.4\textwidth}
\begin{tkzexample}[code only]
\directlua{
init_elements()
z.A = point(0 , 0 )
z.B = point(5 , 2 )
L.AB = line(z.A, z.B)
z.C = point(1, 2)
C.AC = circle(z.A, z.C)
C.BC = circle(z.B, z.C)
L.TTp = C.AC:common_tangent(C.BC)
z.T, z.Tp = L.TTp:get()
z.M = C.AC:point(0.45)
L.MC =line(z.M, z.C)
z.Mp = intersection(L.MC, C.BC)
L.mm = L.TTp:ll_from(z.C)
_, z.M = intersection(L.mm, C.AC)
z.Mp = intersection(L.mm, C.BC)
_, z.D = intersection(C.AC,C.BC)}
\end{tkzexample}
\end{minipage}

\subsubsection{Method \tkzMeth{circle}{polar(pt)}}
\label{ssub:method_circle_polar_pt}

In projective geometry, the notions of \emph{pole} and \emph{polar} see  a duality between points and lines with respect to a conic section.

\medskip

In the special case of a circle, this duality becomes particularly elegant. The method \code{polar(pt)} computes the \textbf{polar line} of a given point with respect to the circle.

\medskip

This construction is based on \textbf{inversion} in the circle:
\begin{itemize}
  \item The \textbf{polar line} of a point $Q$ (not at the center) is defined as the line orthogonal to the radius through $Q$, passing through the \emph{inverse} of $Q$ with respect to the circle.
  \item Conversely, the \textbf{pole} of a line $L$ (not passing through the center) is the inverse (in the circle) of the foot of the perpendicular from the center to the line.
\end{itemize}


This method currently only supports the case where a \emph{point} is provided as argument. The result is a line — the polar of that point.

\medskip

(See also: \href{https://en.wikipedia.org/wiki/Pole_and_polar}{Wikipedia — Pole and polar})

\vspace{1em}


\begin{tkzexample}[latex = .5\textwidth]
\directlua{
 init_elements()
 z.o = point(-1,1)
 z.t = point(1,3)
 z.P = point(3.2,0)
 C.o = circle(z.o, z.t)
 L.P = C.o:polar(z.P)
 z.a, z.b = L.P:get()
 z.u, z.v = intersection(C.o,L.P)
 z.K = L.P:projection(z.P)
 L.K = C.o:polar(z.K)
 z.ka, z.kb = L.K:get()
 C.wH = C.o:inversion(L.P)
 z.w, z.H = C.wH:get()
 z.ap, z.bp = C.o:inversion(z.a, z.b)
 L.oa = line(z.o, z.a)
 z.cp = intersection(L.K,L.oa)
 z.c = C.o:inversion(z.cp)}
\begin{center}
\begin{tikzpicture}
  \tkzGetNodes
  \tkzDrawCircles[red,thick](o,t)
  \tkzDrawCircles(w,H)
  \tkzDrawLines[red](P,u P,v)
  \tkzDrawLines[blue,thick](u,v)
  \tkzDrawLines[add = 1 and 1,
     green!50!black,thick](ka,kb)
  \tkzDrawSegments[dashed](o,P o,c' o,b' K,c)
  \tkzMarkRightAngle[size=.1,
     fill=lightgray!15](o,c,K)
  \tkzDrawPoints(o,w,K,P,a,b,u,v,a',b',c',c)
  \tkzLabelPoints(o,w,b')
  \tkzLabelPoints[above right,blue](a,b,u,v)
  \tkzLabelPoints[above](c,a',c')
  \tkzLabelPoints[right,blue](P)
  \tkzLabelPoints[green!50!black,left](K)
 \end{tikzpicture}
\end{center}
\end{tkzexample}

\subsubsection{Method \tkzMeth{circle}{radical\_axis}(C)}
\label{ssub:method_circle_radical__axis_c}

The radical line, also called the radical axis, is the locus of points of equal circle power with respect to two nonconcentric circles. By the chordal theorem, it is perpendicular to the line of centers (Dörrie 1965).
\begin{flushright}
\small
 \href{https://mathworld.wolfram.com/RadicalLine.html}{Weisstein, Eric W. "Radical Line." From MathWorld--A Wolfram Web Resource.}
\end{flushright}

\vspace{1em}
Radical axis v1
\label{par:radical_axis_v1}

\vspace{1em}

\begin{minipage}{.5\textwidth}
\directlua{
 init_elements()
 z.X = point(0,0)
 z.B = point(2,2)
 z.Y = point(7,1)
 z.Ap = point(8,-1)
 L.XY = line(z.X, z.Y)
 C.XB = circle(z.X, z.B)
 C.YAp = circle(z.Y, z.Ap)
 z.E, z.F = C.XB:radical_axis(C.YAp):get()
 z.A = C.XB:point(0.4)
 T.ABAp = triangle(z.A, z.B, z.Ap)
 z.O = T.ABAp.circumcenter
 C.OAp = circle(z.O, z.Ap)
 _, z.Bp = intersection(C.OAp,C.YAp)
 L.AB = line(z.A, z.B)
 L.ApBp = line(z.Ap, z.Bp)
 z.M = intersection(L.AB,L.ApBp)
 z.H = L.XY:projection(z.M)}
 \begin{center}
   \begin{tikzpicture}[scale = .4]
   \tkzGetNodes
   \tkzDrawCircles(X,B Y,A')
   \tkzDrawArc[dashed,delta=30](O,A')(A)
   \tkzDrawPoints(A,B,A',B',M,H,X,Y,O,E,F)
   \tkzDrawLines[red](A,M A',M X,Y E,F)
   \tkzDrawLines[red,add=1 and 3](M,H)
   \end{tikzpicture}
 \end{center}
\end{minipage}
\begin{minipage}{.5\textwidth}
\begin{tkzexample}[code only]
\directlua{
 init_elements()
 z.X = point(0,0)
 z.B = point(2,2)
 z.Y = point(7,1)
 z.Ap = point(8,-1)
 L.XY = line(z.X, z.Y)
 C.XB = circle(z.X, z.B)
 C.YAp = circle(z.Y, z.Ap)
 z.E,
 z.F = C.XB:radical_axis(C.YAp):get()
 z.A = C.XB:point(0.4)
 T.ABAp = triangle(z.A, z.B, z.Ap)
 z.O = T.ABAp.circumcenter
 C.OAp = circle(z.O, z.Ap)
 _, z.Bp = intersection(C.OAp,C.YAp)
 L.AB = line(z.A, z.B)
 L.ApBp = line(z.Ap, z.Bp)
 z.M = intersection(L.AB,L.ApBp)
 z.H = L.XY:projection(z.M)}
\end{tkzexample}
\end{minipage}


\vspace{1em}
Radical axis v2
\label{par:radical_axis_v2}

\vspace{1em}
\begin{minipage}{.5\textwidth}
\directlua{
  init_elements()
  z.O = point(-1,0)
  z.Op = point(4,-1)
  z.B = point(0,2)
  z.D = point(4,0)
  C.OB = circle(z.O, z.B)
  C.OpD = circle(z.Op, z.D)
  L.EF = C.OB:radical_axis(C.OpD)
  z.E, z.F = L.EF:get()
  z.M = L.EF:point(.75)
  L.MT,L.MTp = C.OB:tangent_from(z.M)
  _, z.T = L.MT:get()
  _, z.Tp = L.MTp:get()
  L.MK,L.MKp = C.OpD:tangent_from(z.M)
  _, z.K = L.MK:get()
  _, z.Kp = L.MKp:get()}
\begin{center}
  \begin{tikzpicture}[scale = .75]
  \tkzGetNodes
  \tkzDrawCircles(O,B O',D)
  \tkzDrawLine(E,F)
  \tkzDrawLine[add=.25 and .25](O,O')
  \tkzDrawLines[add = 0 and .5](M,T M,T' M,K M,K')
  \tkzDrawCircle(M,T)
  \tkzDrawPoints(O,O',T,M,T',K,K')
  \tkzLabelPoints(O,O',T,T',K,K',M)
  \end{tikzpicture}
\end{center}
\end{minipage}
\begin{minipage}{.5\textwidth}
\begin{tkzexample}[code only]
\directlua{
  init_elements()
  z.O = point(-1,0)
  z.Op = point(4,-1)
  z.B = point(0,2)
  z.D = point(4,0)
  C.OB = circle(z.O, z.B)
  C.OpD = circle(z.Op, z.D)
  L.EF = C.OB:radical_axis(C.OpD)
  z.E, z.F = L.EF:get()
  z.M = L.EF:point(.75)
  L.MT,L.MTp = C.OB:tangent_from(z.M)
  _, z.T = L.MT:get()
  _, z.Tp = L.MTp:get()
  L.MK,L.MKp = C.OpD:tangent_from(z.M)
  _, z.K = L.MK:get()
  _, z.Kp = L.MKp:get()}

\end{tkzexample}
\end{minipage}


Radical axis v3
\label{par:radical_axis_v3}

\begin{minipage}{.5\textwidth}
\directlua{
 init_elements()
 z.O = point(0,0)
 z.B = point(4,0)
 z.Op = point(6,0)
 C.OB = circle(z.O, z.B)
 C.OpB = circle(z.Op, z.B)
 L.EF = C.OB:radical_axis(C.OpB)
 z.E, z.F = L.EF:get()
 z.M = L.EF:point(0.2)
 L.tgt = C.OB:tangent_from(z.M)
 _, z.T = L.tgt:get()
 L.tgtp = C.OpB:tangent_from(z.M)
 _, z.Tp =L.tgtp:get()}
\begin{center}
  \begin{tikzpicture}[scale =.5]
  \tkzGetNodes
  \tkzDrawCircles(O,B O',B)
  \tkzDrawSegments(M,T M,T')
  \tkzDrawSegments(E,F)
  \tkzDrawLine[add=.5 and .5](O,O')
  \tkzDrawPoints(O,B,O',E,F,M,T,T')
  \tkzLabelPoints(O,O',B,E,F,T,T')
  \tkzDrawArc(M,T')(T)
  \end{tikzpicture}
\end{center}
\end{minipage}
\begin{minipage}{.5\textwidth}
\begin{tkzexample}[code only]
\directlua{
 init_elements()
 z.O = point(0,0)
 z.B = point(4,0)
 z.Op = point(6,0)
 C.OB = circle(z.O, z.B)
 C.OpB = circle(z.Op, z.B)
 L.EF = C.OB:radical_axis(C.OpB)
 z.E, z.F = L.EF:get()
 z.M = L.EF:point(0.2)
 L.tgt = C.OB:tangent_from(z.M)
 _, z.T = L.tgt:get()
 L.tgtp = C.OpB:tangent_from(z.M)
 _, z.Tp =L.tgtp:get()}
\end{tkzexample}
\end{minipage}

% paragraph radical_axis_v3 (end)

Radical axis v4
\label{par:radical_axis_v4}

\begin{minipage}{.5\textwidth}
\directlua{
 init_elements()
 z.O = point(0,0)
 z.B = point(5,0)
 z.Op = point(3,0)
 C.OB = circle(z.O, z.B)
 C.OpB = circle(z.Op, z.B)
 L.EF = C.OB:radical_axis(C.OpB)
 z.E, z.F = L.EF:get()
 z.H = L.EF.mid
 z.M = L.EF:point(.8)
 _,L.t = C.OB:tangent_from(z.M)
 _, z.T = L.t:get()
 _,L.tp = C.OpB:tangent_from(z.M)
 _, z.Tp = L.tp:get()}
\begin{center}
\begin{tikzpicture}[scale =.5]
  \tkzGetNodes
  \tkzDrawCircles(O,B O',B)
  \tkzDrawSegments(M,T M,T')
  \tkzDrawSegments(E,F)
  \tkzDrawLine[add=.3 and .3](O,H)
  \tkzDrawPoints(O,O',B,E,H,M)
  \tkzLabelPoints[below right](O,O',E,F,M,T,T')
  \tkzDrawArc(M,B)(T)
\end{tikzpicture}
\end{center}
\end{minipage}
\begin{minipage}{.5\textwidth}
\begin{tkzexample}[code only]
\directlua{
 init_elements()
 z.O = point(0,0)
 z.B = point(5,0)
 z.Op = point(3,0)
 C.OB = circle(z.O, z.B)
 C.OpB = circle(z.Op, z.B)
 L.EF = C.OB:radical_axis(C.OpB)
 z.E, z.F = L.EF:get()
 z.H = L.EF.mid
 z.M = L.EF:point(.8)
 _,L.t = C.OB:tangent_from(z.M)
 _, z.T = L.t:get()
 _,L.tp = C.OpB:tangent_from(z.M)
 _, z.Tp = L.tp:get()}
\end{tkzexample}
\end{minipage}


% paragraph radical_axis_v4 (end)


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%  Circles %%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\subsection{Returns a circle}

\subsubsection{Method \tkzMeth{circle}{orthogonal\_from(pt)}}
\label{ssub:method_circle_orthogonal_from_pt}

In geometry, two circles are said to be \emph{orthogonal} if their tangent lines at each point of intersection meet at a right angle.
(See also: \href{https://en.wikipedia.org/wiki/Orthogonal_circles}{Wikipedia — Orthogonal circles}).

\medskip

This method constructs a circle:
\begin{itemize}
  \item centered at a given point,
  \item and orthogonal to a given circle.
\end{itemize}


The result is a circle that intersects the original one at right angles. The construction ensures that the condition of orthogonality is satisfied at all points of intersection.

\vspace{1em}

\begin{minipage}{.5\textwidth}
\directlua{
 init_elements()
 z.C_1 = point(0,0)
 z.C_2 = point(8,0)
 z.A = point(5,0)
 C.C1A = circle(z.C_1, z.A)
 z.S,
 z.T = C.C1A:orthogonal_from(z.C_2):get()}
\begin{center}
  \begin{tikzpicture}[scale = .35]
  \tkzGetNodes
  \tkzDrawCircles(C_1,T C_2,T)
  \tkzDrawSegments(C_1,T C_2,T)
  \tkzDrawLine(C_1,C_2)
  \tkzMarkRightAngle[fill=teal,
  opacity=.2,size=.5](C_1,T,C_2)
  \tkzDrawPoints(C_1,C_2,T)
  \tkzLabelPoints(C_1,C_2)
  \tkzLabelPoints[above](T)
  \tkzLabelSegment[left](C_1,T){r}
  \tkzLabelSegments[right](C_2,T){$\gamma$}
  \tkzLabelSegment[below](C_1,C_2){d}
  \tkzLabelCircle[left=10pt](C_1,T)(180){%
                       Circle 1}
  \tkzLabelCircle[below=10pt](C_2,T)(180){%
                       Circle 2}
  \end{tikzpicture}
\end{center}
\end{minipage}
\begin{minipage}{.5\textwidth}
\begin{tkzexample}[code only]
\directlua{
 init_elements()
 z.C_1 = point(0,0)
 z.C_2 = point(8,0)
 z.A = point(5,0)
 C = circle(z.C_1, z.A)
 z.S,
 z.T = C:orthogonal_from(z.C_2):get()}
\end{tkzexample}
\end{minipage}

\subsubsection{Method \tkzMeth{circle}{orthogonal\_through(pt,pt)}}
\label{ssub:method_circle_orthogonal_through}

This method constructs a circle that is orthogonal to a given circle and passes through two specified points.

\medskip

Geometrically, the resulting circle satisfies:
\begin{itemize}
\item it intersects the given circle orthogonally (i.e., the tangents at their intersection points are perpendicular),
\item it passes through the two given points.
\end{itemize}

\medskip

Special cases:
\begin{itemize}
\item Inverse points:
If the two points are inverse with respect to the given circle, there is an infinite number of solutions, all with their centers lying on the perpendicular bisector of the segment joining the two points.
The chosen solution is the one whose center is the midpoint of the two points.

\item Collinear with center (non-inverse):
If the two points are collinear with the center of the given circle but are not inverse points, no orthogonal circle exists.

\item General case:
In all other situations, there is a unique solution.
\end{itemize}

\vspace{1em}
\begin{minipage}{.5\textwidth}
\directlua{
  init_elements()
  z.O = point(0,1)
  z.A = point(1,0)
  z.z1 = point(-1.5,-1.5)
  z.z2 = point(2.5,-1.25)
  C.OA = circle(z.O, z.A)
  C.z1 = C.OA:orthogonal_through(z.z1, z.z2)
  z.c = C.z1.center}
\begin{center}
  \begin{tikzpicture}
  \tkzGetNodes
  \tkzDrawCircle(O,A)
  \tkzDrawCircle[orange](c, z1)
  \tkzDrawPoints[orange](O,A, z1, z2,c)
  \tkzLabelPoints[right](O,A)
  \tkzLabelPoints[left](z1, z2,c)
  \end{tikzpicture}
\end{center}
\end{minipage}
\begin{minipage}{.5\textwidth}
\begin{tkzexample}[code only]
\directlua{
  init_elements()
  z.O = point(0,1)
  z.A = point(1,0)
  z.z1 = point(-1.5,-1.5)
  z.z2 = point(2.5,-1.25)
  C.OA = circle(z.O, z.A)
  C.z1 = C.OA:orthogonal_through(z.z1, z.z2)
  z.c = C.z1.center}
\end{tkzexample}
\end{minipage}

\subsubsection{Method \tkzMeth{circle}{radical\_circle(C,C)}}
\label{ssub:radical_circle}

\texttt{Radical circle of three given circles.}

\medskip

This method constructs the \emph{radical circle} associated with three given circles. It is defined as the circle:

\begin{itemize}
  \item centered at the \textbf{radical center} (the common intersection point of the three radical axes),
  \item and orthogonal to all three given circles.
\end{itemize}


An important geometric property is that a circle centered at the radical center and orthogonal to one of the original circles is necessarily orthogonal to the other two as well.

\medskip

This construction plays a key role in advanced configurations such as coaxal systems, power of a point geometry, and triangle centers.
\begin{flushright}
\small
\href{https://mathworld.wolfram.com/RadicalCircle.html}{\textit{(Reference: Weisstein, Eric W. "Radical Circle." MathWorld)}}
\end{flushright}

\vspace{1em}



\begin{minipage}[t]{.5\textwidth}\vspace{0pt}%
\begin{verbatim}
\directlua{
 init_elements()
 z.A = point(0,0)
 z.B = point(6,0)
 z.C = point(0.8,4)
 T.ABC = triangle(z.A, z.B, z.C)
 C.exa = T.ABC:ex_circle()
 z.I_a, z.Xa = C.exa:get()
 C.exb = T.ABC:ex_circle(1)
 z.I_b, z.Xb = C.exb:get()
 C.exc = T.ABC:ex_circle(2)
 z.I_c, z.Xc = C.exc:get()
 C.ortho = C.exa:radical_circle(C.exb,C.exc)
 z.w, z.a = C.ortho:get()}
\begin{tikzpicture}[scale = .5]
   \tkzGetNodes
   \tkzDrawPolygon(A,B,C)
   \tkzDrawCircles(I_a,Xa I_b,Xb I_c,Xc)
   \tkzDrawCircles[red,thick](w,a)
   \tkzDrawPoints(A,B,C)
   \tkzLabelPoints(A,B,C)
\end{tikzpicture}
\end{verbatim}
\end{minipage}

\directlua{
 init_elements()
 z.A = point(0,0)
 z.B = point(6,0)
 z.C = point(0.8,4)
 T.ABC = triangle(z.A, z.B, z.C)
 C.exa = T.ABC:ex_circle()
 z.I_a, z.Xa = C.exa:get()
 C.exb = T.ABC:ex_circle(1)
 z.I_b, z.Xb = C.exb:get()
 C.exc = T.ABC:ex_circle(2)
 z.I_c, z.Xc = C.exc:get()
 C.ortho = C.exa:radical_circle(C.exb,C.exc)
 z.w, z.a = C.ortho:get()}

\begin{center}
  \begin{tikzpicture}[ scale = .5]
     \tkzGetNodes
     \tkzDrawPolygon(A,B,C)
     \tkzDrawCircles(I_a,Xa I_b,Xb I_c,Xc)
     \tkzDrawCircles[red,thick](w,a)
     \tkzDrawPoints(A,B,C)
     \tkzLabelPoints(A,B,C)
  \end{tikzpicture}
\end{center}

\subsubsection{Method \tkzMeth{circle}{CPP}}
\label{ssub:method_c__c__pp}

This method is presented in the document \tkzname{Euclidean Geometry} presented in \href{http://altermundus.fr}{altermundus.fr}.


\vspace{1em}
\begin{minipage}{.6\textwidth}
\directlua{
  init_elements()
  z.A = point(5,4)
  z.B = point(3,0)
  z.O = point(0,0)
  z.C = point(1,0)
  C.OC = circle(z.O, z.C)
  PA.center, PA.through,
  n = C.OC:CPP(z.A, z.B)
}
\begin{center}
\begin{tikzpicture}[scale=.6]
  \tkzGetNodes
  \tkzDrawCircle[blue](O,C)
  \tkzDrawPoints(A,B,C,O)
  \tkzDrawCirclesFromPaths[draw,
  red](PA.center,PA.through)
  \tkzLabelPoints(O,C,A,B)
\end{tikzpicture}
\end{center}
\end{minipage}
\begin{minipage}{.4\textwidth}
\begin{tkzexample}[code only]
\directlua{
  init_elements()
  z.A = point(5,4)
  z.B = point(3,0)
  z.O = point(0,0)
  z.C = point(1,0)
  C.OC = circle(z.O, z.C)
  PA.center,
  PA.through,
  n = C.OC:CPP(z.A, z.B)
}
\begin{tikzpicture}
  \tkzGetNodes
  \tkzDrawCircle[blue](O,C)
  \tkzDrawPoints(A,B,C,O)
  \tkzDrawCirclesFromPaths[draw,
      red](PA.center,PA.through)
\end{tikzpicture}
\end{tkzexample}
\end{minipage}


\subsubsection{Method \tkzMeth{circle}{CCP(C,p[,mode])}}
\label{ssub:method_c_cc_p}

This method is presented in the document \tkzname{Euclidean Geometry} presented in \href{http://altermundus.fr}{altermundus.fr}.

\begin{tkzexample}[latex=.5\textwidth]
\directlua{
  init_elements()
  z.A = point(0, 0)
  z.TA = point(3, 0)
  z.B = point(6, 2)
  z.TB = point(6, 1)
  z.P = point(3, 6)
  C.A = circle(z.A, z.TA)
  C.B = circle(z.B, z.TB)
  PA.center, PA.through  = C.A:CCP(C.B,
    z.P,"external")
  z.O1 = PA.center:get(1)
  z.O2 = PA.center:get(2)
  z.T1 = PA.through:get(1)
  z.T2 = PA.through:get(2)
  PA.center, PA.through = C.A:CCP(C.B,
    z.P,"internal")
  z.O3 = PA.center:get(1)
  z.O4 = PA.center:get(2)
  z.T3 = PA.through:get(1)
  z.T4 = PA.through:get(2)}
\begin{center}
  \begin{tikzpicture}[scale =.5]
 \tkzGetNodes
 \tkzDrawCircles[thick](A,TA B,TB)
 \tkzDrawCircles[red](O1,T1 O2,T2)
 \tkzDrawCircles[blue](O3,T3 O4,T4)
 \tkzDrawPoints[size=3](P)
 \tkzLabelPoints[above](P)
\end{tikzpicture}
\end{center}
\end{tkzexample}




\subsubsection{Method \tkzMeth{circle}{CLP}(L,p)}
\label{ssub:method_c_lc_p}

This method is presented in the document \tkzname{Euclidean Geometry} presented in \href{http://altermundus.fr}{altermundus.fr}.

\begin{tkzexample}[latex=.5\textwidth]
\directlua{
  init_elements()
  z.A = point(0, 0)
  z.B = point(4, 0)
  L.AB = line (z.A, z.B)
  z.O = point(3, 3)
  z.T = point(3, 2)
  z.P = point(2, .25)
  C.OT = circle(z.O, z.T)
  PA.center, PA.through = C.OT:CLP(L.AB, z.P)
  z.O1 =  PA.center:get(1)
  z.O2 =  PA.center:get(2)
  PA.center,
  PA.through = C.OT:CLP(L.AB, z.P,'internal')
  z.O3 = PA.center:get(1)
  z.O4 = PA.center:get(2)}
\begin{tikzpicture}
  \tkzGetNodes
  \tkzDrawCircles[thick](O,T)
  \tkzDrawCircles[red](O1,P O2,P)
  \tkzDrawCircles[cyan](O3,P O4,P)
  \tkzDrawLines[thick](A,B)
  \tkzDrawPoints[size = 2](P)
  \tkzDrawPoints(A,B,O,O1,O2,O3,O4)
\end{tikzpicture}
\end{tkzexample}


\subsubsection{Method \tkzMeth{circle}{CLL}(L,L,<choice,inside>)}
\label{ssub:method_c_cll}

This method is presented in the document \tkzname{Euclidean Geometry} presented in \href{http://altermundus.fr}{altermundus.fr}.

\vspace{1em}
\begin{tkzexample}[vbox]
\directlua{
  init_elements()
  z.A = point(0, 0)
  z.B = point(6, -2)
  L.AB  = line(z.A, z.B)
  z.C = point(-3, -4)
  z.D = point(3, 1)
  L.CD  = line(z.C, z.D)
  z.O = z.D + point(-3,1)
  z.X = z.O + point(0,1)
  C.OX = circle(z.O, z.X)
  PA.center, PA.through = C.OX:CLL(L.AB, L.CD,"all")
  tkz.nodes_from_paths(PA.center, PA.through)}
\begin{center}
\begin{tikzpicture}[scale=.75]
 \tkzGetNodes
 \tkzInit[xmin=-5,xmax=10,ymin=-1,ymax=5]
 \tkzClip
 \tkzDrawLines[blue,add =1 and .25](A,B)
 \tkzDrawLines[blue,add =.25 and 1](C,D)
 \tkzDrawPoints[blue,size=3](O)
 \tkzDrawCirclesFromPaths[draw,red,thick](PA.center,PA.through)
 \tkzDrawCircles[thick,blue](O,X)
 \tkzDrawPoints[red,size=3](w1)
 \tkzLabelPoints[red](O)
\end{tikzpicture}
\end{center}
\end{tkzexample}

\subsection{Case: \tkzMeth{circle}{CCL}(C2, L)}
\label{ssub:CCL}

This method is presented in the document \tkzname{Euclidean Geometry} presented in \href{http://altermundus.fr}{altermundus.fr}.

\vspace{1em}

\begin{tkzexample}[vbox]
\directlua{
  init_elements()
  z.A = point(-4, 4)
  z.B = z.A + point(3, 0)
  C.AB  = circle(z.A, z.B)
  z.C = point(3,2)
  z.D = z.C + point(1,0)
  C.CD = circle(z.C, z.D)
  z.E = point(-3, 0)
  z.F = point(5, 0)
  L.EF  = line(z.E, z.F)
  PA.center, PA.through,n = C.AB:CCL(C.CD, L.EF)
  tkz.nodes_from_paths(PA.center, PA.through)
  }
\begin{center}
  \begin{tikzpicture}[scale=.5]
\tkzGetNodes
 \tkzInit[xmin=-8,xmax=8,ymin=-8,ymax=8]
 \tkzClip
 \tkzDrawLines[thick,blue](E,F)
 \tkzDrawCircles[thick,blue](A,B C,D)
 \tkzDrawCirclesFromPaths[draw,purple,thick](PA.center, PA.through)
\end{tikzpicture}
  \end{center}
\end{tkzexample}

\subsubsection{Case: \tkzMeth{circle}{CCC}(C2, C3 [, opts])}
\label{ssub:CCC}

This method is presented in the document \tkzname{Euclidean Geometry} presented in \href{http://altermundus.fr}{altermundus.fr}.

\vspace{1em}

\begin{tkzexample}[vbox]
\directlua{
init_elements()
z.A = point(0, 0)
z.B = point(6, 0)
z.C = point(2, 5)
z.a = z.A + point(3, 0)
z.b = z.B + point(2, 0)
z.c = z.C + point(1, 0)
C.Aa = circle(z.A, z.a)
C.Bb = circle(z.B, z.b)
C.Cc = circle(z.C, z.c)
PA.center, PA.through, n = C.Aa:CCC(C.Bb, C.Cc)
}
\begin{center}
\begin{tikzpicture}[ scale = .5,gridded]
  \tkzInit[xmin=-8,xmax=12,ymin=-8,ymax=10]
  \tkzClip
  \tkzGetNodes
  \tkzDrawCircles[thick,blue](A,a B,b C,c)
  \tkzDrawCirclesFromPaths[draw,
    purple,thick](PA.center, PA.through)
\end{tikzpicture}
\end{center}
\end{tkzexample}

\subsubsection{Case: \tkzMeth{circle}{CCC\_gergonne}(C\_2, C\_3)}
\label{ssub:CCC_gergonne}


\begin{tkzexample}[vbox]
\directlua{
   z.A = point(0, 0)
   z.a = z.A + point (1, 0)
   z.B = point (4, 1)
   z.b = z.B + point (2, 0)
   z.C = point (2, 6)
   z.c = z.C + point (3, 0)
   C.Aa = circle(z.A, z.a)
   C.Bb = circle(z.B, z.b)
   C.Cc = circle(z.C,z.c)
   PA.center, PA.through = C.Aa:CCC_gergonne(C.Bb, C.Cc)
}
\begin{center}
\begin{tikzpicture}[scale = 0.7]
  \tkzInit[xmin=-8,xmax=12,ymin=-8,ymax=10]
  \tkzClip
  \tkzGetNodes
  \tkzDrawCircles[fill=blue!15](A,a B,b C,c)
  \tkzDrawCirclesFromPaths[draw,purple,thick](PA.center, PA.through)
\end{tikzpicture}
\end{center}
\end{tkzexample}

\subsubsection{Method \tkzMeth{circle}{midcircle}}
\label{ssub:midcircle}

\medskip

\emph{According to Eric Danneels and Floor van Lamoen:}

\begin{quote}
A \textbf{midcircle} of two given circles is a circle that maps one to the other via an \textbf{inversion}. Midcircles belong to the same pencil of circles as the two originals. The center(s) of the midcircle(s) correspond to the \emph{centers of similitude} of the given circles.
\end{quote}

I have adopted the term \textbf{midcircle} used by \tkzimp{Eric Danneels} and \tkzimp{Floor van Lamoen}, as well as by \tkzimp{Eric W. Weisstein}, but many other names exist, such as \textbf{mid-circle} or \textbf{circle of antisimilitude} [Wikipedia]. The latter name can be found in Advanced Euclidean Geometry by \tkzimp{Roger A. Johnson} (2007). On the website \textit{cut-the-knot.org}, reference is made to the \textbf{bisectal circle}, translated from French as \textbf{cercle bissecteur} and used by \tkzimp{Hadamard}, but this refers to the case where the two given circles intersect.


Four cases can be distinguished:

\begin{enumerate}[label=(\roman*)]
  \item \textbf{The two circles intersect}: There are two midcircles, centered at the internal and external centers of similitude;
  \item \textbf{One circle lies entirely inside the other}: There is a unique midcircle centered at the \emph{internal} center of similitude;
  \item \textbf{One circle lies entirely outside the other}: There is a unique midcircle centered at the \emph{external} center of similitude;
  \item \textbf{Tangency or single-point intersection}: These are limiting cases of the configurations above.
\end{enumerate}


\vspace{1em}
Let’s examine at each of these cases in more detail:

\begin{enumerate}[label=(\roman*)]
\item If the two given circles intersect, then there are two  circles of inversion through their common points, with centers at the centers of similitudes.  The two midcircles bisect their angles and are orthogonal to each other. The centers of the midcircles are the internal center of similitude and the external center of similitude $I$ and $J$.

\begin{itemize}
  \item Suppose $(\mathcal{A})$ and $(\mathcal{B})$ are two intersecting circles.
  \item Their common points define two inversion circles (midcircles), orthogonal to each other.
  \item The centers of these midcircles are the internal and external centers of similitude, denoted $I$ and $J$.
\end{itemize}


To construct these centers:
\begin{itemize}
  \item Take two diameters $EH$ of $(\mathcal{A})$ and $FG$ of $(\mathcal{B})$, such that the segments $EH$ and $FG$ are parallel.
  \item The intersection of lines $(GE)$ and $(AB)$ gives point $J$, the \emph{external} center of similitude.
  \item The intersection of lines $(EF)$ and $(AB)$ gives point $I$, the \emph{internal} center of similitude.
\end{itemize}


The circles $(\mathcal{I})$ and $(\mathcal{J})$, centered respectively at $I$ and $J$, are orthogonal and form the midcircles of $(\mathcal{A})$ and $(\mathcal{B})$. The division $(A,B;I,J)$ is harmonic.

\vspace{1em}

\begin{minipage}{.45\textwidth}
\directlua{
init_elements()
z.A = point(1, 0)
z.B = point(3, 0)
z.O = point(2.1, 0)
z.P = point(1,0)
C.AO = circle(z.A, z.O)
C.BP = circle(z.B, z.P)
z.E = C.AO.south
z.H = C.AO.north
z.F = C.BP.north
z.G = C.BP.south
C.IT,C.JV = C.AO:midcircle(C.BP)
z.I, z.T = C.IT:get()
z.J, z.V = C.JV:get()
z.X, z.Y = intersection(C.AO,C.BP)}
\begin{center}
\begin{tikzpicture}[scale = .75]
\tkzGetNodes
   \tkzDrawCircles[teal,thick](A,O B,P)
   \tkzDrawSegments[dashed,red](E,F I,B I,G I,F)
   \tkzDrawLines[gray](I,T J,V)
   \tkzDrawCircles[teal,thick](A,O B,P)
    \tkzDrawCircles[red,thick](I,X J,X)
   \tkzDrawPoints(A,B,I,J,E,F,G,H,X,Y)
   \tkzDrawPoints[red](I,J)
   \begin{scope}[font = \scriptsize]
   \tkzLabelPoints(A,I,J,G)
   \tkzLabelPoints[below left](E)
    \tkzLabelPoints[right](B)
    \tkzLabelPoints[above](F,H,X)
   \tkzLabelPoints[above right](Y)
   \end{scope}
\end{tikzpicture}
\end{center}
\end{minipage}
\begin{minipage}{.45\textwidth}
\begin{tkzexample}[code only]
\directlua{
 init_elements()
 z.A = point(1, 0)
 z.B = point(3, 0)
 z.O = point(2.1, 0)
 z.P = point(1,0)
 C.AO = circle(z.A, z.O)
 C.BP = circle(z.B, z.P)
 z.E = C.AO.south
 z.H = C.AO.north
 z.F = C.BP.north
 z.G = C.BP.south
 C.IT,C.JV = C.AO:midcircle(C.BP)
 z.I, z.T = C.IT:get()
 z.J, z.V = C.JV:get()
 z.X, z.Y = intersection(C.AO,C.BP)}
\end{tkzexample}
\end{minipage}

\item \textbf{One given circle lies entirely within the other.}
\label{midcircle_diameter}

This configuration is slightly more delicate to handle. To construct the midcircle, we proceed as follows:

\begin{itemize}
  \item First, construct two auxiliary circles $(\alpha)$ and $(\beta)$, each tangent to both of the given circles — one internally, one externally.
  \item Then, construct the \emph{radical circle} orthogonal to both $(\alpha)$ and $(\beta)$.
  \item The center of this radical circle is the \textbf{radical center}, which coincides with the \emph{internal center of similitude} of the original circles.
\end{itemize}


This radical circle is the unique midcircle in this case: it swaps the two original circles via inversion and lies in the same pencil of circles.

\vspace{1em}
\begin{minipage}{.45\textwidth}
\directlua{
  init_elements()
  z.A = point(3, 0)
  z.B = point(5, 0)
  z.O = point(2, 0)
  z.P = point(1, 0)
  L.AB = line(z.A, z.B)
  C.AO = circle(z.A, z.O)
  C.BP = circle(z.B, z.P)
  z.R, z.S = intersection(L.AB,C.BP)
  z.U, z.V = intersection(L.AB,C.AO)
  C.SV = circle:diameter(z.S, z.V)
  C.UR = circle:diameter(z.U, z.R)
  z.x = C.SV.center
  z.y = C.UR.center
  C.IT = C.AO:midcircle(C.BP)
  z.I, z.T = C.IT:get()}
\begin{center}
\begin{tikzpicture}[scale =.6]
\tkzGetNodes
   \tkzDrawCircles[teal,thick](A,O B,P)
   \tkzDrawCircles[green!20!black](x,S y,R)
   \tkzDrawPoints(A,B)
   \tkzDrawPoints[red](I)
   \tkzLabelPoints(A,B,I)
   \tkzDrawCircles[red,thick](I,T)
   \tkzLabelCircle[below](x,V)(270){$(\alpha)$}
   \tkzLabelCircle[below](y,R)(270){$(\beta)$}
   \tkzLabelCircle[below](I,T)(250){$\textcolor{red}{(\gamma)}$}
\end{tikzpicture}
\end{center}
\end{minipage}
\begin{minipage}{.45\textwidth}
\begin{tkzexample}[code only]
\directlua{
   init_elements()
   z.A = point(3, 0)
   z.B = point(5, 0)
   z.O = point(2, 0)
   z.P = point(1, 0)
   L.AB = line(z.A, z.B)
   C.AO = circle(z.A, z.O)
   C.BP = circle(z.B, z.P)
   z.R, z.S = intersection(L.AB,C.BP)
   z.U, z.V = intersection(L.AB,C.AO)
   C.SV = circle:diameter(z.S, z.V)
   C.UR = circle:diameter(z.U, z.R)
   z.x = C.SV.center
   z.y = C.UR.center
   C.IT = C.AO:midcircle(C.BP)
   z.I, z.T = C.IT:get()}
\end{tkzexample}
\end{minipage}

\item \textbf{The two given circles are external to each other.}

In this configuration, there exists a unique midcircle whose center is the \textbf{external center of similitude} of the two given circles.

\medskip

Let $I$ denote this external center of similitude. To construct the corresponding inversion circle (the midcircle), we proceed as follows:

\begin{itemize}
  \item Construct the external center $I$ based on the line joining the centers of the two given circles and their respective radii.
  \item Let $E$ and $F$ be the points of tangency (or auxiliary points) such that $IE \cdot IF = IH^2$.
  \item The point $H$ lies on the desired midcircle, and the circle centered at $I$ and passing through $H$ is the unique \textbf{external midcircle}.
\end{itemize}


This circle performs an inversion that maps one circle onto the other and lies in the same pencil of circles.

\item \textbf{The two given circles are external to each other.}

In this configuration, there exists a unique midcircle whose center is the \textbf{external center of similitude} of the two given circles.

\medskip

Let $I$ denote this external center of similitude. To construct the corresponding inversion circle (the midcircle), we proceed as follows:

\begin{itemize}
  \item Construct the external center $I$ based on the line joining the centers of the two given circles and their respective radii.
  \item Let $E$ and $F$ be the points of tangency (or auxiliary points) such that $IE \cdot IF = IH^2$.
  \item The point $H$ lies on the desired midcircle, and the circle centered at $I$ and passing through $H$ is the unique \textbf{external midcircle}.
\end{itemize}


This circle performs an inversion that maps one circle onto the other and lies in the same pencil of circles.


\begin{minipage}{.45\textwidth}
\directlua{
 init_elements()
 z.A = point(0, 0)
 z.B = point(4, 0)
 z.a = point(.5, 0)
 z.b = point(1, 0)
 C.Aa = circle (z.A, z.a)
 C.Bb = circle (z.B, z.b)
 L.AB = line(z.A, z.B)
 z.E = C.Aa.north
 z.F = C.Bb.north
 L.EF = line(z.E, z.F)
 C.IT =  C.Aa:midcircle(C.Bb)
 z.I, z.T = C.IT:get()
 L.TF = C.Bb:tangent_from(z.I)
 z.H = intersection(L.TF,C.IT)
 z.E = intersection(L.TF,C.Aa)
 z.F=L.TF.pb}
\begin{center}
\begin{tikzpicture}[scale=.75]
  \tkzGetNodes
  \tkzDrawCircles[teal,thick](A,a B,b)
  \tkzDrawCircles[red,thick](I,T)
  \tkzDrawSegments[gray](I,F)
  \tkzDrawPoints(A,B,E,F)
  \tkzDrawPoints[red](I,H)
  \tkzDrawLine(I,B)
  \tkzLabelPoints(A,B)
  \tkzLabelPoints[above](E,F)
  \tkzLabelPoints[above left,red](I)
  \tkzLabelPoints[above right,red](H)
\end{tikzpicture}
\end{center}
\end{minipage}
\begin{minipage}{.45\textwidth}
\begin{tkzexample}[code only]
\directlua{
 init_elements()
 z.A = point(0, 0)
 z.B = point(4, 0)
 z.a = point(.5, 0)
 z.b = point(1, 0)
 C.Aa = circle (z.A, z.a)
 C.Bb = circle (z.B, z.b)
 L.AB = line(z.A, z.B)
 z.E = C.Aa.north
 z.F = C.Bb.north
 L.EF = line(z.E, z.F)
 C.IT =  C.Aa:midcircle(C.Bb)
 z.I, z.T = C.IT:get()
 L.TF = C.Bb:tangent_from(z.I)
 z.H = intersection(L.TF,C.IT)
 z.E = intersection(L.TF,C.Aa)
 z.F=L.TF.pb}
\end{tkzexample}
\end{minipage}

\item \textbf{The two circles are tangent.}

\begin{itemize}
  \item If circle $(\mathcal{B})$ is \emph{externally tangent} to circle $(\mathcal{A})$, the construction of the midcircle is identical to the case of two disjoint circles. The external center of similitude still exists, and the inversion circle centered at this point transforms one circle into the other.

  \item If one of the circles lies \emph{inside} the other and they are \emph{internally tangent}, the construction simplifies. The center of the midcircle is the internal center of similitude, which coincides with the point of tangency. The inversion circle is then centered at this point and passes through any auxiliary point satisfying the inversion relation.
\end{itemize}


\begin{minipage}{.45\textwidth}
\directlua{
  init_elements()
  local a,b,c,d
  z.A = point(0, 0)
  z.B = point(4, 0)
  z.a = point(1, 0)
  z.b = point(1, 0)
  C.Aa = circle (z.A, z.a)
  C.Bb = circle (z.B, z.b)
  L.AB = line(z.A, z.B)
  z.E = C.Aa.north
  z.F = C.Bb.north
  L.EF = line(z.E, z.F)
  C.IT =  C.Aa:midcircle(C.Bb)
  z.I, z.T = C.IT:get()
  L.TF = C.Bb:tangent_from(z.I)
  z.H = intersection(L.TF,C.IT)
  z.E = intersection(L.TF,C.Aa)
  z.F=L.TF.pb}
\begin{center}
  \begin{tikzpicture}[scale=.5]
  \tkzGetNodes
  \tkzDrawCircles[teal,thick](A,a B,b)
  \tkzDrawCircles[red,thick](I,T)
  \tkzDrawSegments[gray](I,F)
  \tkzDrawPoints(A,B,E,F)
  \tkzDrawPoints[red](I,H)
  \tkzDrawLine(I,B)
  \tkzLabelPoints(A,B)
  \tkzLabelPoints[above](E,F)
  \tkzLabelPoints[above left,red](I)
  \tkzLabelPoints[above right,red](H)
  \end{tikzpicture}
\end{center}
\end{minipage}
\begin{minipage}{.45\textwidth}
\begin{tkzexample}[code only]
\directlua{
  init_elements()
  local a,b,c,d
  z.A = point(0, 0)
  z.B = point(4, 0)
  z.a = point(1, 0)
  z.b = point(1, 0)
  C.Aa = circle (z.A, z.a)
  C.Bb = circle (z.B, z.b)
  L.AB = line(z.A, z.B)
  z.E = C.Aa.north
  z.F = C.Bb.north
  L.EF = line(z.E, z.F)
  C.IT =  C.Aa:midcircle(C.Bb)
  z.I, z.T = C.IT:get()
  L.TF = C.Bb:tangent_from(z.I)
  z.H = intersection(L.TF,C.IT)
  z.E = intersection(L.TF,C.Aa)
  z.F=L.TF.pb}
\end{tkzexample}
\end{minipage}


\begin{minipage}{.45\textwidth}
\directlua{
 init_elements()
 z.A = point(2, 0)
 z.B = point(4, 0)
 z.a = point(1, 0)
 z.b = point(1, 0)
 C.Aa = circle(z.A, z.a)
 C.Bb = circle(z.B, z.b)
 C.IT = C.Aa:midcircle(C.Bb)
 z.I,
 z.T = C.IT:get()}
\begin{center}
  \begin{tikzpicture}
  \tkzGetNodes
  \tkzDrawCircles[teal,thick](A,a B,b)
  \tkzDrawCircles[red,thick](I,T)
  \tkzDrawPoints(A,B)
  \tkzDrawPoints[red](I)
  \tkzLabelPoints(A,B)
  \tkzLabelPoints[above left,red](I)
  \end{tikzpicture}
\end{center}
\end{minipage}
\begin{minipage}{.45\textwidth}
\begin{tkzexample}[code only]
\directlua{
 init_elements()
 z.A = point(2, 0)
 z.B = point(4, 0)
 z.a = point(1, 0)
 z.b = point(1, 0)
 C.Aa = circle(z.A, z.a)
 C.Bb = circle(z.B, z.b)
 C.IT = C.Aa:midcircle(C.Bb)
 z.I,
 z.T = C.IT:get()}
\end{tkzexample}
\end{minipage}

\end{enumerate}

\textbf{Midcircle between a circle and a line}

It is possible to generalize the notion of midcircle to the case of a circle and a line.
A midcircle of a circle and a straight line is defined as a circle with respect to which the given circle and line are mutually inverse.


In this situation, there are only three possible cases, but they share several common features.
The center of the midcircle lies on the line passing through the center of the given circle and perpendicular to the given line.
Moreover, the center is also one of the intersection points of the circle and the line.

Three cases can be distinguished:

\begin{enumerate}[label=(\roman*)]
  \item \texttt{The circle and the line intersect};
  \item \texttt{The circle and the line are disjoint};
  \item \texttt{The circle and the line are tangent}.
\end{enumerate}

Let's look at each case:

\texttt{Note: } It should be noted that in each case, inversion allows us to verify that the two objects are inverses of each other.


\begin{enumerate}
\item  \texttt{The circle and the line are disjoint.}

\begin{tkzexample}[latex=.5\textwidth]
\directlua{
init_elements()
z.o = point(-1,1)
z.a = point(1,2)
C.oa = circle(z.o, z.a)
z.c = point(3,2)
z.d = point(0,4)
L.cd = line(z.c, z.d)
C.OH = C.oa:inversion(L.cd)
z.O, z.H = C.OH:get()
L.inv = C.oa:inversion(C.OH)
z.x, z.y = L.inv:get()
C.inv  = C.OH:midcircle(L.cd)
z.w, z.t = C.inv:get()
z.P = L.cd:projection(z.o)
z.T = intersection(C.inv,line(z.o,z.P))}
\begin{center}
\begin{tikzpicture}[scale=.75]
\tkzGetNodes
\tkzDrawCircles[blue](O,H)
\tkzDrawCircles[red](w,t)
\tkzDrawLines[blue](c,d)
\tkzDrawLines[lightgray](o,P)
\tkzDrawPoint(w)
\tkzMarkRightAngle(w,P,c)
\end{tikzpicture}
\end{center}
\end{tkzexample}

\item  \texttt{The circle and the line intersect}

\begin{tkzexample}[latex=.5\textwidth]
\directlua{
init_elements()
z.o = point(0,1)
z.a = point(1,3)
C.oa = circle(z.o, z.a)
z.c = point(-1,2)
z.d = point(1,3)
L.cd = line(z.c, z.d)
C.OH = C.oa:inversion(L.cd)
z.O, z.H = C.OH:get()
L.inv = C.oa:inversion(C.OH)
z.x, z.y = L.inv:get()
C.inv  = C.OH:midcircle(L.cd)
z.w, z.t = C.inv:get()
z.P = L.cd:projection(z.o)
z.T = intersection(C.inv,line(z.o,z.P))}
\begin{center}
\begin{tikzpicture}[scale=.75]
\tkzGetNodes
\tkzDrawCircles[blue](O,H)
\tkzDrawCircles[red](w,t)
\tkzDrawLines[blue,add = 2 and 1](c,d)
\tkzDrawLines[lightgray](o,T)
\tkzDrawPoint(w)
\tkzMarkRightAngle(w,P,c)
\end{tikzpicture}
\end{center}
\end{tkzexample}

\item \texttt{The circle and the line are tangent}

\begin{tkzexample}[latex=.5\textwidth]
\directlua{
init_elements()
z.o = point(-1,1)
z.a = point(1,3)
C.oa = circle(z.o, z.a)
z.c = point(3,2)
z.d = point(0,4)
L.cd = C.oa:tangent_at(z.a)
C.OH = C.oa:inversion(L.cd)
C.wt = C.OH:midcircle(L.cd)
z.O, z.H = C.OH:get()
z.w, z.t = C.wt:get()
z.c, z.d = L.cd:get()}
\begin{center}
\begin{tikzpicture}
\tkzGetNodes
\tkzDrawCircles[red](w,t)
\tkzDrawCircles[blue](O,H)
\tkzDrawLines[blue](c,d)
\tkzDrawLines[lightgray](o,H)
\tkzDrawPoint(w)
\tkzMarkRightAngle(w,a,c)
\end{tikzpicture}
\end{center}
\end{tkzexample}

\end{enumerate}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%  Inversion

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\subsection{Transformations: the result is an object}

\subsubsection{Method \tkzMeth{circle}{inversion(obj)}:point, line and circle} %(fold)
\label{ssub:inversion}

The \code{inversion} method can be used on a point, a group of points, a line or a circle. Depending on the type of object, the function determines the correct algorithm to use.


\textbf{Inversion:point} %(fold)
\label{par:inversion_point}

Returns  a point.

\begin{tkzexample}[latex=.5\textwidth]
\directlua{
  init_elements()
  z.o = point(-1,2)
  z.a = point(2,1)
  C.oa = circle(z.o, z.a)
  z.c = point(3,4)
  z.d = C.oa:inversion(z.c)
  p = C.oa:power(z.c)}

\begin{center}
\begin{tikzpicture}[scale =.75]
  \tkzGetNodes
  \tkzDrawCircle(o,a)
  \tkzDrawSegments(o,a o,c)
  \tkzDrawPoints(a,o,c,d)
  \tkzLabelPoints(a,o,c,d)
  \tkzLabelSegment[sloped,above=1em](c,d){%
   The power of c is \tkzUseLua{p}}
 \end{tikzpicture}
\end{center}
\end{tkzexample}

\textbf{Inversion:line}
\label{par:inversion_line}

The result is either a straight line or a circle.

\begin{tkzexample}[latex=.5\textwidth]
\directlua{
  init_elements()
  z.o = point(-1,1)
  z.a = point(1,3)
  C.oa = circle(z.o, z.a)
  z.c = point(3,2)
  z.d = point(0,4)
  L.cd = line(z.c, z.d)
  C.OH = C.oa:inversion(L.cd)
  z.O, z.H = C.OH:get()}

\begin{center}
\begin{tikzpicture}
  \tkzGetNodes
  \tkzDrawCircles(o,a)
  \tkzDrawCircles[new](O,H)
  \tkzDrawLines(c,d o,H)
  \tkzDrawPoints(a,o,c,d,H)
  \tkzLabelPoints(a,o,c,d,H)
\end{tikzpicture}
\end{center}
\end{tkzexample}

\textbf{Inversion:circle}
 \label{par:inversion_circle}

The result is either a straight line or a circle.

\begin{tkzexample}[latex=.5\textwidth]
\directlua{
  init_elements()
  z.o, z.a = point(-1,3),point(2,3)
  z.c = point(-2,1)
  z.e, z.d = point(-2,7),point(-3,5)
  C.oa = circle(z.o, z.a)
  C.ed = circle(z.e, z.d)
  C.co = circle(z.c, z.o)
  obj = C.oa:inversion(C.co)
  if obj.type == "line" then
     z.p, z.q = obj:get()
  else
      z.f, z.b = obj:get()
  end
  obj = C.oa:inversion(C.ed)
  if obj.type == "line" then
    z.p, z.q = obj:get()
  else
     z.f, z.b = obj:get()
  end
  color = "orange"}
\begin{center}
\begin{tikzpicture}[scale =.75]
  \tkzGetNodes
  \tkzDrawCircles[black](o,a)
  \tkzDrawCircles[teal](c,o e,d)
  \tkzDrawCircles[\tkzUseLua{color}](f,b)
  \tkzDrawSegments[\tkzUseLua{color}](p,q)
  \tkzDrawPoints(a,...,f,o,p,q)
 \tkzLabelPoints(a,...,f,o,p,q)
\end{tikzpicture}
\end{center}
\end{tkzexample}

\subsubsection{Method \tkzMeth{circle}{inversion\_neg(obj)}}
\label{ssub:inversion_neg}


\texttt{Syntax: }

\verb|local Q = C:inversion_neg(obj)|

\texttt{Purpose: }

This method performs the inversion with respect to the circle \(C\) but with a
\emph{negative power}.
For a point \(P \neq O\), this means that
\[
\overrightarrow{OP'} \cdot \overrightarrow{OP} = -R^2,
\]
that is, \(P'\) is the inverse of \(P\) on the opposite half–line of \(OP\).
From a geometric point of view, the image set (line or circle) is the same as
with the ordinary inversion, but the points are taken with reversed orientation
along that set.

\texttt{Arguments: }
\begin{itemize}
  \item \verb|obj| – a \tkzname{point}, a \tkzname{line} (possibly not passing through \(O\)),
  or a \tkzname{circle}.
\end{itemize}

\texttt{Returns: }
\begin{itemize}
  \item If \verb|obj| is a point \(P\neq O\): the point \(P'=\texttt{inversion\_neg}(P)\).
  \item If \verb|obj| is a line not passing through \(O\): the same circle image
  as with \verb|C:inversion(line)| (it passes through \(O\)), but the orientation of the
  points on it is reversed.
  \item If \verb|obj| is a line passing through \(O\): the image is the same
  line.
  \item If \verb|obj| is a circle not passing through \(O\): the image is the same
  circle as with \verb|inversion|, but with reversed orientation.
  \item If \verb|obj| is a circle passing through \(O\): the image is the same line.
\end{itemize}

\texttt{Details: }

For a point \(P\),
\[
\vec{OP'} = -\frac{R^2}{\|OP\|^2}\,\vec{OP}.
\]
This is equivalent to performing the ordinary inversion followed by a
central symmetry with respect to \(O\) (taking the antipode).

For lines and circles, \verb|inversion_neg| produces the same geometric image as
\verb|inversion|; the negative sign only affects the parametrization along that
image.

\texttt{About the next example: }

The aim is to find the circles passing through a point $P$ tangent to a line $L$ and a circle.


In the example given above, the point
\verb|P2 = C.inv2:inversion_neg(P)| lies on the required circle because
the negative inversion places the image of \(P\) on the same geometric locus as
the standard inversion, but on the opposite direction relative to \(O\).
When combined with \verb|CPP(P,P2)|, this choice selects the correct circle among
the possible tangent ones, ensuring that \(P_2\) lies exactly on the desired
solution circle.



\begin{tkzexample}[vbox]
\directlua{
 init_elements()
 z.A = point(0, -5)
 z.B = point(5, -3)
 z.O = point(0, 0)
 z.C = point(2, 0)
 L.AB = line(z.A, z.B)
 C.OC = circle(z.O, z.C)
 L.main = L.AB:orthogonal_from(z.O)
 z.P = point(-4, -5)
 C.inv, C.inv2 = C.OC:midcircle(L.AB)
 z.P1 = C.inv:inversion(z.P)
 local center,
 through = C.OC:CPP(z.P,z.P1)
  z.w1 = center:get(1)
  z.t1 = through:get(1)
  z.w2 = center:get(2)
  z.t2 = through:get(2)
  z.P2 = C.inv2:inversion_neg(z.P)
  PA.c, PA.t = C.OC:CPP(z.P,z.P2)
  tkz.nodes_from_paths(PA.c, PA.t,"w","t",3)
 }
\begin{center}
 \begin{tikzpicture}[scale=.5]
  \tkzInit[xmin=-8,xmax=12,ymin=-8,ymax=10]
  \tkzClip
  \tkzGetNodes
  \tkzDrawLines[thick,blue, add = 1 and 1](A,B)
  \tkzDrawCircle[thick,blue](O,C)
  \tkzDrawCircles[thick,purple](w1,t1 w2,t2)
  \tkzDrawCircles[orange,thick](w3,t3)
  \tkzDrawArc[delta=10,orange,thick](w4,P)(P2)
  \tkzDrawPoints(P,P1,P2)
  \tkzLabelPoints(P,P1,P2)
  \tkzLabelLine[below,pos=1.25](A,B){$L$}
\end{tikzpicture}
 \end{center}
\end{tkzexample}




\subsubsection{Method \tkzMeth{circle}{path(p1, p2, N)}}
\label{ssub:circle_path}

\texttt{Purpose: } The \tkzClass{circle} class includes a method \code{path} to create a \tkzClass{path} object representing a circular arc between two points on the circle.

\medskip
\texttt{Syntax: }
This method samples the arc between two points \code{za} and \code{zb} lying on the circle, using a specified number of subdivisions.

\begin{mybox}
\begin{verbatim}
C = circle(z.O, z.A)
PA.arc = C:path(z.B, z.C, 100)
\end{verbatim}
\end{mybox}

The arc begins at \code{z.B} and ends at \code{z.C}, and is divided into 100 steps.

You can draw the resulting path in \TIKZ{} using:

\begin{mybox}
\begin{verbatim}
\tkzDrawCoordinates[smooth](PA.arc)
\end{verbatim}
\end{mybox}

\texttt{Example usage: }


\begin{tkzexample}[latex = .5\textwidth]
  \directlua{
   z.O = point(0, 0)
   z.A = point(5, 0)
   C.OA = circle(z.O, z.A)
   z.S = C.OA.south
   C.SO = circle(z.S, z.O)
   z.B,z.C = intersection(C.OA, C.SO)
   C.BC =  circle(z.B, z.C)
   L.BC = line(z.B, z.C)
   z.D = intersection(C.OA, C.BC)
   C.CD =  circle(z.C, z.D)
   PA.p1 = C.SO:path(z.C, z.B, 20)
   PA.p2 = C.BC:path(z.C, z.D, 20)
   PA.p3 = C.CD:path(z.D, z.B, 20)
   PA.path = (-PA.p1) + PA.p2 + PA.p3
  }
  \begin{tikzpicture}[scale = .5]
  \tkzGetNodes
  \tkzDrawCircles(O,A S,O)
  \tkzDrawArc(B,C)(D)
  \tkzDrawArc(C,D)(B)
  \tkzDrawCoordinates[fill = purple!20,
                   opacity=.4](PA.path)
  \tkzDrawCoordinates[smooth,red,
                       thick](PA.path)
  \tkzDrawPoints(A,O,B,C,S,D)
  \tkzLabelPoints(A,B,C)
  \end{tikzpicture}
\end{tkzexample}
\endinput
