Debian Codegraph @

texmf-dist/doc/latex/tkz-elements/TKZdoc-elements-classes-point.tex

raw
1 \newpage
2
3 \section{Class \tkzClass{point}}
4 A point in tkz-elements is internally represented as a complex number (its affix). This choice enables concise computations (translation, rotation, scaling) while remaining compatible with TikZ/tkz-euclide for rendering.
5
6
7 The variable \tkzVar{point}{z} holds a table used to store points. It is \textbf{mandatory} and is automatically initialized by the package (e.g.,\tkzname{ z = \{\}}).
8
9
10 \vspace{1em}
11 The \tkzClass{point} class forms the foundation of the entire framework. It is a hybrid class, representing both points in the plane and complex numbers. The underlying principle is as follows:
12
13 \begin{itemize}
14 \item The plane is equipped with an orthonormal basis (OCCS See [\ref{sec:orthonormal_cartesian_coordinate_system}]), allowing us to determine a point's position via its abscissa and ordinate.
15 \item Similarly, any complex number can be seen as an ordered pair of real numbers (its real and imaginary parts).
16 \item Therefore, the plane can be identified with the complex plane, and a complex number $x + iy$ is represented by a point in the plane with coordinates $(x, y)$.
17 \end{itemize}
18
19 Thus, a point such as $A$ is stored as the object \code{z.A}, with its coordinates and associated properties encapsulated within this object.
20
21 \vspace{1em}
22 The \code{point} object possesses several attributes:
23 \begin{mybox}{}
24 \begin{itemize}
25 \item \code{re} --> the real part (abscissa),
26 \item \code{im} --> the imaginary part (ordinate),
27 \item \code{type} --> the type of the object (in this case, always \code{"point"}),
28 \item \code{arg} --> the argument of the complex number (angle with respect to the x-axis),
29 \item \code{mod} --> the modulus of the complex number (distance from the origin).
30 \end{itemize}
31 \end{mybox}
32
33
34
35 \subsection{Creating a point}
36 \label{sub:creating_a_point}
37
38 Points are created by providing their coordinates in the current orthonormal Cartesian coordinate system (OCCS). The recommended form is:
39
40 \begin{mybox}
41 \code{z.A = point(x, y)}
42 \end{mybox}
43
44 where \code{x} and \code{y} are real numbers corresponding to the $x$ and $y$ coordinates of the point.
45
46 \medskip
47
48 Internally, this creates a complex number $x + i y$ and stores it in the table \tkzVar{point}{z} under the key \code{"A"}. The table \tkzVar{point}{z} is used to reference all points by their label.
49
50 \medskip
51
52 Alternatively, the more explicit syntax is also available:
53
54 \begin{center}
55 \code{z.A = point:new(x, y)}
56 \end{center}
57
58
59 Both forms are equivalent. The shorthand constructor is available since version 4 and preferred for readability and consistency.
60
61
62 \def\size{42mm}
63 \begin{tikzpicture}[remember picture]
64 \node[ draw, fill=red!10] (tbl) {%
65 \centering
66 \begin{minipage}{\size}
67
68 \hspace{\fill} \texttt{Arguments}\hspace{\fill}
69
70 \tikz\node[minimum width=\size,font=\small,
71 draw, fill=cyan!10,
72 rectangle split, rectangle split parts=6
73 ] {
74 \texttt{re (real)}
75 \nodepart{two}\texttt{im (real)}
76 \nodepart{three}\texttt{type = 'point'}
77 \nodepart{four}\texttt{argument (rad)}
78 \nodepart{five}\texttt{modulus (cm)}
79 \nodepart{six}\texttt{mtx (matrix)}
80 };
81
82 \hspace{\fill} \texttt{Methods}\hspace{\fill}
83
84 \tikz\node[minimum width=\size,font=\small,
85 draw, fill=orange!20,sharp corners,
86 rectangle split, rectangle split parts=4
87 ] {
88 \texttt{homothety(coeff,obj)}
89 \nodepart{two}\texttt{rotation(angle, object)}
90 \nodepart{three}\texttt{symmetry (object)}
91 \nodepart{four}\texttt{\ldots}
92 };
93 \end{minipage}};
94 \node[ draw, fill=red!10,,minimum height = 2em,
95 rounded corners,anchor=south] (tc) at (tbl.north){Class |Point|};
96 \end{tikzpicture}
97 \hspace{5cm}\begin{tikzpicture}[remember picture]
98 \node[ draw, fill=red!10] (tbl) {%
99 \centering
100 \begin{minipage}{\size}
101 \hspace{\fill} \texttt{Arguments}\hspace{\fill}
102
103 \tikz\node[minimum width=\size,font=\small,
104 draw, fill=cyan!10,
105 rectangle split, rectangle split parts=6
106 ] {
107 \texttt{re = 1}
108 \nodepart{two}\texttt{im = 2}
109 \nodepart{three}\texttt{type = 'point'}
110 \nodepart{four}\texttt{argument = atan(2)}
111 \nodepart{five}\texttt{modulus = $\sqrt{5}$}
112 \nodepart{six}\texttt{mtx = \{\{1\},\{2\}\}}
113 };
114
115 \hspace{\fill} \texttt{Methods}\hspace{\fill}
116
117 \tikz\node[minimum width=\size,font=\small,
118 draw, fill=orange!20,sharp corners,
119 rectangle split, rectangle split parts=4
120 ] {
121 \texttt{homothety(coeff,obj)}
122 \nodepart{two}\texttt{rotation(angle, object)}
123 \nodepart{three}\texttt{symmetry (object)}
124 \nodepart{four}\texttt{\ldots}
125 };
126 \end{minipage}
127 };
128 \node[ draw, fill=red!10,remember picture,minimum height = 2em,
129 rounded corners,anchor=south] (to) at (tbl.north){object |z.A|};
130 \end{tikzpicture}
131
132 \begin{tikzpicture}[remember picture,overlay]
133 \draw [thick,->](tc.east) -- (to.west);
134 \end{tikzpicture}
135
136
137 \subsection{Attributes of a point}
138 \label{sub:attributes_of_a_point}
139 % Method \tkzMeth{point}{new}
140
141 \begin{mybox}
142 Creation \\
143 |z.A = point(1, 2) |
144 \end{mybox}
145 The point $A$ has coordinates $x=1$ and $y=2$. If you use the notation |z.A|, then $A$ will be referenced as a node in \TIKZ\ or in \tkzNamePack{tkz-euclide}.
146
147 This is the creation of a fixed point with coordinates $1$ and $2$ and which is named $A$. The notation \tkzname{z.A} indicates that the coordinates will be stored in a table assigned to the variable \tkzVar{point}{z} (reference to the notation of the affixes of the complex numbers) that $A$ is the name of the point and the key allowing access to the values.
148
149 \label{point:attributes}
150 \bgroup
151 \small
152 \catcode`_=12
153 \captionof{table}{Point attributes.}
154 \begin{tabular}{lll}
155 \toprule
156 \texttt{Attributes} & \textbf{Description}& \texttt{Example / Reference} \\
157 \midrule
158 \tkzAttr{point}{type} & Object type name, always \texttt{"point"} & \\
159 \tkzAttr{point}{re} & Real part (i.e., $x$-coordinate) & [\ref{ssub:methods}] \\
160 \tkzAttr{point}{im} & Imaginary part (i.e., $y$-coordinate) & [\ref{ssub:methods}] \\
161 \tkzAttr{point}{argument} & Argument of the affix (angle in radians) & $\approx$ \code{0.785398...} \quad [\ref{ssub:example_point_attributes}] \\
162 \tkzAttr{point}{modulus} & Modulus of the affix (distance to origin) & $\sqrt{5} \approx$ \code{2.2360...} \quad [\ref{ssub:example_point_attributes}] \\
163 \tkzAttr{point}{mtx} & Matrix representation as column vector & \code{z.A.mtx = \{\{1\},\{2\}\}} \quad [\ref{ssub:example_point_attributes}] \\
164 \bottomrule
165 \end{tabular}
166 \egroup
167
168
169 \subsubsection{Example: point attributes}
170 \label{ssub:example_point_attributes}
171
172 \directlua{
173 init_elements()
174 z.M = point(1, 2)}
175 \hspace*{\fill}
176
177 \begin{verbatim}
178 \directlua{
179 init_elements()
180 z.M = point(1, 2)}
181 \end{verbatim}
182 \pgfkeys{/pgf/number format/.cd,std,precision=2}
183 \let\pmpn\pgfmathprintnumber
184 \DeleteShortVerb{\|}
185
186 \begin{verbatim}
187 \begin{tikzpicture}[scale = 1]
188 \pgfkeys{/pgf/number format/.cd,std,precision=2}
189 \let\pmpn\pgfmathprintnumber
190 \tkzDefPoints{2/4/M,2/0/A,0/0/O,0/4/B}
191 \tkzLabelPoints(O)
192 \tkzMarkAngle[fill=gray!30,size=1](A,O,M)
193 \tkzLabelAngle[pos=1,right](A,O,M){%
194 $\theta \approx \pmpn{\tkzUseLua{z.M.argument}}$ rad}
195 \tkzDrawSegments(O,M)
196 \tkzLabelSegment[above,sloped](O,M){%
197 $|z_M| =\sqrt{5}\approx \pmpn{%
198 \tkzUseLua{z.M.modulus}}$ cm}
199 \tkzLabelPoint[right](M){$M: z_M = 1 + 2i$}
200 \tkzDrawPoints(M,A,O,B)
201 \tkzPointShowCoord(M)
202 \tkzLabelPoint[below,teal](A){$\tkzUseLua{z.M.re}$}
203 \tkzLabelPoint[left,teal](B){$\tkzUseLua{z.M.im}$}
204 \tkzDrawSegments[->,add = 0 and 0.25](O,B O,A)
205 \end{tikzpicture}
206 \end{verbatim}
207
208
209 \begin{center}
210 \begin{tikzpicture}
211 \pgfkeys{/pgf/number format/.cd,std,precision=2}
212 \let\pmpn\pgfmathprintnumber
213 \tkzDefPoints{2/4/M,2/0/A,0/0/O,0/4/B}
214 \tkzLabelPoints(O)
215 \tkzMarkAngle[fill=gray!30,size=1](A,O,M)
216 \tkzLabelAngle[pos=1,right](A,O,M){%
217 $\theta \approx \pmpn{\tkzUseLua{z.M.argument}}$ rad}
218 \tkzDrawSegments(O,M)
219 \tkzLabelSegment[above,sloped](O,M){%
220 $|z_M| =\sqrt{5}\approx \pmpn{\tkzUseLua{z.M.modulus}}$ cm}
221 \tkzLabelPoint[right](M){$M: z_M = 1 + 2i$}
222 \tkzDrawPoints(M,A,O,B)
223 \tkzPointShowCoord(M)
224 \tkzLabelPoint[below,teal](A){$\tkzUseLua{z.M.re}$}
225 \tkzLabelPoint[left,teal](B){$\tkzUseLua{z.M.im}$}
226 \tkzDrawSegments[->,add = 0 and 0.25](O,B O,A)
227 \begin{scope}[every annotation/.style={fill=lightgray!15,anchor = east}]
228 \node [annotation,font =\small,text width=6cm] at (current bounding box.west) {
229 Attributes of \texttt{z.M}
230 \begin{mybox}{}
231 \begin{itemize}
232 \item \texttt{z.M.re} = 1
233 \item \texttt{z.M.im} = 2
234 \item \texttt{z.M.type} = point
235 \item \texttt{z.M.argument} = $\theta \approx \pmpn{\tkzUseLua{z.M.argument}}$ rad
236 \item \texttt{z.M.modulus} = $|z_M| =\sqrt{5}\approx \pmpn{\tkzUseLua{z.M.modulus}}$ cm
237 \item \texttt{z.M.mtx} = \tkzUseLua{z.M.mtx:print()}
238 \end{itemize}
239 \end{mybox}
240 };
241 \end{scope}
242 \end{tikzpicture}
243 \end{center}
244
245 \MakeShortVerb{\|}
246
247
248 \subsubsection{Attribute \tkzAttr{point}{mtx}}
249 \label{ssub:attribute_iattr_point_mtx}
250
251 This attribute allows the point to be used in conjunction with matrices.
252
253 \vspace{1em}
254 \begin{minipage}{.5\textwidth}
255 \begin{verbatim}
256 \directlua{
257 z.A = point(2, -1)
258 z.A.mtx:print()}
259 \end{verbatim}
260 \end{minipage}
261 \begin{minipage}{.5\textwidth}
262 \begin{center}
263 \directlua{
264 z.A = point(2, -1)
265 z.A.mtx:print()}
266 \end{center}
267 \end{minipage}
268
269 \subsubsection{Argand diagram}
270 \label{ssub:argand_diagram}
271 \normalsize
272 \begin{minipage}{\textwidth}
273 \begin{verbatim}
274 \directlua{
275 init_elements()
276 z.A = point(2, 3)
277 z.O = point(0, 0)
278 z.I = point(1, 0)}
279 \begin{tikzpicture}
280 \tkzGetNodes
281 \tkzInit[xmin=-4,ymin=-4,xmax=4,ymax=4]
282 \tkzDrawCircle[dashed,red](O,A)
283 \tkzPointShowCoord(A)
284 \tkzDrawPoint(A)
285 \tkzLabelPoint[above right](A){\normalsize $a+ib$}
286 \tkzDrawX\tkzDrawY
287 \tkzDrawSegment(O,A)
288 \tkzLabelSegment[above,anchor=south,sloped](O,A){ OA = modulus of $z_A$}
289 \tkzLabelAngle[anchor=west,pos=.5](I,O,A){$\theta$ = argument of $z_A$}
290 \end{tikzpicture}
291 \end{verbatim}
292 \end{minipage}
293
294 \begin{minipage}{\textwidth}
295 \directlua{
296 init_elements()
297 z.A = point(2, 3)
298 z.O = point(0, 0)
299 z.I = point(1, 0)}
300 \begin{center}
301 \begin{tikzpicture}
302 \tkzGetNodes
303 \tkzInit[xmin=-4,ymin=-4,xmax=4,ymax=4]
304 \tkzDrawCircle[dashed,red](O,A)
305 \tkzPointShowCoord(A)
306 \tkzDrawPoint(A)
307 \tkzLabelPoint[above right](A){\normalsize $a+ib$}
308 \tkzDrawX\tkzDrawY
309 \tkzDrawSegment(O,A)
310 \tkzLabelSegment[above,anchor=south,sloped](O,A){ OA = modulus of $z_A$}
311 \tkzLabelAngle[anchor=west,pos=.5](I,O,A){$\theta$ = argument of $z_A$}
312 \end{tikzpicture}
313 \end{center}
314 \end{minipage}
315
316 \newpage
317 \subsection{Methods of the class point}
318
319 The methods listed in the following table are standard and commonly used throughout the examples at the end of this documentation. Each of these methods returns a \tkzNameObj{point} object.
320
321 \medskip
322
323 For more advanced operations using complex numbers and operator overloading, see section~\ref{sub:complex_numbers}, which describes the available metamethods.
324
325
326 \vspace{1em}
327
328 \bgroup
329 \catcode`_=12
330 \small
331 \captionof{table}{Functions and Methods of the \code{class} point.}\label{point:methods}
332 \begin{tabular}{lll}
333 \toprule
334
335 \texttt{Methods} & \texttt{Reference} \\
336 \midrule
337 \texttt{Constructors} &\\
338 \midrule
339 \tkzMeth{point}{new(r,r)} &[\ref{ssub:method_point_new}; \ref{ssub:method_normalize}]\\
340 \tkzMeth{point}{polar(d,an)} &[\ref{ssub:method_point_polar}] \\
341 \tkzMeth{point}{polar\_deg(d,an)} &[\ref{ssub:method_point_polar_deg}] \\
342 \midrule
343 \texttt{Methods Returning a Real Number} & \\
344 \midrule
345 \tkzMeth{point}{get()} &[\ref{ssub:method_point_get}] \\
346 \midrule
347 \texttt{Methods Returning a Point} & \\
348 \midrule
349 \tkzMeth{point}{north(r)} & [\ref{ssub:methods}] \\
350 \tkzMeth{point}{south(r)} & \\
351 \tkzMeth{point}{east(r)} & \\
352 \tkzMeth{point}{west(r)} & \\
353 \tkzMeth{point}{normalize()} & [\ref{ssub:method_normalize}] \\
354 \tkzMeth{point}{normalize\_from(pt)} & [\ref{ssub:method_normalize}] \\
355 \tkzMeth{point}{orthogonal(d)} & [\ref{ssub:orthogonal_method}]\\
356 \tkzMeth{point}{at()} & [\ref{ssub:_point_at_method}] \\
357 \tkzMeth{point}{shift\_orthogonal\_to(pt, d)}& [\ref{shift_orthogonal}] \\
358 \tkzMeth{point}{shift\_collinear\_to(pt, d)} & [\ref{shift_collinear}] \\
359 \midrule
360 \texttt{Methods Returning a Circle} & \\
361 \midrule
362 \tkzMeth{point}{PPP(a,b)} &[\ref{ssub:point_PPP}]\\
363 \midrule
364 \texttt{Methods Returning a Object} & \\
365 \midrule
366 \tkzMeth{point}{symmetry(obj)} & [\ref{ssub:object_symmetry}] \\
367 \tkzMeth{point}{rotation(an, obj)} & [\ref{ssub:object_rotation}] \\
368 \tkzMeth{point}{homothety(r,obj)} & [\ref{ssub:method_point_homothety_k_obj}] \\
369 \midrule
370
371 \texttt{Utilities} &\\
372 \midrule
373 \tkzMeth{point}{identity(pt)} & [\ref{ssub:identity}]\\
374 \tkzMeth{point}{print()} & [\ref{ssub:print}]\\
375 \bottomrule %
376 \end{tabular}
377 \egroup
378
379
380 \subsubsection{Method \tkzMeth{point}{new(r, r)}}
381 \label{ssub:method_point_new}
382
383 This method creates a point in the plane using Cartesian coordinates. The \textbf{shorthand constructor} \tkzMeth{point}{(r, r)} is available since version 4 and preferred for readability and consistency.
384
385 \medskip
386
387 It takes two real numbers as arguments: the first represents the \emph{abscissa} (real part), and the second the \emph{ordinate} (imaginary part). Internally, the point is treated as a complex number and stored in the global table \tkzname{z}.
388
389 \medskip
390
391 The resulting object is of type \tkzNameObj{point}, and can be used in further geometric constructions or displayed with \tkzNamePack{tkz-euclide}.
392
393 \medskip
394
395 \smallbf{Note:} The default unit is the centimeter, in accordance with the conventions of \tkzNamePack{tkz-euclide}. All coordinates are interpreted in an orthonormal Cartesian coordinate system.
396
397 \vspace{1em}
398
399 \begin{tkzexample}[latex = 7cm]
400 \directlua{
401 init_elements()
402 z.A = point(0, 0)
403 z.B = point(2, 1)}
404 \begin{tikzpicture}[gridded]
405 \tkzGetNodes
406 \tkzDrawPoints(A,B)
407 \tkzLabelPoints(A,B)
408 \end{tikzpicture}
409 \end{tkzexample}
410
411 \subsubsection{Method \tkzMeth{point}{get()}}
412 \label{ssub:method_point_get}
413
414 The \code{get} method is used to retrieve the Cartesian coordinates of a point.
415
416 \medskip
417
418 Let $I$ be the intersection point of two lines. You can obtain its coordinates in two equivalent ways:
419 \begin{itemize}
420 \item using the point’s attributes directly:
421 \begin{center}
422 \code{x = z.I.re} \quad and \quad \code{y = z.I.im}
423 \end{center}
424 \item or using the \code{get()} method:
425 \begin{center}
426 \code{x, y = z.I:get()}
427 \end{center}
428 \end{itemize}
429
430
431 This method improves code readability and makes it easier to pass coordinates to functions that expect numerical values.
432
433 \vspace{1em}
434
435 \begin{minipage}{.5\textwidth-1cm}
436 \directlua{
437 init_elements()
438 z.A, z.B = point(0, 0), point(5, -1)
439 z.C, z.D = point(1, -4), point(4, 2)
440 L.AB = line(z.A, z.B)
441 L.CD = line(z.C, z.D)
442 z.I = intersection(L.AB, L.CD)
443 x, y = z.I:get()
444 tex.print("$x_I = $"..x)
445 tex.print('\\\\')
446 tex.print("$y_I = $"..y)}
447 \end{minipage}
448 \begin{minipage}{.5\textwidth}
449 \begin{tkzexample}[code only]
450 \directlua{
451 init_elements()
452 z.A, z.B = point(0, 0), point(5, -1)
453 z.C, z.D = point(1, -4), point(4, 2)
454 L.AB = line(z.A, z.B)
455 L.CD = line(z.C, z.D)
456 z.I = intersection(L.AB, L.CD)
457 x, y = z.I:get()
458 tex.print("$x_I = $"..x)
459 tex.print('\\\\')
460 tex.print("$y_I = $"..y)}
461 \end{tkzexample}
462 \end{minipage}
463
464 \subsubsection{Function \tkzFct{point}{polar(r, an)}}
465 \label{ssub:method_point_polar}
466
467 This method creates a point in the plane using polar coordinates.
468
469 \medskip
470
471 It takes two arguments:
472 \begin{itemize}
473 \item \code{r} —> the modulus (distance from the origin),
474 \item \code{an} —> the argument (angle in radians).
475 \end{itemize}
476
477
478 Internally, the point is represented as a complex number: \code{r * exp(i * an)}. This method is particularly useful for constructing points on circles or for defining points in terms of angle and distance.
479
480 \medskip
481
482 \textbf{Note:} The default unit is the centimeter, consistent with the conventions of \tkzNamePack{tkz-euclide}. All coordinates are interpreted in an orthonormal Cartesian coordinate system.
483
484 \vspace{1em}
485
486 \begin{mybox}
487 \begin{verbatim}
488 z.B = polar(2, math.pi / 4)
489 or
490 z.B = point:polar(2, math.pi / 4)
491 \end{verbatim}
492 \end{mybox}
493
494 \begin{tkzexample}[latex = 7cm]
495 \directlua{
496 init_elements()
497 z.O = point(0, 0)
498 z.A = point(3, 0)
499 z.F = polar(3, math.pi / 3)}
500 \begin{center}
501 \begin{tikzpicture}[scale=.75]
502 \tkzGetNodes
503 \tkzDrawCircle(O,A)
504 \tkzDrawSegments[new](O,A)
505 \tkzDrawSegments[purple](O,F)
506 \tkzDrawPoints(A,O,F)
507 \tkzLabelPoints[below right=6pt](A,O)
508 \tkzLabelPoints[above](F)
509 \end{tikzpicture}
510 \end{center}
511
512 \end{tkzexample}
513
514 \subsubsection{Method \tkzMeth{point}{polar\_deg(d,an)}}
515 \label{ssub:method_point_polar_deg}
516
517 Identical to the previous one, except that the angle is given in degrees.
518
519 \begin{tkzexample}[latex=7cm]
520 \directlua{
521 init_elements()
522 z.A = point(0, 0)
523 z.B = polar_deg(3, 60)
524 z.C = polar_deg(3, 0)}
525 \begin{center}
526 \begin{tikzpicture}[gridded]
527 \tkzGetNodes
528 \tkzDrawPolygon(A,B,C)
529 \tkzDrawPoints(A,B,C)
530 \tkzLabelPoints(A,C)
531 \tkzLabelPoints[above](B)
532 \end{tikzpicture}
533 \end{center}
534 \end{tkzexample}
535
536 \subsubsection{Method \tkzMeth{point}{north(d)}}
537 \label{ssub:example_method_point_north_d}
538
539 This method creates a new point located at a vertical distance from the given point, along the line passing through it and directed upward (toward the north).
540
541 \medskip
542
543 It is particularly useful when you want to construct a point offset by a specific distance above a reference point—for example, to place a label or construct a geometric configuration with a known height.
544
545 \medskip
546
547 The optional argument \code{d} represents the vertical distance. If omitted, a default value of $1$ is used.
548
549 \vspace{1em}
550
551
552 \begin{tkzexample}[latex = 7cm]
553 \directlua{
554 init_elements()
555 z.O = point(0, 0)
556 z.A = z.O:east()
557 z.Ap= z.O:east(1):north(1)
558 z.B = z.O:north()
559 z.C = z.O:west()
560 z.D = z.O:south()}
561 \begin{center}
562 \begin{tikzpicture}
563 \tkzGetNodes
564 \tkzDrawPolygon(A,B,C,D)
565 \tkzDrawPoints(A,B,C,D,O,A')
566 \end{tikzpicture}
567 \end{center}
568 \end{tkzexample}
569
570 \subsubsection{Method \tkzMeth{point}{normalize()}}
571 \label{ssub:method_normalize}
572
573 This method returns a new point located on the segment from the origin to the current point, at a distance of $1$ from the origin. It is typically used to extract the direction of a vector and normalize its length to one.
574
575 \medskip
576
577 You can also use this method to construct a point at a fixed distance from another point along a given direction. For example:
578
579 \begin{center}
580 \code{z.U = (z.C - z.B):normalize() + z.B}
581 \end{center}
582
583
584 Here, the vector $\overrightarrow{BU}$ has length $1$, and $U$ lies on the segment $[BC]$ in the direction from $B$ to $C$.
585
586 \medskip
587
588 There are two equivalent ways to achieve the same result:
589
590 \begin{mybox}
591 \begin{verbatim}
592 z.U = z.C:normalize_from(z.B)
593 z.U = L.BC:normalize()
594 \end{verbatim}
595 \end{mybox}
596
597
598 The second approach requires prior creation of the line object \code{L.BC}.
599
600 \vspace{1em}
601
602 \begin{tkzexample}[latex=8cm]
603 \directlua{
604 init_elements()
605 z.A = point(0, 0)
606 z.B = point(4, 3)
607 z.C = point(1, 5)
608 L.AB = line(z.A, z.B)
609 L.BC = line(z.B, z.C)
610 z.N = z.B:normalize()
611 z.U = z.C:normalize_from(z.B)}
612 \begin{tikzpicture}
613 \tkzGetNodes
614 \tkzDrawLines(A,B B,C)
615 \tkzDrawPoints(A,B,C,U,N)
616 \tkzLabelPoints(A,B,C,U,N)
617 \tkzDrawSegment(B,C)
618 \end{tikzpicture}
619 \end{tkzexample}
620
621 \subsubsection{Method \tkzMeth{point}{orthogonal(d)}}
622 \label{ssub:orthogonal_method}
623
624 Let $O$ be the origin of the plane, and let $A$ be a point distinct from $O$. This method constructs a new point $B$ such that the vectors $\overrightarrow{OB}$ and $\overrightarrow{OA}$ are orthogonal:
625
626 \[
627 \overrightarrow{OB} \perp \overrightarrow{OA}
628 \]
629
630 \medskip
631 \DeleteShortVerb{\|}
632 By default, the point $B$ is chosen so that $|OB| = |OA|$. If the optional argument \code{d} is provided, then the point $B$ is constructed so that $|OB| = d$.
633 \MakeShortVerb{\|}
634
635 \medskip
636
637 This method is useful for constructing perpendicular vectors or generating points on circles orthogonal to given directions.
638
639 \vspace{1em}
640
641
642 \begin{tkzexample}[latex=7cm]
643 \directlua{
644 init_elements()
645 z.A = point(3, 1)
646 z.B = z.A:orthogonal(1)
647 z.O = point(0, 0)
648 z.C = z.A:orthogonal()}
649 \begin{center}
650 \begin{tikzpicture}[gridded]
651 \tkzGetNodes
652 \tkzDrawSegments(O,A O,C)
653 \tkzDrawPoints(O,A,B,C)
654 \tkzLabelPoints[below right](O,A,B,C)
655 \end{tikzpicture}
656 \end{center}
657 \end{tkzexample}
658
659 \subsubsection{Method \tkzMeth{point}{at(pt)}}
660 \label{ssub:_point_at_method}
661
662 This method complements the \code{orthogonal} method. Instead of constructing a point $B$ such that $\overrightarrow{OB} \perp \overrightarrow{OA}$ (with $O$ as the origin), it constructs a point $B$ such that:
663
664 \[
665 \overrightarrow{AB} \perp \overrightarrow{OA}
666 \]
667
668
669 In this case, the reference direction remains $\overrightarrow{OA}$, but the orthogonal vector is constructed from point $A$, not the origin. The result is a point $B$ lying on a line orthogonal to $(OA)$ and passing through $A$.
670
671 \medskip
672
673 This method is useful when working with local orthogonal directions, such as when constructing altitudes in a triangle or defining perpendicular vectors anchored at a given point.
674
675 \vspace{1em}
676
677 \begin{tkzexample}[latex=7cm]
678 \directlua{
679 init_elements()
680 z.O = point(0, 0)
681 z.A = point(3, 2)
682 z.B = z.A:orthogonal(1)
683 z.C = z.A + z.B
684 z.D =(z.C - z.A):orthogonal(2):at(z.C)}
685 \begin{center}
686 \begin{tikzpicture}[gridded]
687 \tkzGetNodes
688 \tkzLabelPoints[below right](O,A,C)
689 \tkzLabelPoints[above](B,D)
690 \tkzDrawSegments(O,A A,B A,C C,D O,B)
691 \tkzDrawPoints(O,A,B,C,D)
692 \end{tikzpicture}
693 \end{center}
694 \end{tkzexample}
695
696 %====================================================================
697 \subsubsection{Method \tkzMeth{point}{PPP(a,b)}}
698 \label{ssub:point_PPP}
699 %====================================================================
700 This method is presented in the document \tkzname{Geometry Euclidean} [\href{https://altermundus.fr}{AlterMundus}]
701
702 \begin{tkzexample}[latex=.4\textwidth]
703 \directlua{
704 init_elements()
705 z.A = point(0, 0)
706 z.B = point(4, 0)
707 z.C = point(3, 4)
708 PA.center, PA.through, _ = z.A:PPP(z.B, z.C)
709 tkz.nodes_from_paths(PA.center, PA.through)
710 }
711
712 \begin{center}
713 \begin{tikzpicture}
714 \tkzGetNodes
715 \tkzDrawPolygon(A,B,C)
716 \tkzDrawCircles(w1,t1)
717 \tkzDrawPoints(A,B,C)
718 \end{tikzpicture}
719 \end{center}
720 \end{tkzexample}
721
722
723
724 \subsubsection{Method \tkzMeth{point}{shift\_orthogonal\_to(pt, dist)}}
725 \label{shift_orthogonal}
726
727 \medskip
728 \texttt{Syntax: } \verb|z.P = z.A:shift_orthogonal_to(z.B, 2)|
729
730 \medskip
731 \texttt{Return value}
732 This method returns the point obtained by shifting the current point
733 A in the direction orthogonal to the line (AB), at a signed distance dist.
734 A positive distance corresponds to a rotation of the vector $\overrightarrow{AB}$
735 by $+90^\circ$ around the point A, while a negative distance corresponds to
736 $-90^\circ$.
737
738 \begin{verbatim}
739 z.Q = z.B:shift_orthogonal_to(z.A, 2)
740 \end{verbatim}
741 A positive distance corresponds to a rotation of the vector $\overrightarrow{BA}$
742 by $+90^\circ$, around the point B.
743
744 \begin{tkzexample}[latex=.4\textwidth]
745 \directlua{
746 z.A = point(3, 2)
747 z.a = point(3, 3)
748 z.B = point(7, 3)
749 z.b = point(7, 4)
750 C.A = circle(z.A, z.a)
751 C.B = circle(z.B, z.b)
752 z.TA = z.A:shift_orthogonal_to(z.B, C.A.radius)
753 z.TB = z.B:shift_orthogonal_to(z.A, -C.A.radius)
754 }
755 \begin{tikzpicture}[gridded]
756 \tkzGetNodes
757 \tkzDrawCircles(A,a B,b)
758 \tkzDrawLines(A,B TA,TB)
759 \tkzDrawPoints(A,B,TA,TB)
760 \end{tikzpicture}
761 \end{tkzexample}
762
763 \subsubsection{Method \tkzMeth{point}{shift\_collinear\_to(pt, dist)}}
764 \label{shift_collinear}
765 This method returns the point obtained by shifting the current point
766 A in the same direction that line (AB), at a signed distance dist.
767
768 \medskip
769 \texttt{Syntax: } \verb|z.P = z.A:shift_collinear_to(z.B, 2)|
770
771
772
773 \subsubsection{Method \tkzMeth{point}{rotation(an, obj)}}
774 \label{ssub:object_rotation}
775
776 Comme les méthodes suivantes, la rotation autour d'un point peut s'appliquer à un point, un groupe de points ou bien à un objet.
777
778 This method performs a rotation of one or more points or an object around the current point, which serves as the center of rotation.
779
780
781 \medskip
782 \texttt{Purpose:}
783
784 This method rotates a geometric object by a given angle around a specified point.
785
786 In this example, the triangle is rotated by an angle of~$\pi/3$ around the point~$O$, which serves as the center of rotation.
787
788
789 \medskip
790 \texttt{Syntax: } \verb|new_obj = z.I:rotation(an, obj)|
791
792
793 \medskip
794 \texttt{Returns:}
795 \begin{itemize}
796 \item The result is a point (or a list of points) obtained by rotating each given point around the center by the specified angle.
797 \item The method returns a new object of the same type, rotated accordingly.
798 \end{itemize}
799
800
801 \medskip
802 \texttt{Example usage for a point or a list of points}
803
804 In the following example, a list of points is rotated about a given center.
805
806 \vspace{1em}
807
808 \begin{tkzexample}[latex=7cm]
809 \directlua{
810 init_elements()
811 z.a = point(0, -1)
812 z.b = point(4, 0)
813 z.o = point(6, -2)
814 z.ap,
815 z.bp = z.o:rotation(math.pi / 2, z.a, z.b)}
816 \begin{center}
817 \begin{tikzpicture}[scale = .5]
818 \tkzGetNodes
819 \tkzDrawLines(o,a o,a' o,b o,b')
820 \tkzDrawPoints(a,a',b,b',o)
821 \tkzLabelPoints(b,b',o)
822 \tkzLabelPoints[below left](a,a')
823 \tkzDrawArc(o,a)(a')
824 \tkzDrawArc(o,b)(b')
825 \end{tikzpicture}
826 \end{center}
827 \end{tkzexample}
828
829 \medskip
830 \texttt{Example usage for an object}
831
832 \vspace{1em}
833 \begin{tkzexample}[latex=7cm]
834 \directlua{
835 init_elements()
836 z.O = point(-1, -1)
837 z.A = point(2, 0)
838 z.B = point(5, 0)
839 L.AB = line(z.A, z.B)
840 T.ABC = L.AB:equilateral()
841 S.fig = L.AB:square()
842 _,_,z.E,z.F = S.fig:get()
843 S.new = z.O:rotation(math.pi / 3, S.fig)
844 _,_,z.Ep,z.Fp = S.new:get()
845 z.C = T.ABC.pc
846 T.ApBpCp = z.O:rotation(math.pi / 3, T.ABC)
847 z.Ap,z.Bp,
848 z.Cp = T.ApBpCp:get()}
849 \begin{center}
850 \begin{tikzpicture}[scale = .6]
851 \tkzGetNodes
852 \tkzDrawPolygons(A,B,C A',B',C' A,B,E,F)
853 \tkzDrawPolygons(A',B',E',F')
854 \tkzDrawPoints(A,B,C,A',B',C',O)
855 \tkzLabelPoints(A,B,C,A',B',C',O)
856 \begin{scope}
857 \tkzDrawArc[delta=0,->,dashed,red](O,A)(A')
858 \tkzDrawSegments[dashed,red](O,A O,A')
859 \end{scope}
860 \end{tikzpicture}
861 \end{center}
862 \end{tkzexample}
863
864
865
866
867 \subsubsection{Method \tkzMeth{point}{symmetry(obj)}}
868 \label{ssub:object_symmetry}
869
870 \medskip
871 \texttt{Description:}
872 This method performs a central symmetry (point reflection) of a geometric object with respect to the given point.
873
874 \medskip
875 \texttt{Arguments}
876
877 The argument \code{obj} can be a point, a line, a triangle, a circle, or any other supported geometric object. Each element of the object is reflected through the center point, producing a new object of the same type.
878
879 \medskip
880 \texttt{Example usage}
881
882 The following example shows how to apply central symmetry to an object (e.g., a triangle) using a reference point as the center.
883
884 \vspace{1em}
885
886 \begin{tkzexample}[latex=7cm]
887 \directlua{
888 init_elements()
889 z.a = point(0, -1)
890 z.b = point(2, 0)
891 L.ab = line(z.a, z.b)
892 C.ab = circle(z.a, z.b)
893 z.o = point(1, 1)
894 z.ap, z.bp = z.o:symmetry(C.ab):get()}
895 \begin{center}
896 \begin{tikzpicture}
897 \tkzGetNodes
898 \tkzDrawCircles(a,b a',b')
899 \tkzDrawLines(a,a' b,b')
900 \tkzDrawLines[red](a,b a',b')
901 \tkzDrawPoints(a,a',b,b',o)
902 \tkzLabelPoints(a,a',b,b',o)
903 \end{tikzpicture}
904 \end{center}
905 \end{tkzexample}
906
907 \subsubsection{Method \tkzMeth{point}{homothety(k, obj)}}
908 \label{ssub:method_point_homothety_k_obj}
909
910 \texttt{Purpose: } This method performs a homothety (dilation or contraction) of a geometric object with respect to the current point, which serves as the center of the transformation.
911
912 \medskip
913
914 \texttt{Arguments: }
915 \begin{itemize}
916 \item \code{k} — the homothety ratio (a real number),
917 \item \code{obj} — the object to be transformed, which can be:
918 \begin{enumerate}
919 \item a single point,
920 \item a list of points,
921 \item or a geometric object (line, triangle, circle, etc.).
922 \end{enumerate}
923 \end{itemize}
924
925
926 A positive ratio \code{k} produces a scaling centered at the point, while a negative ratio also reflects the object through the center.
927
928 \vspace{1em}
929
930 \begin{tkzexample}[latex=7cm]
931 \directlua{
932 init_elements()
933 z.A = point(0, 0)
934 z.B = point(1, 2)
935 z.E = point(-3, 2)
936 z.C, z.D = z.E:homothety(2, z.A, z.B)}
937 \begin{center}
938 \begin{tikzpicture}[scale = .5]
939 \tkzGetNodes
940 \tkzDrawPoints(A,B,C,E,D)
941 \tkzLabelPoints(A,B,C,E)
942 \tkzDrawCircles(A,B C,D)
943 \tkzDrawLines(E,C E,D)
944 \end{tikzpicture}
945 \end{center}
946 \end{tkzexample}
947
948 This method converts the point’s coordinates to a formatted string that can be displayed directly in the text.
949
950 \medskip
951
952 The number of decimal places is controlled by the global variable \code{tkz\_dc}, which is set to $2$ by default in the \code{init\_elements()} function. You can override it by assigning a new value before calling \code{print()}:
953
954 \begin{verbatim}
955 tkz_dc = 0
956 \end{verbatim}
957
958 \medskip
959
960 This is particularly useful when displaying coordinates, sums, products, or intermediate results in mathematical expressions.
961
962 \medskip
963 \texttt{Example usage:}
964
965 \begin{verbatim}
966 \directlua{
967 init_elements()
968 z.A = point(1, 2)
969 z.B = point(1, -1)
970 z.a = z.A + z.B
971 z.m = z.A * z.B
972 tkz_dc = 0}
973 The respective affixes of points $A$ and $B$ being
974 \tkzUseLua{z.A:print()} and \tkzUseLua{z.B:print()},
975 their sum is \tkzUseLua{z.a:print()} and
976 their product \tkzUseLua{z.m:print()}.
977 \end{verbatim}
978
979 \directlua{
980 init_elements()
981 z.A = point(1, 2)
982 z.B = point(1, -1)
983 z.a = z.A + z.B
984 z.m = z.A * z.B
985 tkz_dc = 0
986 }
987
988 The respective affixes of points $A$ and $B$ being
989 \tkzUseLua{z.A:print()} and \tkzUseLua{z.B:print()},
990 their sum is \tkzUseLua{z.a:print()} and
991 their product \tkzUseLua{z.m:print()}.
992
993 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
994 %%% Utilities %%%
995 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
996 \subsubsection{\tkzMeth{point}{identity}(pt)}
997 \label{ssub:identity}
998
999 \medskip
1000 \texttt{Syntax: } \verb|z.A:identity(z.B)|
1001
1002 \medskip
1003 \texttt{Purpose: }Check whether two points are identical within the numerical precision defined by \tkzVar{tkz}{tkz.epsilon}.
1004
1005 \medskip
1006 \texttt{Parameters: } The point to be compared with \textbf{self}.\\
1007
1008 \medskip
1009 \texttt{Return value: } True if the two points are numerically identical, false otherwise.\\
1010
1011
1012 \begin{tkzexample}[latex=.5\textwidth]
1013 \directlua{
1014 z.A = point(0, 0)
1015 z.B = point(0.0000000001, 0)
1016 tex.print(tostring(z.A:identity(z.B)))
1017 tex.print('\\\\')
1018 tex.print(tkz.epsilon)}
1019 %% true if tkz.epsilon > 1e-10
1020 \end{tkzexample}
1021
1022 \medskip
1023 \texttt{Remark: }
1024
1025 This method compares two points by computing the Euclidean distance between them
1026 and checking if it is smaller than the global tolerance \textbf{tkz.epsilon}.
1027 It is useful to test equality of points in floating-point computations.
1028
1029
1030
1031 \subsubsection{\tkzMeth{point}{print}()}
1032 \label{ssub:print}
1033
1034 \texttt{Usage:}
1035 \begin{verbatim}
1036 z.A:print()
1037 \end{verbatim}
1038
1039 \medskip
1040
1041 This method prints the coordinates of the point in a format suitable for \LaTeX{}.
1042
1043 It internally converts the point into a string using \texttt{tostring(self)} and sends the result to the \TeX{} output using \texttt{tex.print}. The output is therefore directly usable in the document.
1044
1045 \medskip
1046
1047 \texttt{Returns:} None.
1048
1049 \medskip
1050
1051 \texttt{Example:}
1052 \begin{verbatim}
1053 \directlua{
1054 z.A = point(1, 2)
1055 }
1056 Coordinates of A: \tkzUseLua{z.A:print()}
1057 \end{verbatim}
1058
1059 \medskip
1060
1061 \texttt{Remark:}
1062
1063 The format of the output depends on the \texttt{\_\_tostring} method of the \texttt{point} class. Typically, it produces coordinates of the form \texttt{(x,y)}, which can be directly used in TikZ paths.
1064 \endinput