summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/tkz/tkz-elements/doc/latex/TKZdoc-elements-presentation.tex
blob: d837d4a82632441f3527443fd11b0e5fd9e7b36a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
\section{Presentation}

I created \pkg{tkz-euclide} to give math teachers and students a tool to draw Euclidean geometry figures. This package was created as an interface based on \pkg{TikZ}, itself based on \TEX{}. The only problem encountered with this method is, in complicated cases, the lack of precision of the calculations made by \TEX{}.

To remedy this lack of precision, I first introduced the package \pkg{fp}, then the package \pkg{xfp}. Lately, with the arrival of lua\LATEX{}, I have been able to add a \tkzname{Lua} option whose goal was to perform some calculations with \tkzname{Lua}. It is much easier to program mathematics with \tkzname{Lua} than with \TEX{} so having prepared \pkg{tkz-euclide}, by separating the first parts of definitions and calculations from the drawing part, the idea of carrying out the first parts with only \tkzname{Lua} was necessary.

I had received some examples of programming with \tkzname{Lua} from Nicolas Kisselhoff and I took many of his ideas.

The essential principles of figure construction with \tkzname{tkz-euclide} are kept: definition, calculations, tracings, labels as well as the  step-by-step programmation, corresponding to a construction with a ruler and a compass.

Then, I read an article by Roberto Giacomelli on object programming based on the \tkzname{Lua} and \TIKZ\ tools. This was my second source of inspiration. Not only could the programming be done step-by-step, but the introduction of objects allowed the link between the code and the geometry. The code becomes more readable, the code is more explicit and better structured but it is less concise. Finally, as the problem of precision disappeared, I came to appreciate more and more what I was getting with object programming. So I've tried to develop this programming as much as possible.

In order to organize and maintain all the functions and methods, I chose to use classes of objects whose main ones are \tkzname{point}, \tkzname{line}, \tkzname{triangle}, \tkzname{circle} and \tkzname{ellipse}.

\subsection{With Lua} % (fold)
\label{sub:with_lua}

The purpose of tkz-elements is simply to calculate dimensions and define points. This is done in Lua. You can think of tkz-elements as a kernel that will be used either by tkz-euclide or by TikZ, see MetaPost.
Definitions and calculations are done inside the environment \tkzNameEnv{tkzelements}, this environment is based on \tkzNameEnv{luacode}.
To improve precision, if it's necessary to modify the scale of your figure, it's best to change the "scale" variable at the start of the code placed in environment \tkzNameEnv{tkzelements}.
Then we need to be able to transfer the coordinates of the points to a package that can use them, in this case tkz-euclide or TikZ.
% subsection with_lua (end)

\subsection{The main process : from tkz-elements (lua) to tkz-euclide (TikZ) with Lua\LaTeX.} % (fold)
\label{sub:the_main_process}


When all the points necessary for the drawing are obtained, they must be transformed into \tkzname{nodes} so that \pkg{TikZ} or \pkg{tkz-euclide} can draw the figure. This is done through the macro \tkzcname{tkzGetNodes}. This macro browse all the elements of the table |z| using the key (in fact the name of the point) and retrieves the values associated with it, i.e. the coordinates of the point (node).

A point $A$ is defined and stored in tkz-elements as follows:
|z.A| is an element of a table |z| which contains the coordinates of $A$ in the form of a complex number (very useful for calculations). Then a  macro, \tkzcname{tkzGetNodes}, transforms all elements of table |z| into nodes usable by tkz-euclide or TikZ. For another package, you'll need to adapt \tkzcname{tkzGetNodes}.

% subsection the_main_process (end)

\newpage
\subsection{Complete example: Pappus circle} % (fold)
\label{sub:the_figure_pappus_circle}

The figure:

\begin{tkzelements}
  z.A  = point: new (0 , 0)
  z.B  = point: new (10 , 0)
  L.AB = line:  new ( z.A, z.B)
  z.C  = L.AB:  gold_ratio () 
  L.AC = line:  new ( z.A, z.C)
  L.CB = line:  new ( z.C, z.B)
  L.AB = line:  new ( z.A, z.B)
  z.O_0    = L.AB.mid
  z.O_1    = L.AC.mid
  z.O_2    = L.CB.mid
  C.AB = circle: new ( z.O_0, z.B) 
  C.AC = circle: new ( z.O_1, z.C) 
  C.CB = circle: new ( z.O_2, z.B)
  z.P  = C.CB.north  
  z.Q  = C.AC.north
  z.O  = C.AB.south
  z.c  = z.C : north (2)
  C.PC = circle: new ( z.P, z.C) 
  C.QA = circle: new ( z.Q, z.A)  
  z.P_0    = intersection (C.PC,C.AB)
  z.P_1    = intersection (C.PC,C.AC)
  _,z.P_2  = intersection (C.QA,C.CB)
 T     = triangle: new ( z.P_0, z.P_1, z.P_2)
 z.O_3 = T.circumcenter
