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
|
\newpage
\section{Transfers} % (fold)
\label{sec:transfers}
\subsection{Fom Lua to tkz-euclide or TikZ} % (fold)
\label{sub:fom_lua_to_tkz_euclide_or_tikz}
In this section, we'll look at how to transfer points, Booleans and numerical values.
\subsubsection{Points transfer} % (fold)
\label{ssub:points_transfer}
We use an environment \tkzname{tkzelements} outside an environment \tkzname{tikzpicture} which allows us to carry out all the necessary calculations, then we launch the macro \Imacro{tkzGetNodes} which transforms the affixes of the table \tkzname{z} into \tkzname{Nodes}. It only remains to draw.
Currently the drawing program is either \TIKZ\ or \pkg{tkz-euclide}. You have the possibility to use another package to trace but for that you have to create a macro similar to \tkzcname{tkzGetNodes}. Of course, this package must be able to store the points as does \TIKZ\ or \pkg{tkz-euclide}.
\vspace*{1em}
\begin{mybox}
\begin{verbatim}
\def\tkzGetNodes{\directlua{%
for K,V in pairs(z) do
local n,sd,ft
n = string.len(K)
if n >1 then
_,_,ft, sd = string.find( K , "(.+)(.)" )
if sd == "p" then K=ft.."'" end
_,_,xft, xsd = string.find( ft , "(.+)(.)" )
if xsd == "p" then K=xft.."'".."'" end
end
tex.print("\\coordinate ("..K..") at ("..V.re..","..V.im..") ;\\\\")
end}
}
\end{verbatim}
\end{mybox}
See the section In-depth Study \ref{sec:in_depth_study} for an explanation of the previous code.
The environment \tkzNameEnv{tkzelements} allows to use the underscore |_| and the macro \tkzcname{tkzGetNodes} allows to obtain names of nodes containing \tkzname{prime} or \tkzname{double prime}. (see the next example)
\begin{minipage}{0.5\textwidth}
\begin{verbatim}
\begin{tkzelements}
scale = 1.2
z.o = point: new (0,0)
z.a_1 = point: new (2,1)
z.a_2 = point: new (1,2)
z.ap = z.a_1 + z.a_2
z.app = z.a_1 - z.a_2
\end{tkzelements}
\begin{tikzpicture}
\tkzGetNodes
\tkzDrawSegments(o,a_1 o,a_2 o,a' o,a'')
\tkzDrawSegments[red](a_1,a' a_2,a')
\tkzDrawSegments[blue](a_1,a'' a_2,a'')
\tkzDrawPoints(a_1,a_2,a',o,a'')
\tkzLabelPoints(o,a_1,a_2,a',a'')
\end{tikzpicture}
\end{verbatim}
\end{minipage}
\begin{minipage}{0.5\textwidth}
\begin{tkzelements}
scale = 1.2
z.o = point: new (0,0)
z.a_1 = point: new (2,1)
z.a_2 = point: new (1,2)
z.ap = z.a_1 + z.a_2
z.app = z.a_1 - z.a_2
\end{tkzelements}
\hspace{\fill}
\begin{tikzpicture}
\tkzGetNodes
\tkzDrawSegments(o,a_1 o,a_2 o,a' o,a'')
\tkzDrawSegments[red](a_1,a' a_2,a')
\tkzDrawSegments[blue](a_1,a'' a_2,a'')
\tkzDrawPoints(a_1,a_2,a',o,a'')
\tkzLabelPoints(o,a_1,a_2,a',a'')
\end{tikzpicture}
\hspace{\fill}
\end{minipage}%
\newpage
% subsection fom_lua_to_tkz_euclide_or_tikz (end)
\subsubsection{Other transfers} % (fold)
\label{ssub:other_transfers}
Sometimes it's useful to transfer angle, length measurements or boolean. For this purpose, I have created the macro (see \ref{sub:transfer_from_lua_to_tex})
\IEmacro{tkzUseLua(value)}
\begin{verbatim}
\begin{tkzelements}
z.b = point: new (1,1)
z.a = point: new (4,2)
z.c = point: new (2,2)
z.d = point: new (5,2)
L.ab = line : new (z.a,z.b)
L.cd = line : new (z.c,z.d)
det = (z.b-z.a)^(z.d-z.c)
if det == 0 then bool = true
else bool = false
end
x = intersection (L.ab,L.cd)
\end{tkzelements}
The intersection of the two lines lies at
a point whose affix is:\tkzUseLua{x}
\begin{tikzpicture}
\tkzGetNodes
\tkzDrawPoints(a,...,d)
\ifthenelse{\equal{\tkzUseLua{bool}}{true}}{
\tkzDrawSegments[red](a,b c,d)}{%
\tkzDrawSegments[blue](a,b c,d)}
\tkzLabelPoints(a,...,d)
\end{tikzpicture}
\end{verbatim}
\begin{tkzelements}
z.b = point: new (1,1)
z.a = point: new (4,2)
z.c = point: new (2,2)
z.d = point: new (5,1)
L.ab = line : new (z.a,z.b)
L.cd = line : new (z.c,z.d)
det = (z.b-z.a)^(z.d-z.c)
if det == 0 then bool = true
else bool = false
end
x = intersection (L.ab,L.cd)
\end{tkzelements}
The intersection of the two lines lies at
a point whose affix is: \tkzUseLua{x}
\vspace{1em}
\hspace{\fill}
\begin{tikzpicture}
\tkzGetNodes
\tkzInit[xmin =-1,ymin=-1,xmax=6,ymax=3]
\tkzGrid\tkzAxeX\tkzAxeY
\tkzDrawPoints(a,...,d)
\ifthenelse{\equal{\tkzUseLua{bool}}{true}}{
\tkzDrawSegments[red](a,b c,d)}{%
\tkzDrawSegments[blue](a,b c,d)}
\tkzLabelPoints(a,...,d)
\end{tikzpicture}
\hspace{\fill}
% subsubsection other_transfers (end)
% subsubsection points_transfer (end)
% section transferts (end)
\endinput
|