Debian Codegraph @

texmf-dist/doc/metapost/mp-geom2d/mp-geom2d-doc-en.tex

raw
1
2 %! TEX root
3 \documentclass[a4paper,english]{article}
4 \input{mp-geom2d-doc-preamb.tex}
5
6 \begin{document}
7 %% === Page de garde ===================================================
8 \thispagestyle{empty}
9 \begin{tikzpicture}[remember picture, overlay]
10 \node[below right, shift={(-4pt,4pt)}] at (current page.north west) {%
11 \includegraphics{fond.pdf}%
12 };
13 \end{tikzpicture}%
14
15 \noindent
16 {\includegraphics{mp-geom2d}\\
17 \Large \MP{} package for plane geometry figures}\\[1cm]
18 \parbox{0.5\textwidth}{
19 \includegraphics[scale=0.86]{figure.pdf}
20 }\hfill
21 \parbox{0.5\textwidth}{\Large\raggedleft
22 \textbf{Contributors}\\
23 Maxime \textsc{Chupin}\\
24 Jean-Michel \textsc{Sarlat}
25 }
26 \vfill
27 \begin{center}
28 Version \gddVersion\ from \printdate{\gddDate} \\
29 \url{https://gitlab.gutenberg-asso.fr/mchupin/mp-geom2d}\\
30 \url{https://ctan.org/pkg/mp-geom2d}
31 \end{center}
32 %% == Page de garde ====================================================
33 \newpage
34
35 \tableofcontents
36
37 \section{Objectif}
38
39 The \mpgeomdd package was written with the goal of providing \MP{} macros that allow the creation of geometric figures by closely following an imperative description:
40 \begin{quote}\itshape
41 Let \(A\) be the point with coordinates (2,3).\\
42 Let \(B\) be the point with coordinates (4,5).\\
43 Draw the line \((A,B)\).\\
44 ....
45 \end{quote}
46 In this context, geometric objects are most often named (\(A\), \(B\), etc.) or designated by their nature and attributes (line \((A,B)\), etc.). To avoid having to go beyond this mode of description, particularly to avoid having to declare the \emph{type} of these objects, the choice was made to identify them by an \emph{index}\footnote{The \typeMP{numeric} type, which is the default type in \MP, does not require prior declaration.} in tables that specify their characteristics.
47
48 \begin{Note} As of today, the goal has not been fully achieved, and the development is far from complete; it is still necessary to use \MP{} commands or \emph{intermediate macros} to describe a figure. This will likely evolve over time as a satisfactory syntax is found...
49 \end{Note}
50
51
52 \section{Files}
53
54 The \mpgeomdd package is a set of tools for plane geometry with
55 \MP~\cite{ctan-metapost}. This
56 set is organized into several files:
57
58 \begin{enumerate}
59 \item \fichier{geom2d.mp} : this is the main file, which loads all the
60 others;
61 \item \fichier{geom2d-main.mp} : contains
62 the general structures and functions;
63 \item \fichier{geom2d-arc.mp} :
64 contains everything related to circle arcs;
65 \item \fichier{geom2d-c2d.mp} :
66 contains everything related to second-degree curves;
67 \item \fichier{geom2d-fct.mp} :
68 contains some usual mathematical functions;
69 \item \fichier{geom2d-lbl.mp} :
70 contains functions related to labels;
71 \item \fichier{geom2d-plt.mp} :
72 contains functions facilitating the representation of mathematical
73 functions;
74 \item \fichier{geom2d-rep.mp}
75 contains various tools for drawing figures in a coordinate system;
76 \item \fichier{geom2d-tra.mp}
77 contains functions for managing transparency (code
78 borrowed from Anthony Phan);
79 \item \fichier{geom2d-svgnames.mp} provides the 150 colors of the SVG specification.
80 \end{enumerate}
81
82 In the following sections, we will describe each of these
83 functions in more detail. Some functions rely on
84 the \fichier{graph.mp} extension, which is included in all good
85 \TeX distributions.
86
87 \section{General Operating Principle}
88
89 \mpgeomdd uses tables as the main structure. Each object is numbered via the counter \variableGDD{gddO}, its type\footnote{The types are specific to \mpgeomdd and will be described later.} is stored in the table \variableGDD{gddT[]} at the position \variableGDD{gddT[gddO]}. The properties of the objects are defined in, again, tables of type \typeMP{numeric} which are \variableGDD{gddA[]}, \variableGDD{gddB[]}, \dots, \variableGDD{gddF[]}.
90
91 For example, for a \typeGDD{point} (type \mpgeomdd), the first coordinate is found in \variableGDD{gddA[]} and the second in \variableGDD{gddB[]} (the other tables are not used for such an object).
92
93 There are three special tables: \variableGDD{gddP[]} which is of type \typeMP{path}, \variableGDD{gddPX[][]} which is its extended version, and \variableGDD{gddS[]} which is of type \typeMP{string}. We will see later what their utility is.
94
95 Of course, during a typical use of \mpgeomdd, calling all these tables is not common practice. The functions we will describe in the rest of this document allow you to avoid having to deal too precisely with this machinery.
96
97
98 \section{Drawing}
99
100 \mpgeomdd provides macros to draw objects. A command allows you to draw most of the \mpgeomdd objects (which are described in section~\ref{sec:types}), as well as some \MP types. The examples throughout the documentation will illustrate the drawing commands.
101
102 To understand how representations work with \mpgeomdd, we first need to describe the unit management mechanism.
103
104 \subsection{Unit}
105
106 \mpgeomdd defines a general unit with the global variable \lstinline+gddU+. This \typeMP{numeric} is by default \SI{1}{cm}.
107 \begin{colourband}
108 \macro|gddU|
109 \index{gddU@\lstinline+gddU+}
110 \end{colourband}
111
112 \subsection{In Place}
113
114 When using the drawing commands, \mpgeomdd uses the macro\label{gddEnPlace}
115 \begin{colourband}
116 \macro|gddInPlace|
117 \index{gddInPlace@\lstinline+gddInPlace+}
118 \end{colourband}
119 This macro specifies the necessary geometric transformations for placing the object, particularly the scaling factor relative to the \lstinline+gddU+ unit.
120
121 Internally, this macro is a \lstinline+scantoken+ of the global variable \variableGDD{gddW}\index{gddW@\lstinline+gddW+} (\typeMP{string}) which contains the transformations.
122
123 \subsection{Drawing Commands}\label{sec:trace}
124
125 The most common drawing macro is the \lstinline+trace+ macro.
126 \begin{colourband}
127 \macro|gddDraw(«object»)|
128 \begin{description}
129 \item[\meta{object}:]
130 \begin{itemize}
131 \item for the \MP{} side, a \typeMP{path}, a
132 \typeMP{picture} or a \typeMP{pair}, in which case \lstinline+gddDraw+ will be
133 equivalent to \lstinline+draw+;
134 \item for the \mpgeomdd side,
135 any of the 6 objects defined so far: \typeGDD{triangle},
136 \typeGDD{segment}, \typeGDD{droite}, \typeGDD{cercle}, \typeGDD{ellipse},
137 \typeGDD{parabole}, \typeGDD{hyperbole},
138 \typeGDD{polygone}, \typeGDD{chemin},
139 \typeGDD{courbe} or \typeGDD{vecteur} (for the latter, an arrow will be
140 added to the end of the vector).
141 \end{itemize}
142 \end{description}\index{gddDraw@\lstinline+gddDraw+}
143 \end{colourband}
144
145 When \lstinline+gddDraw+ is used on an \mpgeomdd object, the macro calls the \MP{} command \lstinline+draw+ with the placement mechanism described above.
146
147 \mpgeomdd provides a drawing with an arrow that no longer calls \lstinline+draw+
148 but \lstinline+drawarrow+.
149
150 \begin{colourband}
151 \macro|gddArrow(«object»)|
152 \begin{description}
153 \item[\meta{object}:]
154 \begin{itemize}
155 \item for the \MP{} side, a \typeMP{path}, a
156 \typeMP{picture}, or a \typeMP{pair}, in which case \lstinline+trace+ will be
157 equivalent to \lstinline+drawarrow+;
158 \item for the \mpgeomdd side,
159 any of the 6 objects defined so far: \typeGDD{triangle},
160 \typeGDD{segment}, \typeGDD{droite}, \typeGDD{cercle}, \typeGDD{ellipse},
161 \typeGDD{polygone}, \typeGDD{chemin},
162 \typeGDD{courbe}, or \typeGDD{vecteur} (for the latter, an arrow will be
163 added to the end of the vector).
164 \end{itemize}
165 \end{description}\index{gddArrow@\lstinline+gddArrow+}
166 \end{colourband}
167
168 You can also color an object using the following macro.
169 \begin{colourband}
170 \macro|gddFill(«object»)|
171 \begin{description}
172 \item[\meta{object}:] can be:
173 \begin{itemize}
174 \item for the \MP{} side, only a \typeMP{path} and in this case \lstinline+trace+ will be equivalent to \lstinline+fill+;
175 \item for the \mpgeomdd side,
176 any colorable object: \typeGDD{triangle},
177 \typeGDD{cercle}, \typeGDD{ellipse}, \typeGDD{polygone}, \typeGDD{chemin}, or
178 \typeGDD{courbe}.
179 \end{itemize}
180 \end{description}\index{gddFill@\lstinline+gddFill+}
181 \end{colourband}
182
183
184 The drawing commands of \mpgeomdd use the basic macros of \MP{}: \lstinline+draw+ and \lstinline+fill+. Thus, to specify the color, you can use the \lstinline+withcolor+ command or the \lstinline+drawoptions+ macro.
185
186
187 You can also color with transparency with the following command.
188 \begin{colourband}
189 \macro|gddAlphaFill(«object»,«color»,«transparency coefficient»)|
190 \begin{description}
191 \item[\meta{object}:] can be:
192 \begin{itemize}
193 \item for the \MP{} side, only a \typeMP{path} and in this case \lstinline+trace+ will be equivalent to \lstinline+fill+;
194 \item for the \mpgeomdd side,
195 any colorable object: \typeGDD{triangle},
196 \typeGDD{cercle}, \typeGDD{ellipse}, \typeGDD{polygone}, \typeGDD{chemin}, or
197 \typeGDD{courbe}.
198 \end{itemize}
199 \item[\meta{color}:] is a \typeMP{color}.
200 \item[\meta{transparency coefficient}:] is a \typeMP{numeric} between 0 and 1, 0 for opaque coloring and 1 for invisible coloring.
201 \end{description}\index{gddAlphaFill@\lstinline+gddAlphaFill+}
202 \end{colourband}
203
204 In fact, with a classic use, transparency is simulated using code borrowed from Anthony Phan:
205 http://www-math.univ-poitiers.fr/~phan/metalpha.html
206 .
207 If one uses \mpgeomdd with the \package{luamplib} package, the macro \lstinline+gddAlphaFill+ calls the \lstinline+withtransparency+ macro, which uses \textsc{pdf} transparency and is much lighter in computation. Thus, some code may be compilable with luatex but not with mpost.
208
209 You can also hatch a closed shape\footnote{The code is taken and adapted from the set of macros \texttt{geometriesyr16} by Christophe Poulain \url{https://melusine.eu.org/syracuse/poulecl/geometriesyr16/}.} with the following command:
210
211 \begin{colourband}
212 \macro|gddHatch(«object»,«angle»,«spacing»,«type»)|\return{\typeMP{image}}
213 \begin{description}
214 \item[\meta{object}:] can be:
215 \begin{itemize}
216 \item for the \MP{} side, only a \typeMP{path} and in this case \lstinline+trace+ will be equivalent to \lstinline+fill+;
217 \item for the \mpgeomdd side,
218 any colorable object: \typeGDD{triangle},
219 \typeGDD{cercle}, \typeGDD{ellipse}, \typeGDD{polygone}, \typeGDD{chemin}, or
220 \typeGDD{courbe}.
221 \end{itemize}
222 \item[\meta{angle}:] is the angle (\typeMP{numeric} in degrees) of the hatching lines.
223 \item[\meta{spacing}:] is the space (\typeMP{numeric}) between each hatching line (in the unit of \mpgeomdd, so no unit should be specified).
224 \item[\meta{type}:] is the type of line. If \meta{type}$=0$, the lines will be solid, if \meta{type}$=1$, the lines will be dashed evenly, if \meta{type}$=2$, the lines will be axis lines, if \meta{type}$=3$, the lines will be dashed with dots. Finally, if \meta{type}$=4$, you can define the line pattern with the \lstinline+HatchPattern+ command.
225 \end{description}\index{gddHatch@\lstinline+gddHatch+}
226 \end{colourband}
227
228 Note that the \lstinline+gddHatch+ macro returns an \typeMP{image}, so it should be
229 used in conjunction with the \lstinline+gddDraw+ macro.
230
231 To use the fourth type of line for hatching, you need to define its pattern using the following command:
232
233 \begin{colourband}
234 \macro|HatchPattern(«pattern»)|
235 \begin{description}
236 \item[\meta{pattern}:] is the pattern that you would typically provide to the
237 \lstinline+dashpattern+ command. We refer you to the \MP{} documentation. Note
238 that the dimensions provided to the \lstinline+on+ and \lstinline+off+ commands
239 will be scaled to the \lstinline+gddU+ unit of \mpgeomdd. Therefore, they should
240 be considered as expressed in the \mpgeomdd unit.
241 \end{description}\index{HatchPattern@\lstinline+HatchPattern+}
242 \end{colourband}
243
244 Below, we illustrate some commands for drawing, coloring, and hatching.
245
246 \begin{ExempleMP}
247 input geom2d;
248
249 beginfig(1);
250 gddU:=0.6cm;
251 A = Point(-1,1); B = Point(3,2);
252 C1= Circle(origine,2);
253 C2 = Circle(A,2); C3 = Circle(B,3);
254
255 gddFill C1 withcolor LightCyan;
256 gddAlphaFill(C2,DarkRed,0.2);
257 gddAlphaFill(C3,DarkBlue,0.2);
258
259 T1 = Triangle((-1,-2),(2,-2),(0.2,1));
260 gddDraw gddHatch(T1,45,0.2,0) withPen(0.6,DarkRed);
261 gddDraw T1;
262 pE1 = Point(-2,-3);
263 pE2 = Point(3,-4);
264 E = EllipseF(pE1,pE2,3.9);
265 HatchPattern(on0.2 off0.3);
266 gddDraw gddHatch(E,-20,0.1,4);
267 gddDraw E;
268 gddDrawPoint pE1; gddDrawPoint pE2;
269 endfig;
270 \end{ExempleMP}
271
272
273 The above macros call a lower-level macro that returns the \typeMP{path} to be drawn or colored for all \mpgeomdd objects.
274
275 \begin{colourband}
276 \macro|gddObjectDrawing(«object»)|\return{\typeMP{path}}
277 \begin{description}
278 \item[\meta{object}:]
279 \typeGDD{triangle}, \typeGDD{segment}, \typeGDD{vecteur},
280 \typeGDD{cercle}, \typeGDD{ellipse}, \typeGDD{parabole}, \typeGDD{hyperbole},\typeGDD{polygone}, \typeGDD{chemin}, or
281 \typeGDD{courbe}.
282 \end{description}\index{gddObjectDrawing@\lstinline+gddObjectDrawing+}
283 \end{colourband}
284
285 If the object is not closed, \mpgeomdd provides the following macro that adds a
286 \lstinline+--cycle+ to the end of the path:
287 \begin{colourband}
288 \macro|gddClose(«object»)|\return{\typeMP{path}}\indication{closed with \lstinline+--cycle+}
289 \begin{description}
290 \item[\meta{object}:]
291 \begin{itemize}
292 \item on the \MP side, \typeMP{path};
293 \item on the \mpgeomdd side, \typeGDD{triangle}, \typeGDD{segment}, \typeGDD{vecteur},
294 \typeGDD{cercle}, \typeGDD{chemin}, or
295 \typeGDD{courbe}.
296 \end{itemize}
297 \end{description}\index{gddClose@\lstinline+gddClose+}
298 \end{colourband}
299
300 You can specify the \emph{pen} used for drawings with the following command:
301
302 \begin{colourband}
303 \macro|withPen(«size»,«color»)|
304 \begin{description}
305 \item[\meta{size}:] scaling factor (\typeMP{numeric}) of the \typeMP{pen}
306 \lstinline+pencircle+ of \MP{};
307 \item[\meta{color}:] color \typeMP{color} to use.
308 \end{description}\index{withPen@\lstinline+withPen+}
309 \end{colourband}
310
311 This macro is a shortcut for the \emph{classic} \texttt{withpen
312 pencircle scaled ... withcolor ...}. You can, of course, always use the \MP{} commands for drawing.
313
314
315
316 You can represent objects of type \typeGDD{point}. For this, there is a command that draws a small colored circle at the location of the point. The command is as follows:
317
318 \begin{colourband}
319 \macro|gddDrawPoint(«point»)|
320 \begin{description}
321 \item[\meta{point}:] \typeGDD{point} or \typeMP{pair}
322 \end{description}\index{gddDrawPoint@\lstinline+gddDrawPoint+}
323 \end{colourband}
324
325 This macro uses three internal parameters of \mpgeomdd for the size, color, and type of mark used
326 (\lstinline+gddTaillePoint+\index{gddTaillePoint@\lstinline+gddTaillePoint+}, \lstinline+gddCouleurPoint+\index{gddCouleurPoint@\lstinline+gddCouleurPoint+}
327 and \lstinline+gddPointeType+ \index{gddPointeType@\lstinline+gddPointeType+}
328 ). These parameters can be modified with the following commands:
329 \begin{colourband}
330 \macro|SetPointSize(«n»)|
331 \begin{description}
332 \item[\meta{n}:] \typeMP{numeric}, default value 3.
333 \end{description}
334 \index{SetPointSize@\lstinline+SetPointSize+}
335 \end{colourband}
336
337 \begin{colourband}
338 \macro|SetPointColor(«c»)|
339 \begin{description}
340 \item[\meta{c}:] \typeMP{color}, default value \lstinline+white+.
341 \end{description}
342 \index{SetPointColor@\lstinline+SetPointColor+}
343 \end{colourband}
344
345 There are two other types of point marking: the cross and the disk. To choose
346 another type of marking (using the same \lstinline+gddDrawPoint+ command), you
347 can use the following macro:
348 \begin{colourband}
349 \macro|SetPointType(«s»)|
350 \begin{description}
351 \item[\meta{s}:] \typeMP{string}, can be \lstinline+"pointe"+
352 (default behavior with a black circle filled with another color,
353 white by default), \lstinline+"croix"+ (for a simple cross), or
354 \lstinline+"disque"+ (for a solid disk).
355 \end{description}
356 \index{SetPointType@\lstinline+SetPointType+}
357 \end{colourband}
358
359 It is often necessary to mark a list of points\footnote{Based on an idea by Alain Matthes.}. For this, the following command is available:
360
361 \begin{colourband}
362 \macro|gddDrawPoints(«pointA», «pointB», «pointC», etc.)|
363 \begin{description}
364 \item[\meta{pointA}, \meta{pointB}, etc.:] list of \typeGDD{point} or
365 \typeMP{pair} separated by commas.
366 \end{description}\index{gddDrawPoints@\lstinline+gddDrawPoints+}
367 \end{colourband}
368
369 \subsection{Clipping the drawings}
370
371 It is often necessary to restrict the drawings to a specific area of the plane $\R^2$.
372 For this, \mpgeomdd provides the command \lstinline+Window+:
373 \begin{colourband}
374 \macro|Window(«Xmin»,«Ymin»,«Xmax»,«Ymax»)|
375 \index{Window@\lstinline+Window+}
376 \end{colourband}
377 This function draws a rectangle with two opposite vertices at the points
378 \lstinline|(Xmin,Ymin)| and \lstinline|(Xmax,Ymax)| with the \MP{} color
379 \lstinline+background+ and clips the current picture around this frame (using the
380 \MP{} command \lstinline+clip currentpicture+).
381
382
383 You can also restrict drawings to the interior of a closed path derived from an \mpgeomdd object. To do this, use the following command:
384 \begin{colourband}
385 \macro|gddClip(«object»)|
386 \begin{description}
387 \item[\meta{object}:] any \mpgeomdd \enquote{closed} object.
388 \end{description}
389 \index{gddClip@\lstinline+gddClip+}
390 \end{colourband}
391
392 Internally, the macro \lstinline|Window| modifies the
393 \hologo{MetaPost}\lstinline+extra_endfig+ variable.
394 To clear this character string, you can use the following command:
395 \begin{colourband}
396 \macro|EndWindow|
397 \index{EndWindow@\lstinline+EndWindow+}
398 \end{colourband}
399
400 \section{Types}\label{sec:types}
401
402 \mpgeomdd provides several types of objects. The object type is stored in the \variableGDD{gddT[]} table, and the \variableGDD{gddA[]} to \variableGDD{gddF[]} tables, as well as the \variableGDD{gddX} table, contain the properties of the objects.
403
404 Here, we will describe each type of the \mpgeomdd extension, their respective properties, as well as methods directly associated with the object.
405
406 \subsection{The \typeGDD{point} type}
407
408 This type corresponds to a point in Euclidean space.
409
410 \subsubsection{Constructor}
411
412 To be clearer, here is the main function to create such an object:
413 %
414 \begin{mpcode}
415 vardef Point(expr a,b) =
416 gddT[incr gddO] = "point";
417 gddA[gddO] = a; gddB[gddO] = b; gddO
418 enddef;
419 \end{mpcode}
420
421 \begin{colourband}
422 \macro|Point(«x»,«y»)|\return{\typeGDD{point}}
423 \begin{description}
424 \item[\meta{x}:] \typeMP{numeric};
425 \item[\meta{y}:] \typeMP{numeric}.
426 \end{description}\index{Point@\lstinline+Point+}
427 \end{colourband}
428 \bigskip
429
430
431 This function returns the counter \variableGDD{gdd0} and creates an entry in the type table as \typeGDD{point} and the corresponding attributes (coordinates) \variableGDD{a} and \variableGDD{b} in the tables \variableGDD{gddA} and \variableGDD{gddB}.
432
433 With such a type of operation, most manipulations are done on \typeMP{numeric}s. Indeed, to declare a \typeGDD{point}, it is sufficient to write
434 \begin{mpcode}
435 A = Point(2,3);
436 \end{mpcode}
437 \variableGDD{A} then takes the current value of \variableGDD{gddO}. This is the identifier of the point.
438
439 A \typeGDD{point} can also be defined by its \emph{polar} coordinates with the following command.
440
441 \begin{colourband}
442 \macro|PolarPoint(«r»,«a»)|\return{\typeGDD{point}}
443 \begin{description}
444 \item[\meta{r}:] \typeMP{numeric}, modulus of the point;
445 \item[\meta{a}:] \typeMP{numeric}, angle with respect to the x-axis.
446 \end{description}\index{PolarPoint@\lstinline+PolarPoint+}
447 \end{colourband}
448 \bigskip
449
450 You can define a point in a coordinate system defined by an origin point and two vectors with the following function:
451 \begin{colourband}
452 \macro|PointInBasis(«x»,«y»,«o»,«i»,«j»)|\return{\typeGDD{point}}
453 \begin{description}
454 \item[\meta{x}:] \typeMP{numeric} ;
455 \item[\meta{y}:] \typeMP{numeric} ;
456 \item[\meta{o}:] \typeGDD{point} origin of the coordinate system ;
457 \item[\meta{i}:] \typeGDD{vecteur} (or \typeGDD{point}) defining the x-axis ;
458 \item[\meta{j}:] \typeGDD{vecteur} (or \typeGDD{point}) defining the y-axis.
459 \end{description}\index{PointInBasis@\lstinline+PointInBasis+}
460 \end{colourband}
461
462 \bigskip
463
464 The following code illustrates the use of this command (with \typeGDD{point}s instead of \typeGDD{vecteur}s, type described later).
465 \begin{mpcode}
466 O = Point(0,0);
467 I = Point(2,0);
468 J = PolarPoint(2,Pi/2);
469 A = PointInBasis(2,3,O,I,J);
470 \end{mpcode}
471
472 \subsubsection{Associated Macros}
473
474 You can retrieve the x-coordinate and y-coordinate of a point with the following commands:
475 \begin{colourband}
476 \macro|Xcoordinate(«a»)|\return{\typeMP{numeric}}
477 \begin{description}
478 \item[\meta{a}:] \typeGDD{point}, \typeGDD{vecteur} or \typeMP{pair}.
479 \end{description}\index{Xcoordinate@\lstinline+Xcoordinate+}
480 \end{colourband}
481
482 \begin{colourband}
483 \macro|Ycoordinate(«a»)|\return{\typeMP{numeric}}
484 \begin{description}
485 \item[\meta{a}:] \typeGDD{point}, \typeGDD{vecteur} or \typeMP{pair}.
486 \end{description}\index{Ycoordinate@\lstinline+Ycoordinate+}
487 \end{colourband}
488
489 You can add the x-coordinates, the y-coordinates, or, like vectors, points together with the following commands.
490 \begin{colourband}
491 \macro|XcoordinateSum(«a»,«b»)|\return{\typeMP{numeric}}
492 \begin{description}
493 \item[\meta{a}:] \typeGDD{point} or \typeMP{pair};
494 \item[\meta{b}:] \typeGDD{point} or \typeMP{pair}.
495 \end{description}\index{XcoordinateSum@\lstinline+XcoordinateSum+}
496 \end{colourband}
497 \begin{colourband}
498 \macro|YcoordinateSum(«a»,«b»)|\return{\typeMP{numeric}}
499 \begin{description}
500 \item[\meta{a}:] \typeGDD{point} or \typeMP{pair};
501 \item[\meta{b}:] \typeGDD{point} or \typeMP{pair}.
502 \end{description}\index{YcoordinateSum@\lstinline+YcoordinateSum+}
503 \end{colourband}
504 and
505 \begin{colourband}
506 \macro|PointSum(«a»,«b»)|\return{\typeGDD{point}}
507 \begin{description}
508 \item[\meta{a}:] \typeGDD{point} or \typeMP{pair};
509 \item[\meta{b}:] \typeGDD{point} or \typeMP{pair}.
510 \end{description}\index{PointSum@\lstinline+PointSum+}
511 \end{colourband}
512
513 You can also calculate the distance between two points using the following command:
514 \begin{colourband}
515 \macro|Length(«a»,«b»)|\return{\typeMP{numeric}}
516 \begin{description}
517 \item[\meta{a}:] \typeGDD{point} or \typeMP{pair};
518 \item[\meta{b}:] \typeGDD{point} or \typeMP{pair}.
519 \end{description}\index{Length@\lstinline+Length+}
520 \end{colourband}
521
522 You can calculate the midpoint between two points:
523 \begin{colourband}
524 \macro|MidPoint(«a»,«b»)|\return{\typeGDD{point}}
525 \begin{description}
526 \item[\meta{a}:] \typeGDD{point} or \typeMP{pair};
527 \item[\meta{b}:] \typeGDD{point} or \typeMP{pair}.
528 \end{description}\index{MidPoint@\lstinline+MidPoint+}
529 \end{colourband}
530
531 You can perform the rotation of a point around the origin $(0,0)$ with the following command:
532 \begin{colourband}
533 \macro|Rotation(«a»,«b»)|\return{\typeGDD{point}}
534 \begin{description}
535 \item[\meta{a}:] \typeGDD{point} or \typeMP{pair};
536 \item[\meta{b}:] \typeMP{numeric}, the angle of rotation in radians.
537 \end{description}\index{Rotation@\lstinline+Rotation+}
538 \end{colourband}
539
540 If you want to rotate a point around another point, you will use the following command:
541 \begin{colourband}
542 \macro|CenterRotation(«a»,«b»,«c»)|\return{\typeGDD{point}}
543 \begin{description}
544 \item[\meta{a}:] \typeGDD{point} or \typeMP{pair};
545 \item[\meta{b}:] \typeGDD{point} or \typeMP{pair}, center of rotation;
546 \item[\meta{c}:] \typeMP{numeric}, the angle of rotation in radians.
547 \end{description}\index{CenterRotation@\lstinline+CenterRotation+}
548 \end{colourband}
549
550 We can calculate the isobarycenter of a list of points (or \typeMP{pair} of \MP) with the following command.
551 \begin{colourband}
552 \macro|IsoBarycenter(«a»,«b»,«c», etc.)|\return{\typeGDD{point}}
553 \begin{description}
554 \item[\meta{a}:] \typeGDD{point} or \typeMP{pair};
555 \item[\meta{b}:] \typeGDD{point} or \typeMP{pair};
556 \item[] etc.
557 \end{description}\index{IsoBarycenter@\lstinline+IsoBarycenter+}
558 \end{colourband}
559
560 We can calculate the barycenter of a list of points associated with weights (but
561 here, it is not possible to use \MP{} \typeMP{pair}s).
562 \begin{colourband}
563 \macro|Barycenter((«A»,«a»),(«B»,«b»),(«C»,«c»), etc.)|\return{\typeGDD{point}}
564 \begin{description}
565 \item[\meta{A}:] \typeGDD{point} ;
566 \item[\meta{a}:] \typeMP{numeric}, weight associated with \meta{A} ;
567 \item[\meta{B}:] \typeGDD{point} ;
568 \item[\meta{b}:] \typeMP{numeric}, weight associated with \meta{B} ;
569 \item[] etc.
570 \end{description}\index{Barycenter@\lstinline+Barycenter+}
571 \end{colourband}
572
573
574 You can determine the bisector of an angular sector defined by three points. The function returns a \typeGDD{droite}.
575 \begin{colourband}
576 \macro|AngleBisector(«A»,«B»,«C»)|\return{\typeGDD{droite}}
577 \begin{description}
578 \item[\meta{A}:] \typeGDD{point} ;
579 \item[\meta{B}:] \typeGDD{point} ;
580 \item[\meta{C}:] \typeGDD{point}.
581 \end{description}\index{AngleBisector@\lstinline+AngleBisector+}
582 \end{colourband}
583
584 \begin{ExempleMP}
585 input geom2d;
586 beginfig(1);
587 A = Point(1,0);
588 B = Point(0,0);
589 C = Point(1,1);
590 D = AngleBisector(A,B,C);
591 gddDraw D;
592 gddMark.bot "A";
593 gddMark.bot "B";
594 gddMark.bot "C";
595 Window(-0.5,-0.5,2,2);
596 endfig;
597 \end{ExempleMP}
598
599
600 The \typeGDD{point} type is obviously related to the \MP{} \typeMP{pair} type.
601
602 \mpgeomdd provides macros that allow converting from \typeGDD{point} to
603 \typeMP{pair} and vice versa.
604 \begin{colourband}
605 \macro|PointTOPair(«a»,«b»)|\return{\typeMP{pair}}
606 \begin{description}
607 \item[\meta{a}:] \typeMP{numeric}, x-coordinate;
608 \item[\meta{b}:] \typeMP{numeric}, y-coordinate.
609 \end{description}\index{PointTOPair@\lstinline+PointTOPair+}
610 \end{colourband}
611
612 \begin{colourband}
613 \macro|PairTOPoint(«p»)|\return{\typeGDD{point}}
614 \begin{description}
615 \item[\meta{p}:] \typeMP{pair}.
616 \end{description}\index{PairTOPoint@\lstinline+PairTOPoint+}
617 \end{colourband}
618
619 These two commands are complemented by two others that ensure an element is of a given type:
620 \begin{colourband}
621 \macro|PairImp(«p»)|\return{\typeGDD{pair}}
622 \begin{description}
623 \item[\meta{p}:] \typeGDD{point} or \typeMP{pair}.
624 \end{description}\index{PairImp@\lstinline+PairImp+}
625 \end{colourband}
626
627
628 \begin{colourband}
629 \macro|PointImp(«p»)|\return{\typeGDD{point}}
630 \begin{description}
631 \item[\meta{p}:] \typeGDD{point} or \typeMP{pair}.
632 \end{description}\index{PointImp@\lstinline+PointImp+}
633 \end{colourband}
634
635 You can also retrieve a point along an \mpgeomdd object (described in the following sections). The following macro returns a \typeGDD{point} along the path (cyclic or not) of the object, parameterized between 0 and 1.
636
637 \begin{colourband}
638 \macro|PointOf(«o»,«t»)|\return{\typeGDD{point}}
639 \begin{description}
640 \item[\meta{o}:] any \mpgeomdd object (even a \typeGDD{point} for which it returns itself);
641 \item[\meta{t}:] \typeMP{numeric} between 0 and 1 (which parameterizes the object's path between 0 and 1).
642 \end{description}\index{PointOf@\lstinline+PointOf+}
643 \end{colourband}
644
645
646 \subsection{The \typeGDD{vecteur} type}
647
648 This type corresponds to vectors defined using two coordinates in Euclidean space.
649
650 \subsubsection{Constructors}
651
652 The constructor function for such an object is:
653 %
654 \begin{mpcode}
655 vardef Vector(expr a,b) =
656 save n; n = incr gddO;
657 gddT[n] = "vecteur"; gddA[n] = a; gddB[n] = b; n
658 enddef;
659 \end{mpcode}
660
661 \begin{colourband}
662 \macro|Vector(«a»,«b»)|\return{\typeGDD{vecteur}}
663 \begin{description}
664 \item[\meta{a}:] \typeMP{numeric} ;
665 \item[\meta{b}:] \typeMP{numeric}.
666 \end{description}\index{Vector@\lstinline+Vector+}
667 \end{colourband}
668 \bigskip
669
670 This function has the same structure as the corresponding one for the \typeGDD{point}: it returns the current value of \variableGDD{gddO} after incrementing it, then assigns the type \typeGDD{vecteur} to the corresponding entry in the \variableGDD{gddT} table.
671
672 A vector can also be defined from an \typeMP{pair} in \MP.
673 \begin{mpcode}
674 vardef VectorP(expr a) =
675 save n; n = incr gddO;
676 gddT[n] = "vecteur"; gddA[n] = xpart a; gddB[n] = ypart a; n
677 enddef;
678 \end{mpcode}
679
680 \begin{colourband}
681 \macro|VectorP(«a»)|\return{\typeGDD{vecteur}}
682 \begin{description}
683 \item[\meta{a}:] \typeMP{pair}.
684 \end{description}\index{VectorP@\lstinline+VectorP+}
685 \end{colourband}
686 \bigskip
687
688 A vector can then be defined as follows:
689 \begin{ExempleMP}
690 input geom2d;
691 beginfig(1);
692 AB = Vector(2,3);
693 pair a;
694 a := (3,2);
695 A = VectorP(a);
696 gddDraw AB;
697 gddDraw A;
698 endfig;
699 \end{ExempleMP}
700
701 \subsubsection{Associated Macros}
702
703 Since \mpgeomdd objects are \typeMP{numeric}s, the classic operations of the
704 vector space cannot be written with the simple characters \lstinline-+-,
705 \lstinline+-+, and \lstinline-*-.
706
707 \begin{colourband}
708 \macro|VectorSum(«a»,«b»)|\return{\typeGDD{vecteur}}
709 \begin{description}
710 \item[\meta{a}:] \typeGDD{vecteur} ;
711 \item[\meta{b}:] \typeGDD{vecteur}.
712 \end{description}\index{VectorSum@\lstinline+VectorSum+}
713 \end{colourband}
714 \bigskip
715
716
717 \begin{colourband}
718 \macro|VectorSubstract(«a»,«b»)|\return{\typeGDD{vecteur}}
719 \begin{description}
720 \item[\meta{a}:] \typeGDD{vecteur} ;
721 \item[\meta{b}:] \typeGDD{vecteur}.
722 \end{description}\index{VectorSubstract@\lstinline+VectorSubstract+}
723 \end{colourband}
724 \bigskip
725
726
727 \begin{colourband}
728 \macro|ScalarVector(«k»,«b»)|\return{\typeGDD{vecteur}}
729 \begin{description}
730 \item[\meta{k}:] \typeMP{numeric} ;
731 \item[\meta{b}:] \typeGDD{vecteur}.
732 \end{description}\index{ScalarVector@\lstinline+ScalarVector+}
733 \end{colourband}
734 \bigskip
735
736 We can then perform the classic operations on vectors.
737
738 \begin{ExempleMP}
739 input geom2d;
740 beginfig(1);
741 AB = Vector(2,3);
742 BC = Vector(1,0);
743 AC = VectorSum(AB,BC);
744 kAC = ScalarVector(3.0,AC);
745 gddDraw AB;
746 gddDraw BC;
747 gddDraw AC;
748 endfig;
749 \end{ExempleMP}
750
751 We can also calculate the dot product of two vectors with the following command.
752
753 \begin{colourband}
754 \macro|ScalarProduct(«a»,«b»)|\return{\typeMP{numeric}}
755 \begin{description}
756 \item[\meta{a}:] \typeGDD{vecteur} ;
757 \item[\meta{b}:] \typeGDD{vecteur}.
758 \end{description}\index{ScalarProduct@\lstinline+ScalarProduct+}
759 \end{colourband}
760 \bigskip
761
762 We can also calculate the Euclidean norm of a vector.
763 \begin{colourband}
764 \macro|Norm(«a»)|\return{\typeMP{numeric}}
765 \begin{description}
766 \item[\meta{a}:] \typeGDD{vecteur}.
767 \end{description}\index{Norm@\lstinline+Norm+}
768 \end{colourband}
769 \bigskip
770
771 The following command returns the angle, in radians, between $[0,\uppi]$ formed
772 between two vectors. If we denote $u$ and $v$ as the two vectors in $\R^2$, the angle
773 calculated
774 \[\theta = \arccos \left(\frac{u\cdot v}{\|u\|\|v\|}\right).\]
775
776 \begin{colourband}
777 \macro|AngleBetweenVectors(«a»,«b»)|\return{\typeMP{numeric} (dans $[0,\uppi]$)}
778 \begin{description}
779 \item[\meta{a}:] \typeGDD{vecteur} ;
780 \item[\meta{b}:] \typeGDD{vecteur}.
781 \end{description}\index{AngleBetweenVectors@\lstinline+AngleBetweenVectors+}
782 \end{colourband}
783 \bigskip
784
785
786 \subsection{The \typeGDD{segment} type}
787 Segments are defined by two points in $\R^2$.
788
789 \subsubsection{Constructor}
790 The constructor function for this object is:
791 \begin{mpcode}
792 vardef Segment (expr a,b) =
793 save n; n = incr gddO;
794 gddT[n] = "segment"; gddA[n] = PointImp(a); gddB[n] = PointImp(b); n
795 enddef;
796 \end{mpcode}
797
798 \begin{colourband}
799 \macro|Segment(«a»,«b»)|\return{\typeGDD{segment}}
800 \begin{description}
801 \item[\meta{a}:] \typeGDD{point} ;
802 \item[\meta{b}:] \typeGDD{point}.
803 \end{description}\index{Segment@\lstinline+Segment+}
804 \end{colourband}
805
806 \bigskip
807
808 A segment is then defined as follows:
809 \begin{ExempleMP}
810 input geom2d;
811 beginfig(1);
812 A = Point(2,3);
813 B = Point(4,5);
814 C = Point(2,1);
815 AB = Segment(A,B);
816 BC = Segment(B,C);
817 AC = Segment(A,C);
818 gddArrow AB;
819 gddArrow BC;
820 gddArrow AC;
821 endfig;
822 \end{ExempleMP}
823
824 \subsubsection{Associated Macros}
825
826 You can calculate the length of a segment with the following macro.
827 \begin{colourband}
828 \macro|SegmentLength(«a»)|\return{\typeMP{numeric}}
829 \begin{description}
830 \item[\meta{a}:] \typeGDD{segment}.
831 \end{description}\index{SegmentLength@\lstinline+SegmentLength+}
832 \end{colourband}
833
834 You can also convert a segment into a vector with the following macro, which calculates the difference in coordinates of the two points defining the segment.
835 \begin{colourband}
836 \macro|SegmentTOVector(«a»)|\return{\typeGDD{vecteur}}
837 \begin{description}
838 \item[\meta{a}:] \typeGDD{segment}.
839 \end{description}\index{SegmentTOVector@\lstinline+SegmentTOVector+}
840 \end{colourband}
841
842
843
844 \subsection{The \typeGDD{droite} type}
845 A line is simply defined by two points.
846
847 \subsubsection{Constructor}
848
849 The constructor function for this object is as follows:
850 \begin{mpcode}
851 vardef Line (expr a,b) =
852 save n; n = incr gddO;
853 gddT[n] = "droite"; gddA[n] = PointImp(a); gddB[n] = PointImp(b); n
854 enddef;
855 \end{mpcode}
856 \begin{colourband}
857 \macro|Line(«a»,«b»)|\return{\typeGDD{droite}}
858 \begin{description}
859 \item[\meta{a}:] \typeGDD{point} ;
860 \item[\meta{b}:] \typeGDD{point}.
861 \end{description}\index{Line@\lstinline+Line+}
862 \end{colourband}
863 \bigskip
864
865
866 When representing lines (see section~\ref{sec:trace}), the \emph{infinite} nature of the line is managed by the global variable \lstinline+gddExtensionDroite+
867 \index{gddExtensionDroite@\lstinline+gddExtensionDroite+}
868 which defaults to 10.
869
870 You can modify it with the following command:
871 \begin{colourband}
872 \macro|SetLineExtension(«d»)|
873 \begin{description}
874 \item[\meta{d}:] \typeMP{numeric} (default value 10).
875 \end{description}\index{SetLineExtension@\lstinline+SetLineExtension+}
876 \end{colourband}
877 \bigskip
878
879
880 \subsubsection{Associated Macros}
881
882 The following macro allows, in the form of a triplet, and thus a \typeMP{color}, to obtain the coefficients of a given line. For a line $(D)$, the macro gives the triplet $(u,v,w)\in\R^3$ such that $\forall (x,y)\in(D)$, $ux+vy+w=0$.
883
884 \begin{colourband}
885 \macro|LineEquation(«a»)|\return{\typeMP{color}}
886 \begin{description}
887 \item[\meta{a}:] \typeGDD{droite}.
888 \end{description}\index{LineEquation@\lstinline+LineEquation+}
889 \end{colourband}
890
891 You can calculate the projection of a point onto a line with the following command.
892
893 \begin{colourband}
894 \macro|PointOnLineProjection(«p»,«a»)|\return{\typeGDD{point}}
895 \begin{description}
896 \item[\meta{p}:] \typeGDD{point} ;
897 \item[\meta{a}:] \typeGDD{droite}.
898 \end{description}\index{PointOnLineProjection@\lstinline+PointOnLineProjection+}
899 \end{colourband}
900
901 You can obtain the relative distance of a point on a line with the following macro.
902 \begin{colourband}
903 \macro|PointLineRelativeDistance(«p»,«a»)|\return{\typeMP{numeric}}
904 \begin{description}
905 \item[\meta{p}:] \typeGDD{point} ;
906 \item[\meta{a}:] \typeGDD{droite}.
907 \end{description}\index{PointLineRelativeDistance@\lstinline+PointLineRelativeDistance+}
908 \end{colourband}
909 The calculation of the distance from a point to a line is done with the following macro.
910 \begin{colourband}
911 \macro|PointLineDistance(«p»,«a»)|\return{\typeMP{numeric}}
912 \begin{description}
913 \item[\meta{p}:] \typeGDD{point} ;
914 \item[\meta{a}:] \typeGDD{droite}.
915 \end{description}\index{PointLineDistance@\lstinline+PointLineDistance+}
916 \end{colourband}
917
918 The following macro allows obtaining the perpendicular line to a given line passing through a point.
919 \begin{colourband}
920 \macro|PerpendicularLine(«a»,«p»)|\return{\typeGDD{droite}}
921 \begin{description}
922 \item[\meta{a}:] \typeGDD{droite} ;
923 \item[\meta{p}:] \typeGDD{point}.
924 \end{description}\index{PerpendicularLine@\lstinline+PerpendicularLine+}
925 \end{colourband}
926
927 Similarly, the following macro allows obtaining the parallel line to another passing through a point.
928 \begin{colourband}
929 \macro|ParallelLine(«a»,«p»)|\return{\typeGDD{droite}}
930 \begin{description}
931 \item[\meta{a}:] \typeGDD{droite} ;
932 \item[\meta{p}:] \typeGDD{point}.
933 \end{description}\index{ParallelLine@\lstinline+ParallelLine+}
934 \end{colourband}
935
936 You can obtain the \typeGDD{point} of intersection of two lines with the
937 following macro.
938 \begin{colourband}
939 \macro|LinesIntersection(«a»,«b»)|\return{\typeGDD{point}}
940 \begin{description}
941 \item[\meta{a}:] \typeGDD{droite} ;
942 \item[\meta{b}:] \typeGDD{droite}.
943 \end{description}\index{LinesIntersection@\lstinline+LinesIntersection+}
944 \end{colourband}
945
946 The following macro allows you to plot a point on a line with a certain
947 length (signed), similar to a compass.
948
949 \begin{colourband}
950 \macro|ReportOnLine(«P»,«D»,«l»)|\return{\typeGDD{point}}
951 \begin{description}
952 \item[\meta{P}:] \typeGDD{point} ;
953 \item[\meta{D}:] \typeGDD{droite} ;
954 \item[\meta{l}:] \typeMP{numeric} (can be negative).
955 \end{description}\index{ReportOnLine@\lstinline+ReportOnLine+}
956 \end{colourband}
957
958 The direction of the plot relative to point \meta{P} depends on the definition
959 of
960 the line: for a line defined by two \typeGDD{point}s $A$ and $B$, the direction
961 of the plot will follow the vector $\overrightarrow{AB}$. To change direction,
962 simply multiply the distance parameter \meta{l} by $-1$.
963
964 Here is an example illustrating the use of some commands related to lines.
965
966 \begin{ExempleMP}
967 input geom2d;
968 beginfig(1);
969 A = Point(0,0);
970 B = Point(3,2);
971 AB = Line(A,B);
972 gddDraw AB;
973 gddDrawPoint A;
974 gddDrawPoint B;
975 C = Point(0,2);
976 DC = PerpendicularLine(AB,C);
977 gddDraw DC;
978 gddDrawPoint C;
979 D = PointOnLineProjection(C,AB);
980 gddDrawPoint D;
981 Window(-2,-2,4,4);
982 endfig;
983 \end{ExempleMP}
984
985
986
987 \subsection{The \typeGDD{cercle} type}
988 A circle could be defined by a point and a radius.
989
990 \subsubsection{Constructors}
991 The basic constructor function for this object is as follows:
992 \begin{mpcode}
993 vardef Circle (expr a,b) =
994 save n; n = incr gddO;
995 gddT[n] = "cercle"; gddA[n] = PointImp(a); gddB[n] = b; n
996 enddef;
997 \end{mpcode}
998 \begin{colourband}
999 \macro|Circle(«a»,«b»)|\return{\typeGDD{cercle}}
1000 \begin{description}
1001 \item[\meta{a}:] \typeGDD{point} or \typeMP{pair},
1002 center of the circle;
1003 \item[\meta{b}:] \typeMP{numeric}, radius of the circle.
1004 \end{description}\index{Circle@\lstinline+Circle+}
1005 \end{colourband}
1006 \bigskip
1007
1008 Two other functions allow defining circles. The \foncGDD{CircleCP} function defines the circle by a center and a point through which the circle passes.
1009 \begin{colourband}
1010 \macro|CircleCP(«a»,«b»)|\return{\typeGDD{cercle}}
1011 \begin{description}
1012 \item[\meta{a}:] \typeGDD{point} or \typeMP{pair},
1013 center of the circle;
1014 \item[\meta{b}:] \typeGDD{point},
1015 such that \meta{b}$-$\meta{a} is the radius.
1016 \end{description}\index{CircleCP@\lstinline+CircleCP+}
1017 \end{colourband}
1018 \bigskip
1019
1020 We can also define a circle by two points defining its diameter. The corresponding function is as follows:
1021 \begin{colourband}
1022 \macro|CircleD(«a»,«b»)|\return{\typeGDD{cercle}}
1023 \begin{description}
1024 \item[\meta{a}:] \typeGDD{point} or \typeMP{pair} ;
1025 \item[\meta{b}:] \typeGDD{point} or \typeMP{pair},
1026 such that $($\meta{a}$-$\meta{b}$)$ is the diameter of the circle.
1027 \end{description}\index{CircleD@\lstinline+CircleD+}
1028 \end{colourband}
1029 \bigskip
1030
1031 You can also define a circle as the circle passing through three points with
1032 the following macro.
1033
1034 \begin{colourband}
1035 \macro|CircleThreePoints(«a»,«b»,«c»)|\return{\typeGDD{cercle}}
1036 \begin{description}
1037 \item[\meta{a}:] \typeGDD{point} ou \typeMP{pair} ;
1038 \item[\meta{b}:] \typeGDD{point} ou \typeMP{pair} ;
1039 \item[\meta{c}:] \typeGDD{point} ou \typeMP{pair}.
1040 \end{description}\index{CircleThreePoints@\lstinline+CircleThreePoints+}
1041 \end{colourband}
1042 \bigskip
1043
1044
1045
1046 \begin{ExempleMP}
1047 input geom2d;
1048 beginfig(1);
1049 A = Point(3,1);
1050 B = Point(0,2);
1051 O = Point(0,0);
1052 r = 1.0;
1053 COr = Circle(O,r);
1054 COA = CircleCP(O,A);
1055 CAB = CircleD(A,B);
1056 COAB = CircleThreePoints(O,A,B);
1057 gddDraw COr;
1058 gddDraw COA;
1059 gddDraw CAB;
1060 gddDraw COAB;
1061 gddDrawPoint A; gddDrawPoint B; gddDrawPoint O;
1062 endfig;
1063 \end{ExempleMP}
1064
1065 \subsubsection{Associated Macros}
1066
1067 Many macros are associated with circles.
1068
1069 You can retrieve the radius of a circle with the following command.
1070
1071 \begin{colourband}
1072 \macro|Radius(«a»)|\return{\typeMP{numeric}}
1073 \begin{description}
1074 \item[\meta{a}:] \typeGDD{cercle}.
1075 \end{description}\index{Radius@\lstinline+Radius+}
1076 \end{colourband}
1077 \bigskip
1078
1079 You can obtain the center (\typeGDD{point}) of a circle with the following command:
1080 \begin{colourband}
1081 \macro|Center(«a»)|\return{\typeGDD{point}}
1082 \begin{description}
1083 \item[\meta{a}:] \typeGDD{cercle}, \typeGDD{ellipse} or \typeGDD{hyperbole}.
1084 \end{description}\index{Center@\lstinline+Center+}
1085 \end{colourband}
1086 \bigskip
1087
1088 We can compute the intersection between two circles using the following macro.
1089
1090 \begin{colourband}
1091 \macro|CirclesIntersection(«a»,«b»)|\return{\typeGDD{point}}
1092 \begin{description}
1093 \item[\meta{a}:] \typeGDD{cercle} ;
1094 \item[\meta{b}:] \typeGDD{cercle}.
1095 \end{description}\index{CirclesIntersectionCercle@\lstinline+CirclesIntersection+}
1096 \end{colourband}
1097 \bigskip
1098
1099 This macro will only give one intersection point. To obtain both intersection points, you will need to reverse the order of the circles in the call, as illustrated in the following example.
1100
1101 \begin{ExempleMP}
1102 input geom2d;
1103 beginfig(1);
1104 A = Point(0,0);
1105 CA = Circle(A,1);
1106 B = Point(1.5,0);
1107 CB = Circle(B,2);
1108 D1 = CirclesIntersection(CA,CB);
1109 D2 = CirclesIntersection(CB,CA);
1110 gddDraw CA; gddDraw CB;
1111 gddDrawPoint A; gddDrawPoint B; gddDrawPoint D1; gddDrawPoint D2;
1112 endfig;
1113 \end{ExempleMP}
1114
1115 If there is no intersection, the compilation will fail with the error
1116 \texttt{! Pythagorean subtraction X.XXXX+-+X.XXXX has been replaced by 0}. If
1117 the two circles are coincident, the error will be \texttt{! Division by zero.}.
1118
1119 \mpgeomdd also provides a macro to obtain the intersections between a
1120 line and a circle.
1121
1122 \begin{colourband}
1123 \macro|LineCircleIntersection(«d»,«c»,«n»)|\return{\typeGDD{point}}
1124 \begin{description}
1125 \item[\meta{d}:] \typeGDD{line} ;
1126 \item[\meta{c}:] \typeGDD{circle} ;
1127 \item[\meta{n}:] \typeMP{numeric} which is 1 or 2 depending on the intersection
1128 point desired (if there is only one intersection point, both values return the same point).
1129 \end{description}\index{LineCircleIntersection@\lstinline+LineCircleIntersection+}
1130 \end{colourband}
1131 \bigskip
1132
1133 If there is no intersection between the line and the circle, you will get
1134 the error \texttt{! Intersection between line and circle does not exist}.
1135
1136 The following example illustrates this macro.
1137 \begin{ExempleMP}
1138 input geom2d;
1139 beginfig(1);
1140 A = Point(2,2);
1141 C_A = Circle(A,1);
1142 B = Point(0,1);
1143 C = Point(4,2);
1144 BC = Line(B,C);
1145 E1 = LineCircleIntersection(BC,C_A,1);
1146 gddDraw C_A;
1147 gddDraw BC dashed evenly;
1148 gddDrawPoint A; gddDrawPoint B; gddDrawPoint C; gddDrawPoint E1;
1149 Window(-0.5,-0.5,5,4);
1150 endfig;
1151 \end{ExempleMP}
1152
1153
1154 You can obtain the common internal and external tangents to two circles with the following two macros. Again, since there are two tangents, to obtain both, you will reverse the order of the two circles in the call.
1155
1156 \begin{colourband}
1157 \macro|ExternalCommonTangent(«a»,«b»)|\return{\typeGDD{droite}}
1158 \begin{description}
1159 \item[\meta{a}:] \typeGDD{cercle} ;
1160 \item[\meta{b}:] \typeGDD{cercle}.
1161 \end{description}\index{ExternalCommonTangent@\lstinline+ExternalCommonTangent+}
1162 \end{colourband}
1163 \bigskip
1164
1165
1166 \begin{colourband}
1167 \macro|InternalCommonTangent(«a»,«b»)|\return{\typeGDD{droite}}
1168 \begin{description}
1169 \item[\meta{a}:] \typeGDD{cercle} ;
1170 \item[\meta{b}:] \typeGDD{cercle}.
1171 \end{description}\index{InternalCommonTangent@\lstinline+InternalCommonTangent+}
1172 \end{colourband}
1173 \bigskip
1174
1175
1176 The following example illustrates the use of these two macros.
1177 \begin{ExempleMP}[sidebyside=false]
1178 input geom2d;
1179 beginfig(1);
1180 C1 = Circle((-2,0),2);
1181 C2 = Circle((1.5,0),1);
1182 T1 = ExternalCommonTangent(C1,C2);
1183 T2 = ExternalCommonTangent(C2,C1);
1184 T3 = InternalCommonTangent(C1,C2);
1185 T4 = InternalCommonTangent(C2,C1);
1186 gddDraw C1; gddDraw C2;
1187 gddDraw T1; gddDraw T2;
1188 gddDraw T3; gddDraw T4;
1189
1190 Window(-5,-3,6,3);
1191 endfig;
1192 \end{ExempleMP}
1193
1194 The following macro calculates the radical axis (\typeGDD{droite}) of two circles\footnote{The construction method was largely inspired by T. Thurston's code in his document \emph{Drawing with \MP}~\cite{ctan-drawing-with-metapost}.}.
1195 \begin{colourband}
1196 \macro|RadicalAxis(«a»,«b»)|\return{\typeGDD{droite}}
1197 \begin{description}
1198 \item[\meta{a}:] \typeGDD{cercle} ;
1199 \item[\meta{b}:] \typeGDD{cercle}.
1200 \end{description}\index{RadicalAxis@\lstinline+RadicalAxes+}
1201 \end{colourband}
1202 \bigskip
1203
1204 The following macro calculates the radical center of three circles.
1205 \begin{colourband}
1206 \macro|RadicalCenter(«a»,«b»,«c»)|\return{\typeGDD{point}}
1207 \begin{description}
1208 \item[\meta{a}:] \typeGDD{cercle} ;
1209 \item[\meta{b}:] \typeGDD{cercle} ;
1210 \item[\meta{c}:] \typeGDD{cercle}.
1211 \end{description}\index{RadicalCenter@\lstinline+RadicalCenter+}
1212 \end{colourband}
1213 \bigskip
1214
1215 The following macro calculates the axis of similarity of three circles.
1216 \begin{colourband}
1217 \macro|AxisOfSimilitude(«a»,«b»,«c»)|\return{\typeGDD{droite}}
1218 \begin{description}
1219 \item[\meta{a}:] \typeGDD{cercle} ;
1220 \item[\meta{b}:] \typeGDD{cercle} ;
1221 \item[\meta{c}:] \typeGDD{cercle}.
1222 \end{description}\index{AxisOfSimilitude@\lstinline+AxisOfSimilitude+}
1223 \end{colourband}
1224 \bigskip
1225
1226 \subsection{The \typeGDD{ellipse} type}
1227 \subsubsection{Constructors}
1228
1229 Ellipses can be defined in several ways. First, they can be defined with their center, one of the points on the major axis (called the vertex), and one of the points on the minor axis (called the co-vertex). However, when creating an ellipse, many attributes are calculated.
1230
1231 The constructor code is as follows:
1232 \begin{mpcode}
1233 vardef Ellipse(expr C,A,B) =
1234 % C : centre
1235 % A : vertex
1236 % B : co-vertex
1237 save n,a,b,c,e,_tmp,slope,_D,_K,_h,_ff;
1238 pair _tmp;
1239 n = incr gddO;
1240 gddT[n] = "ellipse"; gddA[n] = PointImp(C); gddB[n] = PointImp(A);
1241 gddC[n] = PointImp(B);
1242 % calcul des deux foyers
1243 a = Longueur(C,A);
1244 b = Longueur(C,B);
1245 c = sqrt(a**2-b**2);
1246 e = c/a;
1247 _tmp = e*(Pt(A)-Pt(C));
1248 % les foyers
1249 gddD[n] = PairTOPoint(Pt(C)+_tmp);
1250 gddE[n] = PairTOPoint(Pt(C)-_tmp);
1251 gddX[n][1] = a;
1252 gddX[n][2] = b;
1253 gddX[n][3] = e;
1254 % angle du demi grand axe
1255 slope = angle(PairImp(A)-PairImp(C));
1256 gddX[n][4] = slope;
1257 % directrices
1258 _h = (a*a-c*c)/c;
1259 % prejection sur la directice
1260 _ff = Droite(gddE[n],gddD[n]);
1261 _K = ReportSurDroite(gddD[n],_ff,_h);
1262 _D = DroitePerpendiculaire(_ff,_K);
1263 gddX[n][5] := _D; % on stock la directrice
1264 gddX[n][6] := SymetrieCentrale(_D,gddA[n]); % on stock la deuxième directrice
1265 n
1266 enddef;
1267 \end{mpcode}
1268
1269 \begin{colourband}
1270 \macro|Ellipse(«c»,«a»,«b»)|\return{\typeGDD{ellipse}}
1271 \begin{description}
1272 \item[\meta{c}:] \typeGDD{point} or \typeMP{pair}, the center;
1273 \item[\meta{a}:] \typeGDD{point} or \typeMP{pair}, the vertex;
1274 \item[\meta{b}:] \typeGDD{point} or \typeMP{pair}, the co-vertex.
1275 \end{description}\index{Ellipse@\lstinline+Ellipse+}
1276 \end{colourband}
1277 \bigskip
1278
1279 This macro is used as shown in the following example.
1280 \begin{ExempleMP}
1281 input geom2d;
1282 beginfig(1);
1283 C = Point(0,0);
1284 A = Point(3,1);
1285 B = Rotation((1.5,0.5),Pi/2);
1286 E = Ellipse(C,A,B);
1287 gddDraw E;
1288 gddDrawPoint A; gddDrawPoint B; gddDrawPoint C;
1289 endfig;
1290 \end{ExempleMP}
1291
1292 An ellipse can be defined with its two foci and the semi-major axis using the following command:
1293 \begin{colourband}
1294 \macro|EllipseF(«A»,«B»,«a»)|\return{\typeGDD{ellipse}}
1295 \begin{description}
1296 \item[\meta{A}:] \typeGDD{point} or \typeMP{pair}, first focus;
1297 \item[\meta{B}:] \typeGDD{point} or \typeMP{pair}, second focus;
1298 \item[\meta{a}:] \typeGDD{numeric}, the semi-major axis.
1299 \end{description}\index{EllipseF@\lstinline+EllipseF+}
1300 \end{colourband}
1301 \bigskip
1302
1303
1304 This macro is used as shown in the following example.
1305 \begin{ExempleMP}
1306 input geom2d;
1307 beginfig(1);
1308 F1 = Point(3,1);
1309 F2 = Point(1.5,0.5);
1310 E = EllipseF(F1,F2,1.7);
1311 gddDraw E;
1312 gddDrawPoint F1; gddDrawPoint F2;
1313 endfig;
1314 \end{ExempleMP}
1315
1316 We can also define an ellipse from a focus, its directrix, and the eccentricity with the following command:
1317 \begin{colourband}
1318 \macro|EllipseFD(«F»,«D»,«e»)|\return{\typeGDD{ellipse}}
1319 \begin{description}
1320 \item[\meta{F}:] \typeGDD{point} or \typeMP{pair}, a focus;
1321 \item[\meta{D}:] \typeGDD{droite}, the associated directrix;
1322 \item[\meta{e}:] \typeGDD{numeric}, the eccentricity ($<1$).
1323 \end{description}\index{EllipseFD@\lstinline+EllipseFD+}
1324 \end{colourband}
1325 \bigskip
1326
1327 \subsubsection{Associated Macros}
1328
1329 You can obtain the center (\typeGDD{point}) of an ellipse with the following command:
1330 \begin{colourband}
1331 \macro|Center(«a»)|\return{\typeGDD{point}}
1332 \begin{description}
1333 \item[\meta{a}:] \typeGDD{cercle}, \typeGDD{ellipse} or \typeGDD{hyperbole}.
1334 \end{description}\index{Center@\lstinline+Center+}
1335 \end{colourband}
1336
1337 You can obtain the vertex and co-vertex with the following commands:
1338 \begin{colourband}
1339 \macro|Vertex(«a»)|\return{\typeGDD{point}}
1340 \begin{description}
1341 \item[\meta{a}:] \typeGDD{ellipse}.
1342 \end{description}\index{Vertex@\lstinline+Vertex+}
1343 \end{colourband}
1344 \bigskip
1345
1346 \begin{colourband}
1347 \macro|CoVertex(«a»)|\return{\typeGDD{point}}
1348 \begin{description}
1349 \item[\meta{a}:] \typeGDD{ellipse}.
1350 \end{description}\index{CoVertex@\lstinline+CoVertex+}
1351 \end{colourband}
1352 \bigskip
1353
1354 The following command allows obtaining the two foci based on the integer passed as an argument.
1355 \begin{colourband}
1356 \macro|Focus(«a»,«n»)|\return{\typeGDD{point}}
1357 \begin{description}
1358 \item[\meta{a}:] \typeGDD{ellipse} ;
1359 \item[\meta{n}:] \typeMP{numeric}, integer which is 1 or 2 to obtain each focus.
1360 \end{description}\index{Focus@\lstinline+Focus+}
1361 \end{colourband}
1362 \bigskip
1363
1364 You can obtain the semi-major axis and the semi-minor axis with the following commands.
1365 \begin{colourband}
1366 \macro|SemiMajorAxis(«a»)|\return{\typeMP{numeric}}
1367 \begin{description}
1368 \item[\meta{a}:] \typeGDD{ellipse}.
1369 \end{description}\index{SemiMajorAxis@\lstinline+SemiMajorAxis+}
1370 \end{colourband}
1371 \bigskip
1372
1373
1374 \begin{colourband}
1375 \macro|SemiMinorAxis(«a»)|\return{\typeMP{numeric}}
1376 \begin{description}
1377 \item[\meta{a}:] \typeGDD{ellipse}.
1378 \end{description}\index{SemiMinorAxis@\lstinline+SemiMinorAxis+}
1379 \end{colourband}
1380 \bigskip
1381
1382 We can get the excentricity, denoted by $e$, with the following command.
1383
1384 \begin{colourband}
1385 \macro|Excentricity(«a»)|\return{\typeMP{numeric}}
1386 \begin{description}
1387 \item[\meta{a}:] \typeGDD{ellipse}, \typeGDD{parabole} ou \typeGDD{hyperbole}.
1388 \end{description}\index{Excentricity@\lstinline+Excentricity+}
1389 \end{colourband}
1390 \bigskip
1391
1392 To obtain the inclination (slope of the line passing through the foci of the ellipse), use the following command.
1393
1394 \begin{colourband}
1395 \macro|Slope(«a»)|\return{\typeMP{numeric}}
1396 \begin{description}
1397 \item[\meta{a}:] \typeGDD{ellipse}, \typeGDD{parabole}, or \typeGDD{hyperbole}.
1398 \end{description}\index{Slope@\lstinline+Slope+}
1399 \end{colourband}
1400 \bigskip
1401
1402 You can obtain the directrices of the ellipse with the following command:
1403
1404 \begin{colourband}
1405 \macro|Directrix(«a»,«n»)|\return{\typeGDD{droite}}
1406 \begin{description}
1407 \item[\meta{a}:] \typeGDD{ellipse}, \typeGDD{parabole}, or \typeGDD{hyperbole}
1408 ;
1409 \item[\meta{n}:] 1 or 2 (\typeMP{numeric}), to choose one of the two
1410 directrices.
1411 \end{description}\index{Directrix@\lstinline+Directrix+}
1412 \end{colourband}
1413 \bigskip
1414 To obtain the tangent (\typeGDD{droite}) at a point on the ellipse, use the following command.
1415
1416 \begin{colourband}
1417 \macro|EllipseTangent(«e»,«p»)|\return{\typeGDD{droite}}
1418 \begin{description}
1419 \item[\meta{e}:] \typeGDD{ellipse};
1420 \item[\meta{p}:] \typeGDD{point} or \typeMP{pair}.
1421 \end{description}\index{EllipseTangent@\lstinline+EllipseTangent+}
1422 \end{colourband}
1423 \bigskip
1424
1425 \begin{ExempleMP}
1426 input geom2d;
1427 beginfig(1);
1428 F1 = Point(3,1);
1429 F2 = Point(1.5,0.5);
1430 E = EllipseF(F1,F2,2.4);
1431 gddDrawPoints F1, F2;
1432 gddDraw E;
1433 M' = PointOf(E,0.5);
1434 D = EllipseTangent(E,M');
1435 gddDraw D;
1436 gddDrawPoints M', Foyer(E,1), Foyer(E,2);
1437 Window(-0.2,-2.5,6,4);
1438 endfig;
1439 \end{ExempleMP}
1440
1441
1442 To obtain the tangents (\typeGDD{droite}) passing through a point outside the
1443 ellipse, use the following command. If the chosen point is not outside the
1444 ellipse, a compilation error will occur.
1445
1446 \begin{colourband}
1447 \macro|ExternalEllipseTangent(«e»,«p»,«n»)|\return{\typeGDD{droite}}
1448 \begin{description}
1449 \item[\meta{e}:] \typeGDD{ellipse} ;
1450 \item[\meta{p}:] \typeGDD{point} or \typeGDD{pair} ;
1451 \item[\meta{n}:] \typeMP{numeric} which is 1 or 2 to choose the tangent among
1452 the two possible ones.
1453 \end{description}\index{ExternalEllipseTangent@\lstinline+ExternalEllipseTangent+}
1454 \end{colourband}
1455 \bigskip
1456
1457 The points of tangency can be accessed as the second point in the definition of
1458 the \typeGDD{droite} using the \variableGDD{gddB[]} table.
1459
1460 \begin{ExempleMP}
1461 input geom2d;
1462 beginfig(1);
1463 F1 = Point(3,1);
1464 F2 = Point(1.5,0.5);
1465 E = EllipseF(F1,F2,2.4);
1466 gddDrawPoint F1; gddDrawPoint F2;
1467 gddDraw E;
1468 M = Point(4,3);
1469 D1 = ExternalEllipseTangent(E,M,1);
1470 gddDraw D1;
1471 gddDrawPoint gddB[D1];
1472 D2 = ExternalEllipseTangent(E,M,2);
1473 gddDraw D2;
1474 gddDrawPoint gddB[D2];
1475 gddDrawPoint M;
1476 gddDrawPoint Focus(E,1);
1477 gddDrawPoint Focus(E,2);
1478 Window(-0.2,-2.5,6,4);
1479 endfig;
1480 \end{ExempleMP}
1481
1482 \subsection{The \typeGDD{parabole} type}
1483
1484 The basic constructor for the parabola defines this object using the focus and
1485 the directrix.
1486
1487 The constructor code is as follows:
1488 \begin{mpcode}
1489 vardef ParaboleFD(expr F,D) =
1490 % F : foyer (point)
1491 % D : directrice (droite)
1492 save u, v, w, d, i, n,_tmp,slope;
1493 pair _tmp;
1494 n = incr gddO;
1495 (u,v,w) = EquationDroite(D);
1496 % ordonnée relative
1497 d := u * gddA[F] + v * gddB[F] + w;
1498 gddT[n] := "parabole";
1499 gddX[n][1] := D; % on stocke la directrice
1500 gddX[n][2] := D; % on stocke la directrice (compatibilité avec hyperbole)
1501 % sommet
1502 _tmp := (((-d/2)*(u,v)) shifted PairImp(F));
1503 gddB[n] = PointImp(_tmp);
1504 gddC[n] = PointImp(_tmp);
1505 % le foyer (doublé pour compatibilité)
1506 gddD[n] := F;
1507 gddE[n] := F;
1508 gddX[n][3] := 1.0; % excentricité
1509 % angle du demi-grand axe
1510 slope = angle(PairImp(gddA[D])-PairImp(gddB[D]))+90;
1511 gddX[n][4] = slope;
1512 i := -gddC2Dparam-1;
1513 gddP[n] := (
1514 ((i*(v,-u)+((i*i-d*d)/(2d))*(u,v))
1515 for i:= -gddC2Dparam upto gddC2Dparam:
1516 ..(i*(v,-u)+((i*i-d*d)/(2d))*(u,v))
1517 endfor)) shifted PairImp(F);
1518 n
1519 enddef;
1520 \end{mpcode}
1521 \begin{colourband}
1522 \macro|ParabolaFD(«f»,«d»)|\return{\typeGDD{path}}
1523 \begin{description}
1524 \item[\meta{f}:] is the focus (\typeGDD{point}) of the parabola;
1525 \item[\meta{d}:] is the directrix (\typeGDD{droite}) of the parabola.
1526 \end{description}
1527 \index{ParabolaFD@\lstinline+ParabolaFD+}
1528 \end{colourband}
1529
1530 When representing a parabola, the \emph{infinite} nature is managed by the
1531 global variable \lstinline+gddC2Dparam+, which defaults to 15.
1532
1533
1534 To modify it, use the following command:
1535 \begin{colourband}
1536 \macro|SetConicCoef(«n»)|
1537 \begin{description}
1538 \item[\meta{n}:] \typeMP{numeric}, parameter for drawing hyperbolas and
1539 parabolas (default value 15).
1540 \end{description}
1541 \index{SetConicCoef@\lstinline+SetConicCoef+}
1542 \end{colourband}
1543
1544 \subsubsection{Associated Functions}
1545
1546 The eccentricity, often denoted as $e$, can be obtained using the following command:
1547
1548 \begin{colourband}
1549 \macro|Excentricity(«a»)|\return{\typeMP{numeric}}
1550 \begin{description}
1551 \item[\meta{a}:] \typeGDD{ellipse}, \typeGDD{parabole}, or \typeGDD{hyperbole}.
1552 \end{description}\index{Excentricity@\lstinline+Excentricity+}
1553 \end{colourband}
1554 \bigskip
1555
1556 To obtain the slope (the slope of the axis of symmetry of the parabola), use the following command:
1557
1558 \begin{colourband}
1559 \macro|Slope(«a»)|\return{\typeMP{numeric}}
1560 \begin{description}
1561 \item[\meta{a}:] \typeGDD{ellipse}, \typeGDD{parabole}, or \typeGDD{hyperbole}.
1562 \end{description}\index{Slope@\lstinline+Slope+}
1563 \end{colourband}
1564 \bigskip
1565 The vertex of the parabola can be obtained using the following command:
1566
1567 \begin{colourband}
1568 \macro|ParabolaVertex(«a»,«n»)|\return{\typeGDD{point}}
1569 \begin{description}
1570 \item[\meta{a}:] \typeGDD{parabole} or \typeGDD{hyperbole};
1571 \item[\meta{n}:] 1 or 2 (\typeMP{numeric}), an argument useful for the
1572 hyperbola which has two vertices. Here, the value of \meta{n} does not
1573 matter, as the unique vertex will be returned.
1574 \end{description}\index{ParabolaVertex@\lstinline+ParabolaVertex+}
1575 \end{colourband}
1576 \bigskip
1577 The parabola's directrix can be obtained using the following command:
1578
1579 \begin{colourband}
1580 \macro|Directrix(«a»,«n»)|\return{\typeGDD{droite}}
1581 \begin{description}
1582 \item[\meta{a}:] \typeGDD{ellipse}, \typeGDD{parabole}, or \typeGDD{hyperbole};
1583 \item[\meta{n}:] 1 or 2 (\typeMP{numeric}), an argument useful for the
1584 hyperbola which has two directrices. Here, the value of \meta{n} does not
1585 matter,
1586 as the unique directrix will be returned.
1587 \end{description}\index{Directrix@\lstinline+Directrix+}
1588 \end{colourband}
1589 \bigskip
1590
1591 \begin{ExempleMP}
1592 input geom2d;
1593 beginfig(1);
1594 A = Point(0,0);
1595 B = Point(3,2);
1596 AB = Line(A,B);
1597 F = Point(-1,1);
1598 Para = ParabolaFD(F,AB);
1599 gddDraw AB;
1600 gddDraw Para;
1601 gddDrawPoint ParabolaVertex(Para,1);
1602 gddDrawPoint F;
1603 Window(-4,-5,2,5);
1604 endfig;
1605 \end{ExempleMP}
1606
1607
1608 \subsection{The \typeGDD{hyperbole} type}
1609
1610 The basic constructor for the hyperbola defines this object using the focus and
1611 the directrix.
1612
1613 The constructor code is as follows:
1614 \begin{mpcode}
1615 vardef HyperboleFD(expr F,D,e) =
1616 % F : foyer (point)
1617 % D : directrice (droite)
1618 % e : exentricité (numeric)
1619 % pm : +1 ou -1 pour les deux branches
1620 save u, v, w, d, i, n,_tmp,slope,aa,bb;
1621 pair _tmp;
1622 n = incr gddO;
1623
1624 (u,v,w) = EquationDroite(D);
1625 d := u * gddA[F] + v * gddB[F] + w;
1626 gddT[n] := "hyperbole";
1627
1628 % sommets
1629 _tmp := -(d+1*sqrt(e*e*d*d))/(e*e-1)*(u,v)shifted (ProduitScalaire(F,Vecteur(v,-u))*(v,-u));
1630 gddB[n] := PointImp(_tmp);
1631 _tmp := -(d-1*sqrt(e*e*d*d))/(e*e-1)*(u,v)shifted
1632 (ProduitScalaire(F,Vecteur(v,-u))*(v,-u));
1633 gddC[n] := PointImp(_tmp);
1634 % centre comme milieu des deux sommets
1635 gddA[n] = Milieu(gddB[n],gddC[n]);
1636 % le foyer (doublé pour compatibilité)
1637 gddD[n] := F;
1638 gddE[n] := RotationCentre(F, gddA[n], Pi);
1639 gddX[n][3] := e; % excentricité
1640 % directrices
1641 gddX[n][1] := D; % on stocke la directrice
1642 gddX[n][2] := Droite(RotationCentre(gddA[D], gddA[n], Pi),RotationCentre(gddB[D], gddA[n], Pi));
1643 % angle de l'axe
1644 slope = angle(PairImp(gddA[D])-PairImp(gddB[D]))+90;
1645 gddX[n][4] = slope;
1646 % cercle principale
1647 gddX[n][5] = CercleD(gddB[n],gddC[n]);
1648 % asymptotes
1649 aa = IntersectionDroiteCercle(D,gddX[n][5],1);
1650 bb = IntersectionDroiteCercle(D,gddX[n][5],2);
1651 gddX[n][6] = Droite(gddA[n],aa);
1652 gddX[n][7] = Droite(gddA[n],bb);
1653 % tracés des moitiés
1654 i := -gddC2Dparam-1;
1655 gddPX[n][1] := (
1656 (
1657 (i*(v,-u)-(d+sqrt(e*e*d*d+i*i*(e*e-1)))/(e*e-1)*(u,v))
1658 for i:= -gddC2Dparam upto gddC2Dparam:
1659 ..(i*(v,-u)-(d+sqrt(e*e*d*d+i*i*(e*e-1)))/(e*e-1)*(u,v))
1660 endfor
1661 ) shifted (ProduitScalaire(F,Vecteur(v,-u))*(v,-u))
1662 );
1663 gddPX[n][2] := (
1664 (
1665 (i*(v,-u)-(d-sqrt(e*e*d*d+i*i*(e*e-1)))/(e*e-1)*(u,v))
1666 for i:= -gddC2Dparam upto gddC2Dparam:
1667 ..(i*(v,-u)-(d-sqrt(e*e*d*d+i*i*(e*e-1)))/(e*e-1)*(u,v))
1668 endfor
1669 ) shifted (ProduitScalaire(F,Vecteur(v,-u))*(v,-u))
1670 );
1671 n
1672 enddef;
1673 \end{mpcode}
1674
1675 In this constructor, we can see the use of the extended \typeMP{path} table \variableGDD{gddPX[][]}, which allows associating multiple \typeMP{path}s with a single object.
1676 \begin{colourband}
1677 \macro|HyperbolaFD(«f»,«d»,«e»)|\return{\typeGDD{hyperbole}}
1678 \begin{description}
1679 \item[\meta{f}:] is the focus (\typeGDD{point}) of the hyperbola;
1680 \item[\meta{d}:] is the directrix (\typeGDD{droite}) of the hyperbola;
1681 \item[\meta{e}:] is the eccentricity of the hyperbola.
1682 \end{description}
1683 \index{HyperbolaFD@\lstinline+HyperbolaFD+}
1684 \end{colourband}
1685
1686 You can also define a hyperbola using its two foci and the distance between
1687 a vertex and the center of the hyperbola (bifocal definition).
1688
1689 \begin{colourband}
1690 \macro|HyperbolaF(«f1»,«f2»,«a»)|\return{\typeGDD{hyperbole}}
1691 \begin{description}
1692 \item[\meta{f1}:] is one focus (\typeGDD{point}) of the hyperbola;
1693 \item[\meta{f2}:] is the second focus (\typeGDD{point}) of the hyperbola;
1694 \item[\meta{a}:] is half the distance between the two vertices of the hyperbola.
1695 \end{description}
1696 \index{HyperbolaF@\lstinline+HyperbolaF+}
1697 \end{colourband}
1698
1699 \subsubsection{Associated Functions}
1700
1701 You can obtain the center (\typeGDD{point}) of a hyperbola with the following command:
1702 \begin{colourband}
1703 \macro|Center(«a»)|\return{\typeGDD{point}}
1704 \begin{description}
1705 \item[\meta{a}:] \typeGDD{cercle}, \typeGDD{ellipse}, or \typeGDD{hyperbole}.
1706 \end{description}\index{Center@\lstinline+Center+}
1707 \end{colourband}
1708
1709
1710 The eccentricity, often denoted as $e$, can be obtained using the following command.
1711
1712 \begin{colourband}
1713 \macro|Excentricity(«a»)|\return{\typeMP{numeric}}
1714 \begin{description}
1715 \item[\meta{a}:] \typeGDD{ellipse}, \typeGDD{parabole}, or \typeGDD{hyperbole}.
1716 \end{description}\index{Excentricity@\lstinline+Excentricity+}
1717 \end{colourband}
1718 \bigskip
1719
1720
1721 To obtain the inclination (slope of the line passing through the foci of the hyperbola), use the following command.
1722
1723 \begin{colourband}
1724 \macro|Slope(«a»)|\return{\typeMP{numeric}}
1725 \begin{description}
1726 \item[\meta{a}:] \typeGDD{ellipse}, \typeGDD{parabole}, or \typeGDD{hyperbole}.
1727 \end{description}\index{Slope@\lstinline+Slope+}
1728 \end{colourband}
1729 \bigskip
1730
1731
1732 The vertices of the hyperbola can be obtained using the following command:
1733
1734 \begin{colourband}
1735 \macro|HyperbolaVertex(«a»,«n»)|\return{\typeGDD{point}}
1736 \begin{description}
1737 \item[\meta{a}:] \typeGDD{parabola} or \typeGDD{hyperbola};
1738 \item[\meta{n}:] 1 or 2 (\typeMP{numeric}), to choose one of the two vertices.
1739 \end{description}\index{HyperbolaVertex@\lstinline+HyperbolaVertex+}
1740 \end{colourband}
1741 \bigskip
1742
1743 You can obtain the directrices of the hyperbola with the following command:
1744
1745 \begin{colourband}
1746 \macro|Directrix(«a»,«n»)|\return{\typeGDD{droite}}
1747 \begin{description}
1748 \item[\meta{a}:] \typeGDD{ellipse}, \typeGDD{parabole}, or \typeGDD{hyperbole}
1749 ;
1750 \item[\meta{n}:] 1 or 2 (\typeMP{numeric}), to choose one of the two
1751 directrices.
1752 \end{description}\index{Directrix@\lstinline+Directrix+}
1753 \end{colourband}
1754 \bigskip
1755
1756 To obtain the \emph{principal circle} of the hyperbola, you can use the
1757 following command:
1758
1759 \begin{colourband}
1760 \macro|PrincipalCircle(«h»)|\return{\typeGDD{cercle}}
1761 \begin{description}
1762 \item[\meta{h}:] \typeGDD{hyperbole}.
1763 \end{description}\index{PrincipalCircle@\lstinline+PrincipalCircle+}
1764 \end{colourband}
1765 \bigskip
1766
1767 You can also obtain the two asymptotes of the hyperbola with the following command:
1768
1769 \begin{colourband}
1770 \macro|HyperbolaAsymptote(«h»,«n»)|\return{\typeGDD{droite}}
1771 \begin{description}
1772 \item[\meta{h}:] \typeGDD{hyperbole} ;
1773 \item[\meta{n}:] 1 or 2 (\typeMP{numeric}), to choose one of the two
1774 asymptotes.
1775 \end{description}\index{HyperbolaAsymptote@\lstinline+HyperbolaAsymptote+}
1776 \end{colourband}
1777 \bigskip
1778
1779 Because a hyperbola consists of two disjoint parts, you cannot directly use the
1780 \lstinline+gddDraw+ command on the object as with other \mpgeomdd objects. Instead,
1781 you must use the following command to obtain the \typeMP{path} associated with
1782 one of the two parts of the hyperbola.
1783
1784 \begin{colourband}
1785 \macro|SemiHyperbola(«h»,«n»)|\return{\typeGDD{path}}
1786 \begin{description}
1787 \item[\meta{h}:] \typeGDD{hyperbole};
1788 \item[\meta{n}:] 1 or 2 (\typeMP{numeric}), to choose one of the two parts.
1789 \end{description}\index{SemiHyperbola@\lstinline+SemiHyperbola+}
1790 \end{colourband}
1791 \bigskip
1792
1793
1794 \begin{ExempleMP}
1795 input geom2d;
1796 beginfig(1);
1797 A = Point(0,0);
1798 B = Point(3,2);
1799 AB = Line(A,B);
1800 F = Point(-1,1);
1801 Hyper = HyperbolaFD(F,AB,1.5);
1802 gddDraw AB;
1803 gddDraw SemiHyperbola(Hyper,1);
1804 gddDraw SemiHyperbola(Hyper,2);
1805 gddDraw Directrix(Hyper,2);
1806 gddDraw PrincipalCircle(Hyper) dashed evenly;
1807 gddDraw HyperbolaAsymptote(Hyper,1) dashed evenly;
1808 gddDraw HyperbolaAsymptote(Hyper,2) dashed evenly;
1809 gddDrawPoint Center(Hyper);
1810 gddDrawPoint Focus(Hyper,1);
1811 gddDrawPoint Focus(Hyper,2);
1812 gddDrawPoint HyperbolaVertex(Hyper,1);
1813 gddDrawPoint HyperbolaVertex(Hyper,2);
1814 Window(-3,-5,3,5);
1815 endfig;
1816 \end{ExempleMP}
1817
1818 \subsection{The \typeGDD{triangle} type}
1819
1820 Triangles are defined by three points in $\R^2$.
1821
1822 \subsubsection{Constructor}
1823 The constructor function for this object is as follows:
1824 \begin{mpcode}
1825 vardef Triangle (expr a,b,c) =
1826 save n; n = incr gddO; gddT[n] = "triangle";
1827 gddA[n] = PointImp(a); gddB[n] = PointImp(b); gddC[n] = PointImp(c); n
1828 enddef;
1829 \end{mpcode}
1830
1831 \begin{colourband}
1832 \macro|Triangle(«a»,«b»,«c»)|\return{\typeMP{numeric}}
1833 \begin{description}
1834 \item[\meta{a}:] \typeGDD{point} ;
1835 \item[\meta{b}:] \typeGDD{point} ;
1836 \item[\meta{c}:] \typeGDD{point}.
1837 \end{description}\index{Triangle@\lstinline+Triangle+}
1838 \end{colourband}
1839
1840
1841 \bigskip
1842
1843 Here, we see the use of the third table \variableGDD{gddC} to store the third point.
1844
1845 A triangle is then defined as follows:
1846 \begin{ExempleMP}
1847 input geom2d;
1848 beginfig(1);
1849 A = Point(3,1);
1850 B = Point(1,3);
1851 C = Point(0,0);
1852 ABC = Triangle(A,B,C);
1853 gddDraw ABC;
1854 endfig;
1855 \end{ExempleMP}
1856
1857 \subsubsection{Associated Macros}
1858
1859 The following macro calculates the area of a triangle.
1860 \begin{colourband}
1861 \macro|TriangleArea(«a»)|\return{\typeMP{numeric}}
1862 \begin{description}
1863 \item[\meta{a}:] \typeGDD{triangle}.
1864 \end{description}\index{TriangleArea@\lstinline+TriangleArea+}
1865 \end{colourband}
1866
1867 We can also calculate the orthocenter of a triangle using the following command.
1868 \begin{colourband}
1869 \macro|Orthocenter(«a»)|\return{\typeGDD{point}}
1870 \begin{description}
1871 \item[\meta{a}:] \typeGDD{triangle}.
1872 \end{description}\index{Orthocenter@\lstinline+Orthocenter+}
1873 \end{colourband}
1874
1875 The following macro calculates the inscribed circle of a triangle.
1876 \begin{colourband}
1877 \macro|InscribedCircle(«a»)|\return{\typeGDD{cercle}}
1878 \begin{description}
1879 \item[\meta{a}:] \typeGDD{triangle}.
1880 \end{description}\index{InscribedCircle@\lstinline+InscribedCircle+}
1881 \end{colourband}
1882
1883 You can also obtain the circumscribed circle with the following macro.
1884 \begin{colourband}
1885 \macro|CircumscribedCircle(«a»)|\return{\typeGDD{cercle}}
1886 \begin{description}
1887 \item[\meta{a}:] \typeGDD{triangle}.
1888 \end{description}\index{CircumscribedCircle@\lstinline+CircumscribedCircle+}
1889 \end{colourband}
1890 We can also calculate the escribed circles. Let \(A\), \(B\), and \(C\) be three points
1891 defining a triangle \(ABC\)\footnote{Of course, the points can have different names.}.
1892 The following command allows obtaining one of the three escribed circles, as desired.
1893 \begin{colourband}
1894 \macro|EscribedCircle(«a»,«n»)|\return{\typeGDD{cercle}}
1895 \begin{description}
1896 \item[\meta{a}:] \typeGDD{triangle};
1897 \item[\meta{n}:] \typeMP{numeric} which can be 1, 2, or 3. If \meta{n}$=1$, it is
1898 the escribed circle tangent to the side \([BC]\) of the triangle; if \meta{n}$=2$, it is
1899 the one tangent to the side \([AC]\); and if \meta{n}$=3$, it is the one tangent to the side \([AB]\).
1900 \end{description}\index{EscribedCircle@\lstinline+EscribedCircle+}
1901 \end{colourband}
1902 You can also obtain the Euler circle of a triangle with the following command.
1903 \begin{colourband}
1904 \macro|EulerCircle(«a»)|\return{\typeGDD{cercle}}
1905 \begin{description}
1906 \item[\meta{a}:] \typeGDD{triangle}.
1907 \end{description}\index{EulerCircle@\lstinline+EulerCircle+}
1908 \end{colourband}
1909
1910 Here is an example illustrating some of the macros related to triangles.
1911 \begin{ExempleMP}
1912 input geom2d;
1913 beginfig(1);
1914 A = Point(3,1);
1915 B = Point(1,3);
1916 C = Point(0,0);
1917 AB = Line(A,B);
1918 BC = Line(B,C);
1919 ABC = Triangle(A,B,C);
1920 gddDraw AB dashed evenly;
1921 gddDraw BC dashed evenly;
1922 gddDraw ABC withPen(1.5,black);
1923 Euler = EulerCircle(ABC);
1924 gddDraw Euler withPen(1,DarkRed);
1925 C_E1 = EscribedCircle(ABC,2);
1926 gddDraw C_E1 withPen(1,LightBlue);
1927 C_C = CircumscribedCircle(ABC);
1928 gddDraw C_C withPen(1,LightCoral);
1929 Window(-1,-4,4,4);
1930 endfig;
1931 \end{ExempleMP}
1932
1933 \subsection{The \typeGDD{polygon} type}
1934 Polygons are defined by $N$ points in $\R^2$.
1935
1936 \subsubsection{Constructors}
1937
1938 The constructor function for this object is as follows:
1939 \begin{mpcode}
1940 vardef Polygon e(text plist) =
1941 save n,_point,i; n = incr gddO; gddT[n] = "polygone";
1942 i:=1;
1943 for _point = plist:
1944 gddX[gddO][i] = PointImp(_point);
1945 i:=i+1;
1946 endfor
1947 gddA[n] = i-1; % number of sides
1948 gddB[n] = IsoBarycenter(plist); % center
1949 n
1950 enddef;
1951 \end{mpcode}
1952
1953 \begin{colourband}
1954 \macro|Polygon(«list»)|\return{\typeGDD{polygone}}
1955 \begin{description}
1956 \item[\meta{list}:] is a list of \typeGDD{point} or \typeMP{pair}.
1957 \end{description}\index{Polygon@\lstinline+Polygon+}
1958 \end{colourband}
1959
1960
1961 \bigskip
1962 Here, we see the use of the \emph{double} table \variableGDD{gddX} to store
1963 the $N$ points.
1964
1965 A polygon is then defined as follows:
1966 \begin{ExempleMP}
1967 input geom2d;
1968 beginfig(1);
1969 A = Point(2,0);
1970 B = Point(3,1);
1971 C = Point(0,2);
1972 D = Point(0,0);
1973 P = Polygon(A,B,C,D);
1974 gddDraw P;
1975 endfig;
1976 \end{ExempleMP}
1977
1978 You can also construct regular polygons with the following command.
1979 \begin{colourband}
1980 \macro|RegularPolygon(«N»,«radius»,«rotation»,«translation»)|\return{\typeGDD{polygone}}
1981 \begin{description}
1982 \item[\meta{N}:] integer (\typeMP{numeric}) indicating the number of points;
1983 \item[\meta{radius}:] \typeMP{numeric}, radius of the circumscribed circle;
1984 \item[\meta{rotation}:] \typeMP{numeric}, rotation of the polygon;
1985 \item[\meta{translation}:] \typeGDD(point) or \typeGDD{vecteur} (or even
1986 \typeMP{pair}), displacement of the polygon's center.
1987 \end{description}\index{RegularPolygon@\lstinline+RegularPolygon+}
1988 \end{colourband}
1989
1990 \begin{ExempleMP}
1991 input geom2d;
1992 beginfig(1);
1993 P = RegularPolygon(7,3,0,origine);
1994 gddDraw P;
1995 endfig;
1996 \end{ExempleMP}
1997
1998 \subsubsection{Associated Macros}
1999
2000 You can obtain the number of sides of a polygon with the following command.
2001
2002 \begin{colourband}
2003 \macro|PolygonNumberOfSides(«a»)|\return{\typeMP{numeric}}
2004 \begin{description}
2005 \item[\meta{a}:] \typeGDD{polygone}.
2006 \end{description}\index{PolygonNumberOfSides@\lstinline+PolygonNumberOfSides+}
2007 \end{colourband}
2008 \bigskip
2009
2010 You can access the different vertices of the polygon, numbered starting from 1, using the following macro.
2011
2012 \begin{colourband}
2013 \macro|PolygonPoint(«a»,«i»)|\return{\typeGDD{point}}
2014 \begin{description}
2015 \item[\meta{a}:] \typeGDD{polygone};
2016 \item[\meta{i}:] \typeMP{numeric}, an integer greater than or equal to 1, allowing access to the $i$\textsuperscript{th} point of the polygon.
2017 \end{description}\index{PolygonPoint@\lstinline+PolygonPoint+}
2018 \end{colourband}
2019 \bigskip
2020
2021 \subsection{The \typeGDD{chemin} type}
2022
2023 For this particular type (french translation of \emph{path}), \mpgeomdd stores
2024 the \typeMP{path} in the reserved \variableGDD{gddP} table. Thus, the constructor
2025 function for this type of object is as follows:
2026 \begin{mpcode}
2027 vardef Chemin (expr p) =
2028 gddT[incr gddO] = "chemin"; gddP[gddO] = p; gddO
2029 enddef;
2030 \end{mpcode}
2031 \begin{colourband}
2032
2033 We defined the english macro \lstinline+Path+ for the english interface.
2034
2035 \macro|Path(«p»)|\return{\typeGDD{chemin}}
2036 \begin{description}
2037 \item[\meta{p}:] a \typeMP{path} from \MP
2038 \end{description}\index{Path@\lstinline+Path+}
2039 \end{colourband}
2040
2041
2042 \subsubsection{Associated Macros}
2043
2044 The following macro constructs, from a list of \typeGDD{point}s, a polyline of
2045 type \typeGDD{chemin}.
2046
2047 \begin{colourband}
2048 \macro|Polyline(«list»)|\return{\typeGDD{chemin}}
2049 \begin{description}
2050 \item[\meta{list}:] is a list of \typeGDD{point} or \typeMP{pair}.
2051 \end{description}\index{Polyline@\lstinline+Polyline+}
2052 \end{colourband}
2053
2054 \subsection{The \typeGDD{courbe} type}
2055
2056 For this particular type, \mpgeomdd stores
2057 a string (a filename to be used with the \fichier{graph.mp} extension) in the reserved \variableGDD{gddS} table.
2058
2059 \subsubsection{Constructor}
2060
2061 The constructor function for this type of object is as follows:
2062 \begin{mpcode}
2063 vardef CourbeDat (expr s) =
2064 gddT[incr gddO] = "courbe"; gddS[gddO] = s; gddO
2065 enddef;
2066 \end{mpcode}
2067
2068 The engilsh interface uses the macro \lstinline+CurveData+.
2069
2070 \begin{colourband}
2071 \macro|CurveData(«s»)|\return{\typeGDD{courbe}}
2072 \begin{description}
2073 \item[\meta{s}:] a filename in the form of a \typeMP{string} in \MP
2074 \end{description}\index{CurveData@\lstinline+CurveData+}
2075 \end{colourband}
2076
2077 \bigskip
2078
2079 \section{Circle Arc}
2080
2081 With \mpgeomdd{}, several commands allow working with circle arcs. First, you
2082 can choose to represent only a circle arc from a previously defined
2083 \typeGDD{cercle}. This is done using the following command, which takes as
2084 arguments a \typeGDD{cercle} and two angles in radians, and returns a
2085 \typeMP{path} in \MP{} corresponding to the circle arc between the two given
2086 angles (angle 0 being parallel to the $Ox$ axis).
2087
2088 \begin{colourband}
2089 \macro|gddDrawCircleArc(«C»,«a»,«b»)|\return{\typeMP{path}}
2090 \begin{description}
2091 \item[\meta{C}:] \typeGDD{cercle} from which we want to represent an arc;
2092 \item[\meta{a}:] first angle in radians (\typeMP{numeric});
2093 \item[\meta{b}:] second angle in radians (\typeMP{numeric}).
2094 \end{description}\index{gddDrawCircleArc@\lstinline+gddDrawCircleArc+}
2095 \end{colourband}
2096
2097 \begin{ExempleMP}
2098 input geom2d;
2099 beginfig(1);
2100 C = Circle(origin,2);
2101 gddDraw C;
2102 gddDraw gddDrawCircleArc(C,Pi/3,Pi) withPen(2,DarkRed);
2103 endfig;
2104 \end{ExempleMP}
2105 You can also define a \typeGDD{path} object. For this, you can use the following two commands. The first allows you to define a circular arc from a point, a radius, and two angles.
2106
2107 \begin{colourband}
2108 \macro|Arc(«P»,«r»,«a»,«b»)|\return{\typeGDD{path}}
2109 \begin{description}
2110 \item[\meta{P}:] \typeGDD{point} or \typeMP{pair}, center of the circular arc;
2111 \item[\meta{r}:] radius of the circular arc (\typeMP{numeric});
2112 \item[\meta{a}:] first angle in radians (\typeMP{numeric});
2113 \item[\meta{b}:] second angle in radians (\typeMP{numeric}).
2114 \end{description}\index{Arc@\lstinline+Arc+}
2115 \end{colourband}
2116
2117
2118 \begin{ExempleMP}
2119 input geom2d;
2120 beginfig(1);
2121 A = Point(2,2);
2122 Ac = Arc(A,2,Pi/3,Pi);
2123 gddDrawPoint A;
2124 gddDraw Ac;
2125 endfig;
2126 \end{ExempleMP}
2127
2128 The second command defining a \typeGDD{chemin} is as follows. It takes as arguments three points, denoted as $C$, $A$, and $B$: the center of the circular arc $C$, and the points $A$ and $B$. It then takes as an argument the radius of the arc defined between the segments $[C,A]$ and $[C,B]$.
2129 \begin{colourband}
2130 \macro|ArcBetweenPoints(«P»,«r»,«A»,«B»,«s»)|\return{\typeGDD{path}}
2131 \begin{description}
2132 \item[\meta{P}:] \typeGDD{point} or \typeMP{pair}, center of the circular arc;
2133 \item[\meta{r}:] radius of the circular arc (\typeMP{numeric});
2134 \item[\meta{A}:] first \typeGDD{point} or \typeMP{pair};
2135 \item[\meta{B}:] second \typeGDD{point} or \typeMP{pair};
2136 \item[\meta{s}:] \typeMP{numeric}, $-1$ or $1$ depending on the chosen direction.
2137 \end{description}\index{ArcBetweenPoints@\lstinline+ArcBetweenPoints+}
2138 \end{colourband}
2139
2140 \begin{ExempleMP}
2141 input geom2d;
2142 beginfig(1);
2143 C = Point(0,0);
2144 A = Point(2,2);
2145 B = Point(0,3);
2146 Cab = ArcBetweenPoints(C,1,A,B,1);
2147 Cba = ArcBetweenPoints(C,1,A,B,-1);
2148 gddDraw Segment(C,A);
2149 gddDraw Segment(C,B);
2150 gddDrawPoint A; gddDrawPoint B; gddDrawPoint C;
2151 gddArrow Cab;
2152 gddArrow Cba withPen(1,DarkRed);
2153 endfig;
2154 \end{ExempleMP}
2155
2156 \section{Some Macros}
2157
2158 This section groups together some macros that are not specific to a type.
2159 \bigskip
2160
2161 The following macro allows calculating an intersection point between two
2162 \mpgeomdd objects. It is essentially a wrapper around the \MP{} primitive
2163 \lstinline|intersectionpoint| applied to the \emph{drawn} objects (using
2164 \lstinline+gddTraceObjet+).
2165
2166 \begin{colourband}
2167 \macro|PointIntersection(«o»,«b»)|\return{\typeGDD{point}}
2168 \begin{description}
2169 \item[\meta{o}:] a \mpgeomdd object;
2170 \item[\meta{b}:] a \mpgeomdd object.
2171 \end{description}\index{PointIntersection@\lstinline+PointIntersection+}
2172 \end{colourband}
2173
2174 \section{Some Transformations}
2175
2176 \subsection{Homothety}
2177
2178 You can perform a homothety on any \mpgeomdd object using the following command.
2179
2180 \begin{colourband}
2181 \macro|Homothety(«p»,«o»,«k»)|\return{same type as \meta{p}}
2182 \begin{description}
2183 \item[\meta{p}:] a \mpgeomdd object;
2184 \item[\meta{o}:] \typeGDD{point} or \typeMP{pair}, center of the homothety;
2185 \item[\meta{k}:] \typeMP{numeric}, scaling factor of the homothety.
2186 \end{description}\index{Homothety@\lstinline+Homothety+}
2187 \end{colourband}
2188
2189 \begin{ExempleMP}
2190 input geom2d;
2191 beginfig(1);
2192 A = Point(1,2);
2193 B = Point(0,2);
2194 C_B = Circle(B,1);
2195 T = Triangle((1,1),(0,0),(0,1));
2196 C_H = Homothety(C_B, A, 2);
2197 T_H = Homothety(T, A ,-1);
2198 gddDraw C_B; gddDraw C_H;
2199 gddDraw T; gddDraw T_H;
2200 gddDrawPoint A; gddDrawPoint B;
2201 endfig;
2202 \end{ExempleMP}
2203
2204
2205 \subsection{Axial Symmetry}
2206
2207 You can perform an axial symmetry on any \mpgeomdd object using the following command.
2208
2209 \begin{colourband}
2210 \macro|AxialSymmetry(«p»,«d»)|\return{same type as \meta{p}}
2211 \begin{description}
2212 \item[\meta{p}:] a \mpgeomdd object;
2213 \item[\meta{d}:] \typeGDD{droite} defining the axis of symmetry.
2214 \end{description}\index{AxialSymmetry@\lstinline+AxialSymmetry+}
2215 \end{colourband}
2216
2217 \begin{ExempleMP}
2218 input geom2d;
2219 beginfig(1);
2220 A = Point(1,2);
2221 B = Point(0,2);
2222 C_B = Circle(B,1);
2223 T = Triangle((1,1),(0,0),(0,1));
2224 D = Line((-1,0),(3,-1));
2225 C_H = AxialSymmetry(C_B, D);
2226 T_H = AxialSymmetry(T, D);
2227 gddDraw C_B; gddDraw C_H;
2228 gddDraw T; gddDraw T_H;
2229 gddDraw D;
2230 gddDrawPoint A; gddDrawPoint B;
2231 Window(-2.5,-3.5,3,3.2);
2232 endfig;
2233 \end{ExempleMP}
2234
2235
2236 \subsection{Central Symmetry}
2237
2238 You can perform a central symmetry on any \mpgeomdd object using the following command.
2239
2240 \begin{colourband}
2241 \macro|CentralSymmetry(«p»,«d»)|\return{same type as \meta{p}}
2242 \begin{description}
2243 \item[\meta{p}:] a \mpgeomdd object;
2244 \item[\meta{d}:] \typeGDD{point} defining the center of symmetry.
2245 \end{description}\index{CentralSymmetry@\lstinline+CentralSymmetry+}
2246 \end{colourband}
2247
2248 \begin{ExempleMP}
2249 input geom2d;
2250 beginfig(1);
2251 A = Point(1,2);
2252 B = Point(0,2);
2253 C_B = Circle(B,1);
2254 T = Triangle((1,1),(0,0),(0,1));
2255 D = Point(-1,0);
2256 C_H = CentralSymmetry(C_B, D);
2257 T_H = CentralSymmetry(T, D);
2258 gddDraw C_B; gddDraw C_H;
2259 gddDraw T; gddDraw T_H;
2260 gddDrawPoint D;
2261 gddDrawPoint A; gddDrawPoint B;
2262 Window(-3.5,-3.5,3,3.2);
2263 endfig;
2264 \end{ExempleMP}
2265 \subsection{Inversion}
2266
2267 You can compute the inversion of a point, a circle, or a line with respect to a circle using the following macro:
2268 \begin{colourband}
2269 \macro|Inverse(«p»,«c»)|\return{\typeGDD{point}}
2270 \begin{description}
2271 \item[\meta{p}:] \typeGDD{point}, \typeGDD{cercle}, or \typeGDD{droite};
2272 \item[\meta{c}:] \typeGDD{cercle}.
2273 \end{description}\index{Inverse@\lstinline+Inverse+}
2274 \end{colourband}
2275 \bigskip
2276
2277 \begin{ExempleMP}
2278 input geom2d;
2279 beginfig(1);
2280 A = Point(2,2);
2281 C = Circle(A,2);
2282 gddDraw C;
2283 gddMark.rt "A";
2284 B = Point(-0.5,1);
2285 D = Inverse(B,C);
2286 drawoptions(withcolor DarkRed);
2287 gddMark.rt "B"; gddMark.rt "D";
2288
2289 drawoptions(withcolor DarkBlue);
2290 E = Point(3,1);
2291 CE = Circle(E,0.5);
2292 gddDraw CE;
2293 gddMark.rt "E";
2294 iCE = Inverse(CE,C);
2295 gddDraw iCE;
2296
2297 drawoptions(withcolor DarkGreen);
2298 d = Line((3,3),(4,2));
2299 gddDraw d;
2300 Cd = Inverse(d,C);
2301 gddDraw Cd;
2302 Window(-1,-1,5.5,6);
2303 endfig;
2304 \end{ExempleMP}
2305
2306 \subsection{Similirity with center (direct)}
2307
2308 One can compute a similarity centered at a point with a given ratio. This is done using the following macro.
2309
2310 \begin{colourband}
2311 \macro|CenterSimilarity(«p»,«d»,«a»,«k»)|\return{same type as \meta{p}}
2312 \begin{description}
2313 \item[\meta{p}:] a \mpgeomdd{} object;
2314 \item[\meta{d}:] a \typeGDD{point} defining the center of the similarity;
2315 \item[\meta{a}:] angle (in radians, \typeMP{numeric}) of the similarity;
2316 \item[\meta{k}:] similarity factor (\typeMP{numeric}).
2317 \end{description}\index{CenterSimilarity@\lstinline+CenterSimilarity+}
2318 \end{colourband}
2319
2320 \begin{ExempleMP}
2321 input geom2d;
2322 beginfig(1);
2323 A = Point(1,2);
2324 B = Point(0,2);
2325 C_B = Circle(B,1);
2326 ratioSimi = 0.4;
2327 angleSimi = Pi/3;
2328 T = Triangle((1,1),(0,0),(0,1));
2329 D = Point(-1,0);
2330 C_H = CenterSimilarity(C_B, D, angleSimi, ratioSimi);
2331 T_H = CenterSimilarity(T, D, angleSimi, ratioSimi);
2332 gddDraw C_B; gddDraw C_H;
2333 gddDraw T; gddDraw T_H;
2334 endfig;
2335 \end{ExempleMP}
2336
2337 \section{Annotations and Labels}
2338
2339 \subsection{Right Angle Marks}
2340
2341 \mpgeomdd provides the following macro to mark a right angle formed by three points:
2342 \begin{colourband}
2343 \macro|OrthoSign(«a»,«b»,«c»,«x»)|
2344 \begin{description}
2345 \item[\meta{a},\meta{b},\meta{c}:] are the three \typeGDD{point}s forming the right angle $\widehat{ABC}$;
2346 \item[\meta{x}:] is the \enquote{size} (\typeMP{numeric}) of the right angle mark.
2347 \end{description}\index{OrthoSign@\lstinline+OrthoSign+}
2348 \end{colourband}
2349 You can also create marks between two points or on a segment, a vector, or any type of object. For this, the first macro is as follows:
2350 \begin{colourband}
2351 \macro|Mark(«a»,«b»,«n»)|
2352 \begin{description}
2353 \item[\meta{a}:] first \typeGDD{point} forming
2354 the segment to be marked;
2355 \item[\meta{b}:] second \typeGDD{point} forming
2356 the segment to be marked;
2357 \item[\meta{n}:] is the type (\typeMP{numeric}) of mark, there are four
2358 \meta{n}$=1$, $2$, $3$, or $4$.
2359 \end{description}\index{Mark@\lstinline+Mark+}
2360 \end{colourband}
2361 You can also mark any type of line with the following macro:
2362 \begin{colourband}
2363 \macro|LineMark(«a»,«n»)|
2364 \begin{description}
2365 \item[\meta{a}:] can be any \mpgeomdd object or even a \typeMP{path} in \MP;
2366 \item[\meta{n}:] is the type (\typeMP{numeric}) of mark, there are four types:
2367 \meta{n}$=1$, $2$, $3$, or $4$.
2368 \end{description}\index{LineMark@\lstinline+LineMark+}
2369 \end{colourband}
2370
2371
2372 \begin{ExempleMP}
2373 input geom2d;
2374 beginfig(1);
2375 A = Point(4,0);
2376 B = Point(0,0);
2377 C = Point(0,2);
2378 gddDraw Segment(B,A);
2379 gddDraw Segment(B,C);
2380 gddMark.bot "A";
2381 gddMark.bot "B";
2382 gddMark.lft "C";
2383 gddDraw OrthoSign(A,B,C,0.5);
2384 gddDraw Mark(A,B,1);
2385 gddDraw LineMark(Segment(B,C),3);
2386 endfig;
2387 \end{ExempleMP}
2388
2389 \subsection{Labels}
2390
2391 Since the code produced with \mpgeomdd is \MP{} code~\cite{ctan-metapost}, we can use the classic labeling tools. However, to allow more flexibility (and particularly compatibility with \hologo{LuaLaTeX} and \package{luamplib}~\cite{ctan-luamplib} or \package{minim-mp}~\cite{ctan-minim-mp}), if the code is compiled with \MP{}, then the package~\package{latexmp}~\cite{ctan-latexmp} is loaded and provides the \lstinline+textext()+ command.
2392
2393 Additionally, \mpgeomdd provides some commands to make life easier.
2394
2395 Points can be marked using the following command. This command \emph{marks} the point (using the \lstinline+gddDrawPoint+ command, see section~\ref{sec:trace}) and adds a label.
2396 \begin{colourband}
2397 \macro|gddMark.«place» "«name»"|
2398 \begin{description}
2399 \item[\meta{place}:] can be the classic placements of \MP{}:
2400 \lstinline+top+, \lstinline+bot+, \lstinline+rt+,
2401 \lstinline+lft+, \lstinline+urt+, \lstinline+ulft+, \lstinline+lrt+, \lstinline+llft+.
2402 \item[\meta{name}:] enclosed in double quotes, must be the name of a point variable. The name will be typeset in math mode (enclosed in \lstinline+$+). If the name contains an \lstinline+_+, everything after it will be subscripted (e.g., \lstinline+A_be+ will become $A_{be}$). If the name is \lstinline+alpha+, \lstinline+beta+, \lstinline+gamma+, or \lstinline+delta+, the result will be the corresponding Greek letter typeset in math mode.
2403 \end{description}\index{gddMark@\lstinline+gddMark+}
2404 \end{colourband}
2405
2406 \mpgeomdd also provides an adaptation to the classic \lstinline+label+ of \MP{}.
2407
2408 \begin{colourband}
2409 \macro|gddLabel.«place»(«content»,«point»)|
2410 \begin{description}
2411 \item[\meta{place}:] can be the classic placements of \MP{}:
2412 \lstinline+top+, \lstinline+bot+, \lstinline+rt+,
2413 \lstinline+lft+, \lstinline+urt+, \lstinline+ulft+, \lstinline+lrt+, \lstinline+llft+.
2414 \item[\meta{content}:] typically what is given to \lstinline+label+, a string,
2415 or a \typeMP{picture} (which can be produced, for example, with
2416 \lstinline+btex ... etex+ or, since \package{latexmp} is loaded by \mpgeomdd,
2417 \lstinline+textext()+).
2418 \item[\meta{point}:] must be a \typeGDD{point} from \mpgeomdd.
2419 \end{description}\index{gddLabel@\lstinline+gddLabel+}
2420 \end{colourband}
2421
2422 You can also label a \typeGDD{chemin}, a \typeGDD{courbe}, or a
2423 \typeMP{path} using the following macro:
2424
2425 \begin{colourband}
2426 \macro|PathTag.«place»(«content»,«path»,«position»)|
2427 \begin{description}
2428 \item[\meta{place}:] can be the classic placements of \MP{}:
2429 \lstinline+top+, \lstinline+bot+, \lstinline+rt+,
2430 \lstinline+lft+, \lstinline+urt+, \lstinline+ulft+, \lstinline+lrt+, \lstinline+llft+.
2431 \item[\meta{content}:] typically what is given to \lstinline+label+, a string,
2432 or a \typeMP{picture} (which can be produced, for example, with
2433 \lstinline+btex ... etex+ or, since \package{latexmp} is loaded by \mpgeomdd,
2434 \lstinline+textext()+).
2435 \item[\meta{path}:] must be a \typeGDD{chemin}, a \typeGDD{courbe}, or
2436 a \typeMP{path}.
2437 \end{description}\index{PathTag@\lstinline+PathTag+}
2438 \end{colourband}
2439
2440
2441 \begin{ExempleMP}
2442 input geom2d;
2443 beginfig(1);
2444 A = Point(0,0);
2445 B_23 = Point(3,3);
2446 alpha = Point(0,2);
2447 gddDraw Segment(A,B_23);
2448 C = MidPoint(A,B_23);
2449 gddDrawPoint C;
2450 gddLabel.top(textext("Midpoint"),C);
2451 gddMark.top "A";
2452 gddMark.urt "B_23";
2453 gddMark.llft "alpha";
2454 P = Path(Pt(A)..Pt(alpha)..Pt(B_23));
2455 gddDraw P;
2456 PathTag.top("Test",P,0.6);
2457 endfig;
2458 \end{ExempleMP}
2459
2460
2461 \section{Coordinate System}
2462
2463 \mpgeomdd provides a set of commands to facilitate the drawing of coordinate systems.
2464
2465 The main command is the definition of the coordinate system, that is, the box in which the drawing will be represented.
2466 \begin{colourband}
2467 \macro|Frame(«l»,«h»,«ox»,«oy»,«ux»,«uy»)|
2468 \begin{description}
2469 \item[\meta{l}:] \typeMP{numeric}, width of the coordinate system (in \lstinline+gddU+ units);
2470 \item[\meta{h}:] \typeMP{numeric}, height of the coordinate system (in \lstinline+gddU+ units);
2471 \item[\meta{ox}:] \typeMP{numeric}, distance (in \lstinline+gddU+ units) from the origin (\typeGDD{point} $(0,0)$) to the left edge;
2472 \item[\meta{oy}:] \typeMP{numeric}, distance (in \lstinline+gddU+ units) from the origin (\typeGDD{point} $(0,0)$) to the bottom edge;
2473 \item[\meta{ux}:] \typeMP{numeric}, unit of the $(Ox)$ axis (in \lstinline+gddU+ units);
2474 \item[\meta{uy}:] \typeMP{numeric}, unit of the $(Oy)$ axis (in \lstinline+gddU+ units).
2475 \end{description}\index{Frame@\lstinline+Frame+}
2476 \end{colourband}
2477
2478
2479 This command does not return or draw anything. It serves to specify some internal variables for drawing definition. It also modifies the behavior of the \lstinline+gddInPlace+ macro (see page~\pageref{gddEnPlace}). Note that this command requires that the origin (i.e., the \typeGDD{point} $(0,0)$) is inside the coordinate system.
2480
2481 This macro is accompanied by two others, also \emph{silent}, which serve only to:
2482 \begin{itemize}
2483 \item save the current \typeMP{picture};
2484 \item build a \typeMP{picture} with the content found between \lstinline+gddBegin+ and \lstinline+gddEnd+;
2485 \item crop (with \lstinline+clip+) the \typeMP{picture} to the frame of the constructed coordinate system;
2486 \item add the current \typeMP{picture} to the saved one;
2487 \item finally, restore the behavior of \lstinline+gddInPlace+ as it was before using \lstinline+Frame+.
2488 \end{itemize}
2489
2490 These two commands are called \lstinline+gddBegin+ and \lstinline+gddEnd+.
2491
2492 \begin{colourband}
2493 \macro|gddBegin|
2494 \index{gddBegin@\lstinline+gddBegin+}
2495 \end{colourband}
2496
2497 \begin{colourband}
2498 \macro|gddEnd|
2499 \index{gddEnd@\lstinline+gddEnd+}
2500 \end{colourband}
2501
2502 Thus, it is very easy to illustrate that, up to a change of orthogonal basis, a circle is an ellipse.
2503
2504
2505 \begin{ExempleMP}
2506 input geom2d;
2507 beginfig(1);
2508 A = Point(1,1);
2509 CA = Circle(A,2);
2510 Frame(5,5,1,1,1,0.5);
2511 gddBegin;
2512 gddDraw CA;
2513 gddEnd;
2514 endfig;
2515 \end{ExempleMP}
2516
2517 There are two commands available to draw the axes of the coordinate system. The first draws the axes passing through the origin.
2518 \begin{colourband}
2519 \macro|Axis|\indication{draws a set of elements on the coordinate system}
2520 \index{Axis@\lstinline+Axis+}
2521 \end{colourband}
2522
2523 This command also adds the labels for the $x$-axis and $y$-axis, which are stored in the following dedicated global variables:
2524 \begin{colourband}
2525 \macro|gddXlabel|\indication{\typeMP{string}, default value \lstinline+"$x$"+}
2526 \index{gddXlabel@\lstinline+gddXlabel+}
2527 \end{colourband}
2528
2529 \begin{colourband}
2530 \macro|gddYlabel|\indication{\typeMP{string}, default value \lstinline+"$y$"+}
2531 \index{gddYlabel@\lstinline+gddYlabel+}
2532 \end{colourband}
2533
2534 Note, these commands must be used before calling \lstinline+gddBegin+.
2535
2536 The following example illustrates how to draw the axes.
2537
2538 \begin{ExempleMP}
2539 input geom2d;
2540 beginfig(1);
2541 A = Point(1,1);
2542 CA = Circle(A,2);
2543 Frame(5,5,1,1,1,1);
2544 gddYlabel:="$z$";
2545 Axis;
2546 gddBegin;
2547 gddDraw CA;
2548 gddEnd;
2549 endfig;
2550 \end{ExempleMP}
2551
2552 You can also define a coordinate system using a syntax that allows you to specify the minimum and maximum abscissas and ordinates.
2553
2554 \begin{colourband}
2555 \macro|FrameMinMax(«xmin»,«xmax»,«ymin»,«ymax»,«ux»,«uy»)|
2556 \begin{description}
2557 \item[\meta{xmin}:] \typeMP{numeric}, minimum abscissa (in \lstinline+gddU+ units).
2558 \item[\meta{xmax}:] \typeMP{numeric}, maximum abscissa (in \lstinline+gddU+ units).
2559 \item[\meta{ymin}:] \typeMP{numeric}, minimum ordinate (in \lstinline+gddU+ units).
2560 \item[\meta{ymax}:] \typeMP{numeric}, maximum ordinate (in \lstinline+gddU+ units).
2561 \item[\meta{ux}:] \typeMP{numeric}, unit of the $(Ox)$ axis (in \lstinline+gddU+ units).
2562 \item[\meta{uy}:] \typeMP{numeric}, unit of the $(Oy)$ axis (in \lstinline+gddU+ units).
2563 \end{description}\index{FrameMinMax@\lstinline+FrameMinMax+}
2564 \end{colourband}
2565
2566 \begin{ExempleMP}
2567 input geom2d;
2568 beginfig(1);
2569 A = Point(1,1);
2570 CA = Circle(A,2);
2571 FrameMinMax(-1,4,-1,4,1,1);
2572 Axis;
2573 gddBegin;
2574 gddDraw CA;
2575 gddEnd;
2576 endfig;
2577 \end{ExempleMP}
2578
2579 \mpgeomdd also provides a way to draw axes on the edge of the frame with the following command.
2580 \begin{colourband}
2581 \macro|SideAxis|\indication{draws a set of elements on the coordinate system}
2582 \index{SideAxis@\lstinline+SideAxis+}
2583 \end{colourband}
2584
2585 \begin{ExempleMP}
2586 input geom2d;
2587 beginfig(1);
2588 A = Point(1,1);
2589 CA = Circle(A,2);
2590 FrameMinMax(-1,4,-1,4,1,1);
2591 SideAxis;
2592 gddBegin;
2593 gddDraw CA;
2594 gddEnd;
2595 endfig;
2596 \end{ExempleMP}
2597
2598
2599 The following commands allow you to add graduations to the axes (either classic or on the edge). Again, these commands take no arguments, return nothing, and simply draw.
2600
2601 \begin{colourband}
2602 \macro|Graduations|\indication{draws a set of elements on the coordinate system}
2603 \index{Graduations@\lstinline+Graduations+}
2604 \end{colourband}
2605
2606
2607 \begin{colourband}
2608 \macro|SideGraduations|\indication{draws a set of elements on the coordinate system}
2609 \index{SideGraduations@\lstinline+SideGraduations+}
2610 \end{colourband}
2611
2612 Use the version consistent with the chosen axes.
2613 \begin{ExempleMP}
2614 input geom2d;
2615 beginfig(1);
2616 A = Point(1,1);
2617 CA = Circle(A,2);
2618 FrameMinMax(-1,4,-1,4,1,1);
2619 SideAxis;
2620 SideGraduations;
2621 gddBegin;
2622 gddDraw CA;
2623 gddEnd;
2624 endfig;
2625 \end{ExempleMP}
2626
2627 If you want to mark the units, \mpgeomdd{} provides the following macro (which can only be used if the axes are not placed on the border).
2628 \begin{colourband}
2629 \macro|Units(«unit»)|\indication{draws a set of elements on the coordinate system}
2630 \begin{description}
2631 \item[\meta{unit}:] \typeMP{numeric}, value to be displayed on both axes.
2632 \end{description}
2633 \index{Units@\lstinline+Units+}
2634 \end{colourband}
2635 \begin{ExempleMP}
2636 input geom2d;
2637 beginfig(1);
2638 A = Point(1,1);
2639 CA = Circle(A,2);
2640 FrameMinMax(-1,4,-1,4,1,1);
2641 Axis;
2642 gddBegin;
2643 Graduations;
2644 Units(2);
2645 gddDraw CA;
2646 gddEnd;
2647 endfig;
2648 \end{ExempleMP}
2649 You can also add a grid to your coordinate system with the following macro.
2650 \begin{colourband}
2651 \macro|FrameGrid|\indication{draws a set of elements on the coordinate system}
2652 \index{FrameGrid@\lstinline+FrameGrid+}
2653 \end{colourband}
2654 In the following example, the color of the grid is set using the
2655 \hologo{MetaPost} \lstinline+drawoptions+ command.
2656 \begin{ExempleMP}
2657 input geom2d;
2658 beginfig(1);
2659 A = Point(1,1);
2660 CA = Circle(A,2);
2661 FrameMinMax(-1,4,-1,4,1,1);
2662 drawoptions(withcolor LightGrey);
2663 FrameGrid;
2664 drawoptions();
2665 Axis;
2666 gddBegin;
2667 Graduations;
2668 Units(1);
2669 gddDraw CA;
2670 gddEnd;
2671 endfig;
2672 \end{ExempleMP}
2673 You can also add a frame to the coordinate system with the following macro.
2674 \begin{colourband}
2675 \macro|FrameBox|\return{\typeMP{path}}
2676 \index{FrameBox@\lstinline+FrameBox+}
2677 \end{colourband}
2678 In the following example, the color of the grid is set using the
2679 \hologo{MetaPost} \lstinline+drawoptions+ command.
2680 \begin{ExempleMP}
2681 input geom2d;
2682 beginfig(1);
2683 A = Point(1,1);
2684 CA = Circle(A,2);
2685 FrameMinMax(-1,4,-1,4,1,1);
2686 drawoptions(withcolor LightGrey);
2687 FrameGrid;
2688 drawoptions();
2689 Axis;
2690 gddBegin;
2691 Graduations;
2692 Units(1);
2693 gddDraw CA;
2694 gddDraw FrameBox withcolor OrangeRed;
2695 gddEnd;
2696 endfig;
2697 \end{ExempleMP}
2698
2699 \section{Some Mathematical Constants and Functions}
2700
2701 \mpgeomdd defines two mathematical constants, \lstinline+Pi+ and \lstinline+_E+
2702 \index{Pi@\lstinline+Pi+}\index{_E@\lstinline+_E+}, for the constants
2703 $\uppi\simeq 3.14159265$ and $\mathrm{e}=2.71828183$.
2704
2705 In addition, the package defines some mathematical functions of a real variable:
2706 \begin{colourband}
2707 \macro|sin(«x»)| \index{sin@\lstinline+sin+}
2708 \macro|cos(«x»)| \index{cos@\lstinline+cos+}
2709 \macro|tan(«x»)| \index{tan@\lstinline+tan+}
2710 \macro|exp(«x»)| \index{exp@\lstinline+exp+}
2711 \macro|ln(«x»)| \index{ln@\lstinline+ln+}
2712 \macro|cosh(«x»)| \index{ch@\lstinline+ch+}
2713 \macro|sinh(«x»)| \index{sh@\lstinline+sh+}
2714 \macro|tanh(«x»)| \index{th@\lstinline+th+}
2715 \macro|arcsin(«x»)| \index{arcsin@\lstinline+arcsin+}
2716 \macro|arccos(«x»)| \index{arccos@\lstinline+arccos+}
2717 \macro|arctan(«x»)| \index{arctan@\lstinline+arctan+}
2718 \end{colourband}
2719 \section{Representation of Curves and Functions}
2720
2721 \mpgeomdd{} also provides some macros to facilitate the simple representation of curves and mathematical functions.
2722
2723 \subsection{Function of a Real Variable}
2724
2725 To represent a function of a real variable, use the following macro:
2726 \begin{colourband}
2727 \macro|Plot(«function»)(«ti»,«tf»,«n»)|\return{\typeMP{path}}
2728 \begin{description}
2729 \item[\meta{function}:] is a \MP{} macro that defines the mathematical function of a real variable to be represented;
2730 \item[\meta{ti}:] is the initial value (\typeMP{numeric}) of the variable from which to start building the representation of the function;
2731 \item[\meta{tf}:] is the final value (\typeMP{numeric}) of the variable up to which to build the representation of the function;
2732 \item[\meta{n}:] is the number of steps (\typeMP{numeric}) used for the discretization of the representation.
2733 \end{description}
2734 \index{Plot@\lstinline+Plot+}
2735 \end{colourband}
2736
2737 \begin{ExempleMP}
2738 input geom2d;
2739 beginfig(1);
2740 FrameMinMax(-2Pi,2Pi,-1.1,1.1,0.4,1);
2741 Axis;
2742 gddBegin;
2743 Graduations;
2744 gddDraw Plot(cos,-2Pi,2Pi,100);
2745 gddEnd;
2746 endfig;
2747 \end{ExempleMP}
2748
2749 \subsection{Parametric Curve}
2750
2751 To represent a plane curve defined by two functions describing the abscissa and ordinate as functions of a parameter, use the following macro:
2752 \begin{colourband}
2753 \macro|Curve(«abscissa_function»)(«ordinate_function»)(«ti»,«tf»,«n»)|\return{\typeMP{path}}
2754 \begin{description}
2755 \item[\meta{abscissa\_function}:] is a \MP{} macro that defines the mathematical function of a real variable describing the evolution of the abscissa of the points of the curve to be represented;
2756 \item[\meta{ordinate\_function}:] is a \MP{} macro that defines the mathematical function of a real variable describing the evolution of the ordinate of the points of the curve to be represented;
2757 \item[\meta{ti}:] is the initial value (\typeMP{numeric}) of the variable from which to start building the representation of the function;
2758 \item[\meta{tf}:] is the final value (\typeMP{numeric}) of the variable up to which to build the representation of the function;
2759 \item[\meta{n}:] is the number of steps (\typeMP{numeric}) used for the discretization of the representation.
2760 \end{description}
2761 \index{Curve@\lstinline+Curve+}
2762 \end{colourband}
2763
2764 \begin{ExempleMP}
2765 input geom2d;
2766 vardef f_x(expr t)= cos(t) enddef;
2767 vardef f_y(expr t)= sin(2*t) enddef;
2768
2769 beginfig(1);
2770 FrameMinMax(-1.1,1.1,-1.1,1.1,2,2);
2771 Axis;
2772 gddBegin;
2773 Graduations;
2774 gddDraw Curve(f_x,f_y,-2Pi,2Pi,100);
2775 gddEnd;
2776 endfig;
2777 \end{ExempleMP}
2778
2779 To represent a plane curve defined by a function describing the polar coordinates as a function of a parameter, use the following macro:
2780 \begin{colourband}
2781 \macro|PolarCurve(«function»)(«ti»,«tf»,«n»)|\return{\typeMP{path}}
2782 \begin{description}
2783 \item[\meta{function}:] is a \MP{} macro that defines the mathematical function of a real variable describing the evolution of the polar coordinates of the points of the curve to be represented;
2784 \item[\meta{ti}:] is the initial value (\typeMP{numeric}) of the variable from which to start building the representation of the function;
2785 \item[\meta{tf}:] is the final value (\typeMP{numeric}) of the variable up to which to build the representation of the function;
2786 \item[\meta{n}:] is the number of steps (\typeMP{numeric}) used for the discretization of the representation.
2787 \end{description}
2788 \index{PolarCurve@\lstinline+PolarCurve+}
2789 \end{colourband}
2790
2791
2792 \begin{ExempleMP}
2793 input geom2d;
2794 a := 2;
2795 vardef cardioid(expr t)= a*(1+cos(t)) enddef;
2796 beginfig(1);
2797 FrameMinMax(-1.1,4.1,-2.8,2.8,1,1);
2798 Axis;
2799 gddBegin;
2800 Graduations;
2801 gddDraw PolarCurve(cardioid,0,2Pi,100);
2802 gddEnd;
2803 endfig;
2804 \end{ExempleMP}
2805
2806
2807 \subsection{Vector Fields}
2808
2809 \mpgeomdd provides macros for representing vector fields.
2810
2811 First, you can plot vector fields associated with a first-order differential equation for a function $y$ of the variable $x$:
2812 \[y'=F(x,y).\]
2813 The associated macro is as follows:
2814 \begin{colourband}
2815 \macro|VectorField(«function»)(«x»,«y»,«px»,«py»,«dx»,«color»)|\return{\typeMP{path}}
2816 \begin{description}
2817 \item[\meta{function}:] is a \MP{} macro that defines a mathematical function from $\R^2$ to $\R$;
2818 \item[\meta{x}:] is a value (\typeMP{numeric}), in \variableGDD{gddU} units, which allows shifting the grid of vectors along the $x$ direction, with points at all \meta{x}$+i$\meta{px} for integer $i$;
2819 \item[\meta{y}:] is a value (\typeMP{numeric}), in \variableGDD{gddU} units, which allows shifting the grid of vectors along the $y$ direction, with points at all \meta{y}$+i$\meta{py} for integer $i$;
2820 \item[\meta{px}:] is the value (\typeMP{numeric}), in \variableGDD{gddU} units, of the grid step along the $x$-axis for the representation of vectors;
2821 \item[\meta{py}:] is the value (\typeMP{numeric}), in \variableGDD{gddU} units, of the grid step along the $y$-axis for the representation of vectors;
2822 \item[\meta{dx}:] is the norm (\typeMP{numeric}), in \variableGDD{gddU} units, of the vectors in the vector field;
2823 \item[\meta{color}:] is the (\typeMP{color}) used to draw the vectors.
2824 \end{description}
2825 \index{VectorField@\lstinline+VectorField+}
2826 \end{colourband}
2827
2828 Since this macro uses the \lstinline+drawarrow+ macro from \MP{}, you will need to adjust the \lstinline+ahlength+ parameter to set the size of the arrowhead triangle (see~\cite{ctan-metapost}).
2829 \begin{ExempleMP}
2830 input geom2d;
2831 vardef F(expr x,y) = x - 2 * x * y enddef;
2832 vardef f(expr x) = 1/2 + a * exp(- x*x) enddef;
2833 beginfig(1);
2834 FrameMinMax(-2.5,2.5,-2.8,2.8,1,1);
2835 Axis;
2836 gddBegin;
2837 Graduations;
2838 ahlength := 1;
2839 VectorField(F,0,0,0.2,0.2,0.1,0.5white);
2840 % Integral curves
2841 for n = 0 upto 16:
2842 a := (n/2) - 4;
2843 gddDraw Plot(f,-2.5,2.5,50)
2844 withPen(1,(0.7,0.2,0.2));
2845 endfor
2846 gddEnd;
2847 endfig;
2848 \end{ExempleMP}
2849
2850 Similarly, you can plot vector fields of a function from
2851 $\R^2$ to $\R^2$.
2852 The associated macro is as follows:
2853 \begin{colourband}
2854 \macro|VectorFieldDD(«function»)(«x»,«y»,«px»,«py»,«dx»,«color»)|\return{\typeMP{path}}
2855 \begin{description}
2856 \item[\meta{function}:] is a \MP{} macro that defines a mathematical function from $\R^2$ to $\R^2$ (thus returning a \typeMP{pair});
2857 \item[\meta{x}:] is a value (\typeMP{numeric}), in \variableGDD{gddU} units, which shifts the grid of vectors along the $x$ direction, with points at all \meta{x}$+i$\meta{px} for integer $i$;
2858 \item[\meta{y}:] is a value (\typeMP{numeric}), in \variableGDD{gddU} units, which shifts the grid of vectors along the $y$ direction, with points at all \meta{y}$+i$\meta{py} for integer $i$;
2859 \item[\meta{px}:] is the value (\typeMP{numeric}), in \variableGDD{gddU} units, of the grid step along the $x$-axis for the representation of vectors;
2860 \item[\meta{py}:] is the value (\typeMP{numeric}), in \variableGDD{gddU} units, of the grid step along the $y$-axis for the representation of vectors;
2861 \item[\meta{dx}:] is the norm (\typeMP{numeric}), in \variableGDD{gddU} units, of the vectors in the vector field;
2862 \item[\meta{color}:] is the (\typeMP{color}) used to draw the vectors.
2863 \end{description}
2864 \index{VectorFieldDD@\lstinline+VectorFieldDD+}
2865 \end{colourband}
2866
2867
2868 \begin{ExempleMP}[sidebyside=false]
2869 input geom2d;
2870 gddXlabel := "$\theta$";
2871 gddYlabel := "$\dot\theta$";
2872 numeric b,c;
2873 b:=0.5;
2874 c=1.0;
2875
2876 vardef F(expr x,y) = (y,-b*y-c*sin(x)) enddef;
2877
2878 beginfig(1);
2879 Frame(10,6,2,4,2,2);
2880 Axis;
2881 Units(1);
2882 gddBegin;
2883 Graduations;
2884 trajectory := CurveData("solution0",0);
2885 VectorFieldDD(F,0.5,0.5,0.2,0.2,0.15,0.5white);
2886 gddDraw trajectory withPen(1,(0.7,0.2,0.2));
2887 gddDrawPoint Point(0,0) withPen(1,(0.7,0.2,0.2));
2888 gddDrawPoint Point(3.1415,0) withPen(1,(0.7,0.2,0.2));
2889 gddEnd;
2890 endfig;
2891 \end{ExempleMP}
2892
2893
2894
2895
2896
2897 \section{SVG Colors (\texttt{svgnames})}
2898
2899 \begin{mplibcode}
2900 input exemples/svgnames/palette.mp
2901 \end{mplibcode}
2902
2903
2904 \pagestyle{empty}
2905 \begin{landscape}
2906 \section{Gallery}
2907 \subsection{Coordinate System and External Tangents}
2908 \begin{minipage}{0.5\linewidth}
2909 \begin{center}
2910 \begin{mplibcode}
2911 input exemples/cercles/cercles2-en.mp;
2912 \end{mplibcode}
2913 \end{center}
2914 \end{minipage}
2915 \begin{minipage}{0.5\linewidth}
2916 \lstinputlisting[basicstyle=\ttfamily\small]{exemples/cercles/cercles2-en.mp}
2917 \end{minipage}
2918 \end{landscape}
2919
2920 \begin{landscape}
2921 \subsection{Vector in a Coordinate System}
2922
2923 \begin{multicols}{2}
2924 \begin{center}
2925 \begin{mplibcode}
2926 input exemples/reperes/reperes2-en.mp;
2927 \end{mplibcode}
2928 \end{center}
2929 \lstinputlisting[basicstyle=\ttfamily\scriptsize]{exemples/reperes/reperes2-en.mp}
2930 \end{multicols}
2931 \end{landscape}
2932
2933 \begin{landscape}
2934 \subsection{Pascal’s Theorem}
2935
2936 \begin{multicols}{2}
2937 \begin{center}
2938 \begin{mplibcode}
2939 input exemples/divers/pascalline-en.mp;
2940 \end{mplibcode}
2941 \end{center}
2942 \lstinputlisting[basicstyle=\ttfamily\scriptsize]{exemples/divers/pascalline-en.mp}
2943 \end{multicols}
2944 \end{landscape}
2945
2946 \begin{landscape}
2947 \subsection{Hyperbola}
2948
2949 \begin{multicols}{2}
2950 \begin{center}
2951 \begin{mplibcode}
2952 input exemples/coniques/hyper-en.mp;
2953 \end{mplibcode}
2954 \end{center}
2955 \lstinputlisting[basicstyle=\ttfamily\scriptsize]{exemples/coniques/hyper-en.mp}
2956 \end{multicols}
2957 \end{landscape}
2958
2959 \begin{landscape}
2960 \subsection{Astroid as an Envelope of Lines}
2961
2962 \begin{multicols}{2}
2963 \begin{center}
2964 \begin{mplibcode}
2965 input exemples/courbes/cp01-en.mp;
2966 \end{mplibcode}
2967 \end{center}
2968 \lstinputlisting[basicstyle=\ttfamily\scriptsize]{exemples/courbes/cp01-en.mp}
2969 \end{multicols}
2970 \end{landscape}
2971
2972
2973 \begin{landscape}
2974 \subsection{Lissajous Curve}
2975
2976 \begin{multicols}{2}
2977 \begin{center}
2978 \begin{mplibcode}
2979 input exemples/courbes/cp02-en.mp;
2980 \end{mplibcode}
2981 \end{center}
2982 \lstinputlisting[basicstyle=\ttfamily\scriptsize]{exemples/courbes/cp02-en.mp}
2983 \end{multicols}
2984 \end{landscape}
2985
2986 \begin{landscape}
2987 \subsection{Function Study}
2988
2989 \begin{multicols}{2}
2990 \begin{center}
2991 \begin{mplibcode}
2992 input exemples/courbes/cp05-en.mp;
2993 \end{mplibcode}
2994 \end{center}
2995 \lstinputlisting[basicstyle=\ttfamily\scriptsize]{exemples/courbes/cp05-en.mp}
2996 \end{multicols}
2997 \end{landscape}
2998
2999 \begin{landscape}
3000 \subsection{Bicorne}
3001
3002 \begin{multicols}{2}
3003 \begin{center}
3004 \begin{mplibcode}
3005 input exemples/courbes/cp08-en.mp;
3006 \end{mplibcode}
3007 \end{center}
3008 \lstinputlisting[basicstyle=\ttfamily\scriptsize]{exemples/courbes/cp08-en.mp}
3009 \end{multicols}
3010 \end{landscape}
3011
3012 \begin{landscape}
3013 \subsection{A function et its derivatives}
3014
3015 \begin{multicols}{2}
3016 \begin{center}
3017 \begin{mplibcode}
3018 input exemples/fonctions/fonction2-en.mp;
3019 \end{mplibcode}
3020 \end{center}
3021 \lstinputlisting[basicstyle=\ttfamily\scriptsize]{exemples/fonctions/fonction2-en.mp}
3022 \end{multicols}
3023 \end{landscape}
3024
3025 \begin{landscape}
3026 \subsection{Cardioid}
3027
3028 \begin{multicols}{2}
3029 \begin{center}
3030 \begin{mplibcode}
3031 input exemples/polaires/pol02-en.mp;
3032 \end{mplibcode}
3033 \end{center}
3034 \lstinputlisting[basicstyle=\ttfamily\scriptsize]{exemples/polaires/pol02-en.mp}
3035 \end{multicols}
3036 \end{landscape}
3037
3038 \begin{landscape}
3039 \subsection{Axis of similitude}
3040 \begin{center}
3041 \begin{mplibcode}
3042 input exemples/cercles/axessimilitude-en.mp;
3043 \end{mplibcode}
3044 \end{center}
3045 \begin{multicols}{2}
3046 \lstinputlisting[basicstyle=\ttfamily\scriptsize]{exemples/cercles/axessimilitude-en.mp}
3047 \end{multicols}
3048 \end{landscape}
3049
3050
3051 \begin{landscape}
3052 \subsection{Cubic Drawing}
3053 \begin{multicols}{2}
3054 \begin{center}
3055 \begin{mplibcode}
3056 input exemples/cubiques/K001-en.mp;
3057 \end{mplibcode}
3058 \end{center}
3059 \lstinputlisting[basicstyle=\ttfamily\scriptsize]{exemples/cubiques/K001-en.mp}
3060 \end{multicols}
3061 \end{landscape}
3062
3063 \begin{landscape}
3064 \subsection{Apollonius}
3065
3066 \begin{multicols}{2}
3067 \begin{center}
3068 \begin{mplibcode}
3069 input exemples/triangles/apollonius-en.mp;
3070 \end{mplibcode}
3071 \end{center}
3072 \lstinputlisting[basicstyle=\ttfamily\scriptsize]{exemples/triangles/apollonius-en.mp}
3073 \end{multicols}
3074 \end{landscape}
3075
3076 \begin{landscape}
3077 \subsection{Ogive Working Drawing}
3078
3079 \begin{multicols}{2}
3080 \begin{center}
3081 \begin{mplibcode}
3082 input exemples/construction/ogiveentiers-en.mp;
3083 \end{mplibcode}
3084 \end{center}
3085 \lstinputlisting[basicstyle=\ttfamily\scriptsize]{exemples/construction/ogiveentiers-en.mp}
3086 \end{multicols}
3087 \end{landscape}
3088
3089 \begin{landscape}
3090 \subsection{Pedal Triangle}
3091
3092 Figure 21 of~\cite{toeplitz}.
3093 \begin{center}
3094 \begin{mplibcode}
3095 input exemples/triangles/pedale-en.mp;
3096 \end{mplibcode}
3097 \end{center}
3098 \begin{multicols}{2}
3099 \lstinputlisting[basicstyle=\ttfamily\scriptsize]{exemples/triangles/pedale-en.mp}
3100 \end{multicols}
3101 \end{landscape}
3102 \newpage
3103
3104 \begin{landscape}
3105 \subsection{Pappus Chain}
3106
3107 Pappus chain with geometric inverse.
3108 \begin{multicols}{2}
3109 \begin{mplibcode}
3110 input exemples/cercles/pappuschain-en.mp;
3111 \end{mplibcode}
3112
3113 \lstinputlisting[basicstyle=\ttfamily\scriptsize]{exemples/cercles/pappuschain-en.mp}
3114 \end{multicols}
3115 \end{landscape}
3116 \newpage
3117 \begin{landscape}
3118 \subsection{The Pythagoras tree using similarity}
3119
3120 Constructing the Pythagoras tree by similarity.
3121 This code is inspired by the construction proposed by MicMath on his Twitch channel.
3122 \begin{multicols}{2}
3123 \begin{mplibcode}
3124 input exemples/transformations/arbrePythagore-en.mp;
3125 \end{mplibcode}
3126
3127 \lstinputlisting[basicstyle=\ttfamily\scriptsize]{exemples/transformations/arbrePythagore-en.mp}
3128 \end{multicols}
3129 \end{landscape}
3130
3131 \newpage
3132
3133 \section{Historique}
3134 \begin{description}
3135 \item[december 2025:] Added the \lstinline+EndWindow+ macro, added the
3136 center-based similarity macros \lstinline+CenterSimilarity+, added the
3137 “Pythagoras Tree” example, fixed bugs, and improved the documentation.
3138 Use of \lstinline+withtransparency+ for the command \lstinline+gddAlphaFill+ when \mpgeomdd is used with \hologo{LuaTeX} and \package{luamplib}.Version 1.4.
3139 \item[may 2025:] translation into English of macros, documentation and examples.
3140 \end{description}
3141
3142 \printbibliography
3143 \addcontentsline{toc}{section}{Références}%Including it as a chapter
3144 \printindex
3145 \addcontentsline{toc}{section}{Index}%Including it as a chapter
3146
3147
3148 \end{document}