summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/tkz/tkz-base/doc/latex/TKZdoc-base-tools.tex
blob: 3ddc5fb111ce5f8041aafa2b0da1276c19ae64f3 (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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
\section{Miscellaneous tools}

\subsection{Duplicate a segment} 

This involves constructing a segment on a given half-line of the same length as a given segment.

\begin{NewMacroBox}{tkzDuplicateSegment}{\parg{pt1,pt2}\parg{pt3,pt4}\marg{pt5}}%
This involves creating a segment on a given half-line of the same length as a given segment . It is in fact the definition of a point.

\medskip
\begin{tabular}{lll}%
\toprule
arguments             & example & explanation                         \\ 
\midrule
\TAline{(pt1,pt2)(pt3,pt4)\{pt5\}} {\tkzcname{tkzDuplicateLen}(A,B)(E,F)\{C\}}{AC=EF et $C \in [AB)$} \\                                                                         
\bottomrule
\end{tabular}

\medskip
The macro \tkzcname{tkzDuplicateLength} is identical to this one. 
\end{NewMacroBox}

\begin{tkzexample}[latex=6cm,small]
   \begin{tikzpicture}
   \tkzDefPoint(0,0){A}
   \tkzDefPoint(2,-3){B}
   \tkzDefPoint(2,5){C} 
   \tkzDrawSegments[red](A,B A,C)
   \tkzDuplicateSegment(A,B)(A,C)  \tkzGetPoint{D}
   \tkzDrawSegment[green](A,D)
   \tkzDrawPoints[color=red](A,B,C,D) 
   \tkzLabelPoints[above right=3pt](A,B,C,D)
 \end{tikzpicture} 
\end{tkzexample} 

\subsubsection{Gold proportion with \tkzcname{tkzDuplicateSegment}} 
 \begin{tkzexample}[latex=7cm,small]
\begin{tikzpicture}[rotate=-90,scale=.75]
 \tkzInit[xmax=10,ymax=10]
 \tkzClip[space=1]
 \tkzDefPoint(0,0){A}
 \tkzDefPoint(10,0){B}
 \tkzDefMidPoint(A,B)   \tkzGetPoint{I}
 \tkzDefPointWith[orthogonal,K=-.75](B,A)
    \tkzGetPoint{C}
 \tkzInterLC(B,C)(B,I)  \tkzGetSecondPoint{D}
 \tkzDuplicateSegment(B,D)(D,A) \tkzGetPoint{E}
 \tkzInterLC(A,B)(A,E)   \tkzGetPoints{N}{M}
 \tkzDrawArc[delta=10](D,E)(B)
 \tkzDrawArc[delta=10](A,M)(E)
 \tkzDrawLines(A,B B,C A,D)
 \tkzDrawArc[delta=10](B,D)(I)
 \tkzDrawPoints(A,B,D,C,M,I,N)
 \tkzLabelPoints(A,B,D,C,M,I,N)
\end{tikzpicture}
 \end{tkzexample}
% <-------------------------------------------------------------------->
 %                About Angles
% <-------------------------------------------------------------------->
\subsection{Determining a slope}
It is a question of determining whether it exists, the slope of a straight line defined by two points. No verification of the existence is made.

\begin{NewMacroBox}{tkzFindSlope}{\parg{pt1,pt2}\marg{name of macro}}%
The result is stored in a macro.

\medskip
\begin{tabular}{lll}
\toprule
arguments             & example & explication       \\
\midrule
\TAline{(pt1,pt2){pt3}} {\tkzcname{tkzFindSlope}(A,B)\{slope\}}{\tkzcname{slope} will give the result of $\frac{y_B-y_A}{x_B-x_A}$} \\
\bottomrule
\end{tabular}

\medskip
\tkzHandBomb\ Careful not to have $x_B=x_A$ 
\end{NewMacroBox}


\begin{tkzexample}[latex=7cm,small]
\begin{tikzpicture}[scale=1.5]
  \tkzInit[xmax=4,ymax=5]\tkzGrid[sub]
  \tkzDefPoint(1,2){A}    \tkzDefPoint(3,4){B}
  \tkzDefPoint(3,2){C}    \tkzDefPoint(3,1){D}
  \tkzDrawSegments(A,B A,C A,D)
  \tkzDrawPoints[color=red](A,B,C,D)  
  \tkzLabelPoints(A,B,C,D)
  \tkzFindSlope(A,B){SAB} \tkzFindSlope(A,C){SAC}
  \tkzFindSlope(A,D){SAD}
  \pgfkeys{/pgf/number format/.cd,fixed,precision=2}
  \tkzText[fill=Gold!50,draw=brown](1,4)%
  {La pente de (AB) est: $\pgfmathprintnumber{\SAB}$}     
  \tkzText[fill=Gold!50,draw=brown](1,3.5)%
  {La pente de (AC) est: $\pgfmathprintnumber{\SAC}$}    
  \tkzText[fill=Gold!50,draw=brown](1,3)%
  {La pente de (AD) est: $\pgfmathprintnumber{\SAD}$}
\end{tikzpicture}
\end{tkzexample}

\subsection{Angle formed by a straight line with the horizontal axis}
Much more interesting than the last one. The result is between -180 degrees and +180 degrees.

\begin{NewMacroBox}{tkzFindSlopeAngle}{\parg{pt1,pt2}}%
The result is stored in a macro \tkzcname{tkzAngleResult}.

\medskip
\begin{tabular}{lll}
\toprule
arguments             & example & explication                         \\
\midrule
\TAline{(pt1,pt2)} {\tkzcname{tkzFindSlopeAngle}(A,B)}{\tkzcname{tkzGetAngle} can retrieve the result}
\bottomrule
\end{tabular}

\medskip
{If recovery is not necessary, it is possible to use \tkzcname{tkzAngleResult}}
\end{NewMacroBox}


\subsubsection{Example of use of \tkzcname{tkzFindSlopeAngle}}
Here is another version of the construction of a mediator

\begin{tkzexample}[latex=6cm,small]
\begin{tikzpicture}
 \tkzInit
 \tkzDefPoint(0,0){A}        \tkzDefPoint(3,2){B}
 \tkzDefLine[mediator](A,B)  \tkzGetPoints{I}{J}
 \tkzCalcLength[cm](A,B)     \tkzGetLength{dAB}
 \tkzFindSlopeAngle(A,B)     \tkzGetAngle{tkzangle}
 \begin{scope}[rotate=\tkzangle]
   \tikzset{arc/.style={color=gray,delta=10}}
   \tkzDrawArc[R,arc](B,3/4*\dAB)(120,240)
   \tkzDrawArc[R,arc](A,3/4*\dAB)(-45,60)
   \tkzDrawLine(I,J)         \tkzDrawSegment(A,B)
  \end{scope}
  \tkzDrawPoints(A,B,I,J)    \tkzLabelPoints(A,B)
   \tkzLabelPoints[right](I,J)
\end{tikzpicture}
\end{tkzexample}

\subsection{from an angle}
In the previous example, I used the macro \tkzcname{tkzGetAngle} to retrieve an angle.

\begin{NewMacroBox}{tkzGetAngle}{\marg{name of macro}}%
This macro retrieves \tkzcname{tkzAngleResult} and stores the result in a new macro.

\medskip

\begin{tabular}{lll}%
\toprule
arguments             & example & explication                         \\
\midrule
\TAline{name of macro} {\tkzcname{tkzGetAngle}\{ang\}}{\tkzcname{ang} contains the value of the angle. }
\end{tabular}
\end{NewMacroBox}

\subsection{Example of the use of \tkzcname{tkzGetAngle}}

 The point here is that $(AB)$ is the bisector of $\widehat{CAD}$, such that the $AD$ slope is zero. We recover the slope of $(AB)$ and then rotate twice.

\begin{tkzexample}[vbox,small]
\begin{tikzpicture}
  \tkzInit
  \tkzDefPoint(1,5){A} \tkzDefPoint(5,2){B}  
  \tkzDrawSegment(A,B)
  \tkzFindSlopeAngle(A,B)\tkzGetAngle{tkzang}
  \tkzDefPointBy[rotation= center A angle \tkzang ](B)
   \tkzGetPoint{C}
  \tkzDefPointBy[rotation= center A angle -\tkzang ](B) 
  \tkzGetPoint{D}
  \tkzCompass[length=1,dashed,color=red](A,C)
  \tkzCompass[delta=10,brown](B,C)  
   \tkzDrawPoints(A,B,C,D)
  \tkzLabelPoints(B,C,D)  
  \tkzLabelPoints[above left](A)
  \tkzDrawSegments[style=dashed,color=orange!30](A,C A,D)
\end{tikzpicture}
\end{tkzexample}

\subsection{Angle formed by three points}
\begin{NewMacroBox}{tkzFindAngle}{\parg{pt1,pt2,pt3}}%
The result is stored in a macro \tkzcname{tkzAngleResult}.

\medskip
\begin{tabular}{lll}
\toprule
arguments             & example & explication                         \\
\midrule
\TAline{(pt1,pt2,pt3)} {\tkzcname{tkzFindAngle}(A,B,C)}{\tkzcname{tkzAngleResult} gives the angle ($\overrightarrow{BA},\overrightarrow{BC}$)}
\bottomrule
\end{tabular}

\medskip
The result is between -180 degrees and +180 degrees. pt2 is the vertex and \tkzcname{tkzGetAngle} can retrieve the angle.
\end{NewMacroBox}

\subsection{Example of use of \tkzcname{tkzFindAngle} }
\begin{tkzexample}[vbox,small]
\begin{tikzpicture}
   \tkzInit[xmin=-1,ymin=-1,xmax=7,ymax=7]
   \tkzClip  
   \tkzDefPoint (0,0){O}  \tkzDefPoint (6,0){A}
   \tkzDefPoint (5,5){B}  \tkzDefPoint (3,4){M}
   \tkzFindAngle (A,O,M)  \tkzGetAngle{an}   
   \tkzDefPointBy[rotation=center O angle \an](A) 
   \tkzGetPoint{C}
   \tkzDrawSector[fill = blue!50,opacity=.5](O,A)(C)
   \tkzFindAngle(M,B,A)   \tkzGetAngle{am}
   \tkzDefPointBy[rotation = center O angle \am](A) 
   \tkzGetPoint{D} 
   \tkzDrawSector[fill = red!50,opacity = .5](O,A)(D) 
   \tkzDrawPoints(O,A,B,M,C,D)   
   \tkzLabelPoints(O,A,B,M,C,D) 
	\edef\an{\fpeval{round(\an,2)}}\edef\am{\fpeval{round(\am,2)}}
   \tkzDrawSegments(M,B B,A)
   \tkzText(4,2){$\widehat{AOC}=\widehat{AOM}=\an^{\circ}$} 
   \tkzText(1,4){$\widehat{AOD}=\widehat{MBA}=\am^{\circ}$}  
\end{tikzpicture}
\end{tkzexample}

\subsection{\tkzcname{tkzCalcLength}}
There's an option in \TIKZ\  name in \tkzname{veclen}. This option
 is used to calculate AB if A and B are two points.

The only problem for me is that the version of \TIKZ\ is not accurate enough in some cases. My version uses the \tkzNamePack{xfp} package and is slower, but more accurate.
 \hypertarget{tpsc}{} 
\begin{NewMacroBox}{tkzCalcLength}{\oarg{local options}\parg{pt1,pt2}\marg{name of macro}}%
\begin{tabular}{lll}%
arguments             & example & explication                         \\
\midrule
\TAline{(pt1,pt2)\{name of macro\}} {\tkzcname{tkzCalcLength}(A,B)\{dAB\}}{\tkzcname{dAB} donne  $AB$ en pt}
\bottomrule
\end{tabular}

\medskip
Une seule option

\begin{tabular}{lll}%
 options             & default & example                         \\
\midrule
\TOline{cm}  {false}{\tkzcname{tkzCalcLength}[cm](A,B)\{dAB\} \tkzcname{dAB} gives AB en cm}
\end{tabular}

The result is stored in a macro.
\end{NewMacroBox}

\subsubsection{Compass square construction}

\begin{tkzexample}[latex=7cm,small]
\begin{tikzpicture}[scale=1]
  \tkzDefPoint(0,0){A} \tkzDefPoint(4,0){B}
  \tkzDrawLine[add= .6 and .2](A,B)
  \tkzCalcLength[cm](A,B)\tkzGetLength{dAB}
  \tkzDefLine[perpendicular=through A](A,B)
  \tkzDrawLine(A,tkzPointResult) \tkzGetPoint{D}
  \tkzShowLine[orthogonal=through A,gap=2](A,B)
  \tkzMarkRightAngle(B,A,D)
  \tkzVecKOrth[-1](B,A)\tkzGetPoint{C}
  \tkzCompasss(A,D D,C)
  \tkzDrawArc[R](B,\dAB)(80,110)
  \tkzDrawPoints(A,B,C,D)
  \tkzDrawSegments[color=gray,style=dashed](B,C C,D)
  \tkzLabelPoints(A,B,C,D)
\end{tikzpicture}
\end{tkzexample}

\subsection{Transformation from pt to cm or cm to pt}
Not sure if this is necessary and it is only a division by 28.45274 and a multiplication by the same number. The macros are:

\begin{NewMacroBox}{tkzpttocm}{\parg{nombre}\marg{name of macro}}%
The result is stored in a macro.

\medskip
\begin{tabular}{lll}%
\toprule
arguments             & example & explication                         \\
\midrule
\TAline{(nombre){name of macro}} {\tkzcname{tkzpttocm}(120)\{len\}}{\tkzcname{len} donne un nombre de tkzname{cm}}
\bottomrule
\end{tabular}

\medskip
You'll have to use \tkzcname{len} along with \tkzname{cm}.
\end{NewMacroBox}

\subsection{Change of unit} 
\begin{NewMacroBox}{tkzcmtopt}{\parg{nombre}\marg{name of macro}}%
The result is stored in a macro.

\medskip
\begin{tabular}{lll}
\toprule
arguments             & example & explication                         \\
\midrule
\TAline{(nombre)\{name of macro\}}{\tkzcname{tkzcmtopt}(5)\{len\}}{\tkzcname{len} longueur en \tkzname{pts}}
\bottomrule
\end{tabular}

\medskip
\noindent{The result can be used with \tkzcname{len}\tkzname{pt}}
\end{NewMacroBox}

\subsubsection{Example}
The macro \tkzcname{tkzDefCircle[radius](A,B)} defines the radius that we retrieve with \tkzcname{tkzGetLength}, but this result is in \tkzname{pt}.

\begin{tkzexample}[latex=6cm,small]
\begin{tikzpicture}[scale=.5]
 \tkzDefPoint(0,0){A}
 \tkzDefPoint(3,-4){B}
 \tkzDefCircle[through](A,B)
 \tkzGetLength{rABpt}
 \tkzpttocm(\rABpt){rABcm}
 \tkzDrawCircle(A,B)
 \tkzDrawPoints(A,B)
 \tkzLabelPoints(A,B)
 \tkzDrawSegment[dashed](A,B)
 \tkzLabelSegment(A,B){$\pgfmathprintnumber{\rABcm}$}
\end{tikzpicture}
\end{tkzexample}

%<--------------------------------------------------------------------------–>
%                    Coordonnées d'un point 
%    result in #2x et #2y    #1 est le point et on récupère ses coordonnées
% usage soit A un point \tkzGetPointCoord(A){V} alors \Vx = xA et \Vy = yA
% en cm 
% tkzGetPointCoord avec [#1] cm ou bien pt ?? todo
%<--------------------------------------------------------------------------–>
\begin{NewMacroBox}{tkzGetPointCoord}{\parg{$A$}\marg{name of macro}}%
Stores in two macros the coordinates of a point

\medskip
\begin{tabular}{lll}
\toprule
arguments             & example & explanation                         \\
\midrule
\TAline{(point)\{name of macro\}} {\tkzcname{tkzGetPointCoord}(A)\{A\}}{\tkzcname{Ax} and \tkzcname{Ay} give the coordinates of $A$}
\end{tabular}

\medskip
If the name of the macro is \tkzname{p}, then \tkzcname{px} and \tkzcname{py} give the coordinates of the chosen point with the cm as.
\end{NewMacroBox}

\subsubsection{Coordinate transfer with \tkzcname{tkzGetPointCoord}}
\begin{tkzexample}[width=8cm,small]
\begin{tikzpicture}
 \tkzInit[xmax=5,ymax=3]
 \tkzGrid[sub,orange]
 \tkzAxeXY
 \tkzDefPoint(1,0){A}
 \tkzDefPoint(4,2){B}
 \tkzGetPointCoord(A){a}
 \tkzGetPointCoord(B){b}
 \tkzDefPoint(\ax,\ay){C}
 \tkzDefPoint(\bx,\by){D}
 \tkzDrawPoints[color=red](C,D)
\end{tikzpicture}
\end{tkzexample}

\subsubsection{Sum of vectors with \tkzcname{tkzGetPointCoord}}
\begin{tkzexample}[width=6cm,small]
\begin{tikzpicture}[>=latex]
   \tkzDefPoint(1,4){a}
   \tkzDefPoint(3,2){b}
   \tkzDefPoint(1,1){c}
   \tkzDrawSegment[->,red](a,b)
   \tkzGetPointCoord(c){c}
   \draw[color=blue,->](a) -- ([shift=(b)]\cx,\cy) ;
   \draw[color=purple,->](b) -- ([shift=(b)]\cx,\cy) ;
   \tkzDrawSegment[->,blue](a,c)
   \tkzDrawSegment[->,purple](b,c)
\end{tikzpicture}
\end{tkzexample}

\endinput