\newpage \section{Why tkz-elements?} % (fold) \label{sec:why_tkz_elements} \subsection{Calculation accuracy} % (fold) \label{sub:calculation_accuracy} \subsubsection{Calculation accuracy in \TIKZ} % (fold) \label{ssub:calculation_accuracy_in_tikz} With \TIKZ, the expression \tkzimp{|veclen(x,y)|} calculates the expression $\sqrt{x^2+y^2}$. This calculation is achieved through a polynomial approximation, drawing inspiration from the ideas of \tkzimp{Rouben Rostamian}. \pgfkeys{/pgf/number format/.cd,std,precision=5} \pgfmathparse{veclen(65,72)} \begin{mybox}{} \begin{Verbatim} pgfmathparse{veclen(65,72)} \pgfmathresult \end{Verbatim} \end{mybox} \tkzHand $\sqrt{65^2+72^2} \approx \pmpn{\pgfmathresult} $ \tkzRBomb. % subsubsection calculation_accuracy_in_tikz (end) \subsubsection{Calculation accuracy in Lua} % (fold) \label{ssub:calculation_accuracy_in_lua} A |luaveclen| macro can be defined as follows: \begin{mybox}{} \begin{Verbatim} \def\luaveclen#1#2{\directlua{tex.print(string.format( '\percentchar.5f',math.sqrt((#1)*(#1)+(#2)*(#2))))}} \end{Verbatim} \end{mybox} and \begin{mybox} \begin{Verbatim} \luaveclen{65}{72} \end{Verbatim} \end{mybox} gives \tkzHand $\sqrt{65^2+72^2} = \pmpn{\luaveclen{65}{72}} $ {\color{red}!!} The error, though insignificant when it comes to the placement of an object on a page by a hundredth of a point, becomes problematic for the results of mathematical demonstrations. Moreover, these inaccuracies can accumulate and lead to erroneous constructions. \vspace{.5em} To address this lack of precision, I initially introduced the \pkg{fp}, followed by the package \pkg{xfp}. More recently, with the emergence of Lua\LATEX{}, I incorporated a \tkzname{Lua} option aimed at performing calculations with \tkzname{Lua}. This was the primary motivation behind creating the package, with the secondary goal being the introduction of object-oriented programming (OOP) and simplifying programming with Lua. The concept of OOP persuaded me to explore its various possibilities further. At that time, I had received some Lua programming examples from {\tkzimpbf{Nicolas Kisselhoff}}, but I struggled to understand the code initially, so I dedicated time to studying Lua patiently. Eventually, I was able to develop \tkzname{\tkznameofpack}, incorporating many of his ideas that I adapted for the package. % subsubsection calculation_accuracy_in_lua (end) \subsubsection{Using objects} % (fold) \label{ssub:using_objects} Subsequently, I came across an article by \tkzimpbf{Roberto Giacomelli}\footnote{\href{https://www.guitex.org/home/images/meeting2012/slides/presentazione_giacomell_guitmeeting_2012.pdf}{Grafica ad oggetti con LuaTEX}} on object-oriented programming using \tkzname{Lua} and \TIKZ\ tools. This served as my second source of inspiration. Not only did this approach enable programming to be executed step-by-step, but the introduction of objects facilitated a direct link between the code and geometry. As a result, the code became more readable, explicit, and better structured. \subsubsection{Example: Apollonius circle} % (fold) \label{ssub:example_apollonius_circle} \begin{mybox}{Problem:} The objective is to identify an inner tangent circle to the three exinscribed circles of a triangle.\end{mybox} For additional details, refer to \href{https://mathworld.wolfram.com/ApolloniusCircle.html}{MathWorld} for more details. This example served as my reference for testing the \pkg{tkz-euclide} package. Initially, with my first methods and the tools available to me, the results lacked precision. However, with tkz-elements, I now have access to more powerful and precise tools that are also easier to use. The fundamental principles of figure construction with \tkzname{tkz-euclide} remain intact: definitions, calculations, tracings, labels, as well as the step-by-step programming, mirroring the process of construction with a ruler and compass. This version utilizes the simplest construction method made possible by Lua. \begin{mybox} \begin{Verbatim} \directlua{ scale = .4 z.A = point: new (0,0) z.B = point: new (6,0) z.C = point: new (0.8,4) T.ABC = triangle : new ( z.A,z.B,z.C ) z.N = T.ABC.eulercenter z.S = T.ABC.spiekercenter T.feuerbach = T.ABC : feuerbach () z.Ea,z.Eb,z.Ec = get_points ( T.feuerbach ) T.excentral = T.ABC : excentral () z.Ja,z.Jb,z.Jc = get_points ( T.excentral ) C.JaEa = circle: new (z.Ja,z.Ea) C.ortho = circle: radius (z.S,math.sqrt(C.JaEa: power(z.S))) z.a = C.ortho.through C.euler = T.ABC: euler_circle () C.apo = C.ortho : inversion (C.euler) z.O = C.apo.center z.xa,z.xb,z.xc = C.ortho : inversion (z.Ea,z.Eb,z.Ec) } \end{Verbatim} \end{mybox} The creation of an object encapsulates its attributes (its characteristics) and methods (i.e. the actions that are specific to it). Subsequently, it is assigned a reference (a name) which is linked to the object using a table. This table functions as an associative array that links the reference, called a \tkzimp{key}, to a \tkzimp{value}, in this case, the object. Further elaboration on these notions will be provided later. For instance, let \tkzimp{T} be a table associating the object \tkzimp{triangle} with the key \tkzimp{ABC}. \tkzimp{T.ABC} is also a table, and its elements are accessed using keys that correspond to attributes of the triangle. These attributes have been defined within the package. \vspace{1em} \begin{mybox} \begin{Verbatim} z.N = T.ABC.eulercenter \end{Verbatim} \end{mybox} |N| is the name of the point, |eulercenter| is an attribute of the triangle. \footnote{ The center of the Euler circle, or center of the nine-point circle, is a characteristic of every triangle.} \begin{mybox} \begin{Verbatim} T.excentral = T.ABC : excentral () \end{Verbatim} \end{mybox} In this context, \tkzimp{excentral} is a method associated with the \tkzimp{T.ABC }object. It defines the triangle formed by the centers of the exinscribed circles. Of particular importance are two lines of code. The first one below demonstrates that the exceptional precision provided by Lua allows for the definition of a radius through a complex calculation. The radius of the radical circle is determined by $\sqrt{\Pi(S,\mathcal{C}(Ja,Ea))}$ (square root of the power of point $S$ with respect to the exinscribed circle with center |Ja| passing through |Ea|). \begin{mybox}{} \begin{Verbatim} C.ortho = circle: radius (z.S,math.sqrt(C.JaEa: power(z.S))) \end{Verbatim} \end{mybox} Lastly, it's worth noting that the inversion of the Euler circle with respect to the radical circle yields the Apollonius circle\footnote{The nine-point circle, or Euler circle, is externally tangent to the three circles. The points of tangency form Feuerbach's triangle.}. This transformation requires an object as a parameter, which is recognized by its type (all objects are typed in the package), and the method determines which algorithm to use according to this type. \begin{mybox}{} \begin{Verbatim} C.apo = C.ortho : inversion (C.euler) \end{Verbatim} \end{mybox} Now that all the points have been defined, it's time to start drawing the paths. To accomplish this, nodes need to be created. This is the role of the macro \Imacro{tkzGetNodes}. Refer to \ref{ssub:points_transfer} The subsequent section exclusively deals with drawings, and is managed by \pkg{tkz-euclide}. \begin{Verbatim} \begin{tikzpicture} \tkzGetNodes \tkzFillCircles[green!30](O,xa) \tkzFillCircles[teal!30](Ja,Ea Jb,Eb Jc,Ec) \tkzFillCircles[lightgray](S,a) \tkzFillCircles[green!30](N,Ea) \tkzDrawPoints(xa,xb,xc) \tkzDrawCircles(Ja,Ea Jb,Eb Jc,Ec S,a O,xa N,Ea) \tkzClipCircle(O,xa) \tkzDrawLines[add=3 and 3](A,B A,C B,C) \tkzDrawPoints(O,A,B,C,S,Ea,Eb,Ec,N) \tkzDrawSegments[dashed](S,xa S,xb S,xc) \tkzLabelPoints(O,N,A,B) \tkzLabelPoints[right](S,C) \end{tikzpicture} \end{Verbatim} \vspace{1em} \directlua{ scale = .4 z.A = point: new (0,0) z.B = point: new (6,0) z.C = point: new (0.8,4) T.ABC = triangle : new ( z.A,z.B,z.C ) z.N = T.ABC.eulercenter z.S = T.ABC.spiekercenter T.feuerbach = T.ABC : feuerbach () z.Ea,z.Eb,z.Ec = get_points ( T.feuerbach ) T.excentral = T.ABC : excentral () z.Ja,z.Jb,z.Jc = get_points ( T.excentral ) C.JaEa = circle: new (z.Ja,z.Ea) C.ortho = circle: radius (z.S,math.sqrt(C.JaEa: power(z.S))) z.a = C.ortho.through C.euler = T.ABC: euler_circle () C.apo = C.ortho : inversion (C.euler) z.O = C.apo.center z.xa,z.xb,z.xc = C.ortho : inversion (z.Ea,z.Eb,z.Ec) } \begin{minipage}{\textwidth} \hspace*{\fill} \begin{tikzpicture} \tkzGetNodes \tkzFillCircles[green!30](O,xa) \tkzFillCircles[teal!30](Ja,Ea Jb,Eb Jc,Ec) \tkzFillCircles[lightgray](S,a) \tkzFillCircles[green!30](N,Ea) \tkzDrawPoints(xa,xb,xc) \tkzDrawCircles(Ja,Ea Jb,Eb Jc,Ec S,a O,xa N,Ea) \tkzClipCircle(O,xa) \tkzDrawLines[add=3 and 3](A,B A,C B,C) \tkzDrawPoints(O,A,B,C,S,Ea,Eb,Ec,N) \tkzDrawSegments[dashed](S,xa S,xb S,xc) \tkzLabelPoints(O,N,A,B) \tkzLabelPoints[right](S,C) \end{tikzpicture} \hspace*{\fill} \end{minipage} % subsubsection example_apollonius_circle (end) % subsubsection using_objects (end) % subsection calculation_accuracy (end) % section why_tkz_elements (end)