\end{tkzelements}
\hspace*{\fill}
   \begin{tikzpicture}
  \tkzGetNodes
  \tkzDrawCircle[black,fill=yellow!20,opacity=.4](O_0,B)
  \tkzDrawCircles[teal,fill=teal!40,opacity=.6](O_1,C O_2,B)
  \tkzDrawCircle[purple,fill=purple!20,opacity=.4](O_3,P_0)
  \tkzDrawArc[cyan,delta=10](Q,A)(P_0)
  \tkzDrawArc[cyan,delta=10](P,P_0)(B)
  \tkzDrawArc[cyan,delta=10](O,B)(A)
  \tkzDrawPoints(A,B,C,O_0,O_1,O_2,P,Q,P_0,P_0,P_1,P_2,O)
  \tkzLabelPoints(A,B,C,O_0,O_1,O_2,P,Q,P_0,P_0,P_1,P_2,O)
   \end{tikzpicture}
\hspace*{\fill}
% subsection the_figure_pappus_circle (end)

\subsubsection{The code} % (fold)
\label{ssub:the_code}

\begin{tkzexample}[small, code only,num]
% !TEX TS-program = lualatex
\documentclass{article}
\usepackage{tkz-euclide}
\usepackage{tkz-elements}
\begin{document}

\begin{tkzelements}
   z.A      = point: new (0 , 0)
   z.B      = point: new (10 , 0)
   L.AB     = line:  new ( z.A, z.B)
   z.C      = L.AB:  gold_ratio () 
   L.AC     = line:  new ( z.A, z.C)
   L.CB     = line:  new ( z.C, z.B)
   L.AB     = line:  new ( z.A, z.B)
   z.O_0    = L.AB.mid
   z.O_1    = L.AC.mid
   z.O_2    = L.CB.mid
   C.AB     = circle: new ( z.O_0, z.B) 
   C.AC     = circle: new ( z.O_1, z.C) 
   C.CB     = circle: new ( z.O_2, z.B)
   z.P      = C.CB.north  
   z.Q      = C.AC.north
   z.O      = C.AB.south
   z.c      = z.C : north (2)
   C.PC     = circle: new ( z.P, z.C) 
   C.QA     = circle: new ( z.Q, z.A)  
   z.P_0    = intersection (C.PC,C.AB)
   z.P_1    = intersection (C.PC,C.AC)
   _,z.P_2  = intersection (C.QA,C.CB)
   T        = triangle: new ( z.P_0, z.P_1, z.P_2)
   z.O_3    = T.circumcenter
\end{tkzelements}

\begin{tikzpicture}
  \tkzGetNodes
  \tkzDrawCircle[black,fill=yellow!20,opacity=.4](O_0,B)
  \tkzDrawCircles[teal,fill=teal!40,opacity=.6](O_1,C O_2,B)
  \tkzDrawCircle[purple,fill=purple!20,opacity=.4](O_3,P_0)
  \tkzDrawArc[cyan,delta=10](Q,A)(P_0)
  \tkzDrawArc[cyan,delta=10](P,P_0)(B)
  \tkzDrawArc[cyan,delta=10](O,B)(A)
  \tkzDrawPoints(A,B,C,O_0,O_1,O_2,P,Q,P_0,P_0,P_1,P_2,O)
  \tkzLabelPoints(A,B,C,O_0,O_1,O_2,P,Q,P_0,P_0,P_1,P_2,O)
\end{tikzpicture}
\end{document}
\end{tkzexample}
% subsubsection the_code (end)

\subsubsection{Some explanations} % (fold)
\label{ssub:some_explanations}

Half of the code concerns the direct creation of objects (|point: new |, |circle: new | etc.)

Then points are obtained using object attributes like |L.AB.mid| which determines the middle of the segment $[AB]$ or |C.AB.south| which allows to obtain the south pole of the circle with center $A$ passing through $B$.

About the naming of objects, see the section \ref{sec:writing_convention}

\begin{itemize}
  \item  Lines 8 and 9 create two fixed points $A$ and $B$.

 \item   Line 10 these two points are used to create the line.

 \item   Line 11 the gold method creates a point $C$ which divides the segment $[AB]$ according to the golden ratio.  

 \item  Lines 12, 13 and 14 creation of 3 new lines.

\item    Lines 15, 16 and 17 creation of 3 points: the midpoints of the previous segments. These points are predefined and it is enough to use the attributes of the lines. Another possibility is to use the triangle T.ABC with the method : |medial_tr|

\item    Lines 18, 19 et 20 creation of three circles.

\item    Line 21 creation of the south pole $P$ of the circle of center C passing through B. It is also a predefined point and we still use an attribute.

\item   Lines 22 and 23 we create two new poles: north and south for two other circles.

\item    Lines 24 and 25 creation of two circles.

\item    Lines 26 and 27 search for intersections of two circles.

\item    Lines 28 and 29 we use a triangle to search for its circum center.
\end{itemize}
% subsubsection some_explanations (end)
\endinput