
%! TEX root
\documentclass[a4paper,english]{article}
\input{mp-geom2d-doc-preamb.tex}

\begin{document}
%% === Page de garde ===================================================
\thispagestyle{empty}
\begin{tikzpicture}[remember picture, overlay]
 \node[below right, shift={(-4pt,4pt)}] at (current page.north west) {%
   \includegraphics{fond.pdf}%
 };
\end{tikzpicture}%

\noindent
{\includegraphics{mp-geom2d}\\
\Large \MP{} package for plane geometry figures}\\[1cm]
\parbox{0.5\textwidth}{
\includegraphics[scale=0.86]{figure.pdf}
}\hfill
\parbox{0.5\textwidth}{\Large\raggedleft
   \textbf{Contributors}\\
   Maxime \textsc{Chupin}\\
   Jean-Michel \textsc{Sarlat}
}
\vfill
\begin{center}
Version \gddVersion\ from \printdate{\gddDate} \\
\url{https://gitlab.gutenberg-asso.fr/mchupin/mp-geom2d}\\
\url{https://ctan.org/pkg/mp-geom2d}
\end{center}
%% == Page de garde ====================================================
\newpage

\tableofcontents

\section{Objectif}

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:
\begin{quote}\itshape
Let \(A\) be the point with coordinates (2,3).\\
Let \(B\) be the point with coordinates (4,5).\\
Draw the line \((A,B)\).\\
....
\end{quote}
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.

\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...
\end{Note}


\section{Files}

The \mpgeomdd package is a set of tools for plane geometry with
\MP~\cite{ctan-metapost}. This 
set is organized into several files:

\begin{enumerate}
\item \fichier{geom2d.mp} : this is the main file, which loads all the
others;
\item \fichier{geom2d-main.mp} : contains
    the general structures and functions;
\item \fichier{geom2d-arc.mp} :
    contains everything related to circle arcs;
\item \fichier{geom2d-c2d.mp} :
    contains everything related to second-degree curves;
\item \fichier{geom2d-fct.mp} :
    contains some usual mathematical functions;
\item \fichier{geom2d-lbl.mp} :
    contains functions related to labels;
\item \fichier{geom2d-plt.mp} :
    contains functions facilitating the representation of mathematical
    functions;
\item \fichier{geom2d-rep.mp}
    contains various tools for drawing figures in a coordinate system;
\item \fichier{geom2d-tra.mp}
    contains functions for managing transparency (code
    borrowed from Anthony Phan);
\item \fichier{geom2d-svgnames.mp} provides the 150 colors of the SVG specification.
\end{enumerate}

In the following sections, we will describe each of these
functions in more detail. Some functions rely on
the \fichier{graph.mp} extension, which is included in all good
\TeX distributions.

\section{General Operating Principle}

\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[]}.

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).

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.

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.


\section{Drawing}

\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.

To understand how representations work with \mpgeomdd, we first need to describe the unit management mechanism.

\subsection{Unit}

\mpgeomdd defines a general unit with the global variable \lstinline+gddU+. This \typeMP{numeric} is by default \SI{1}{cm}.
\begin{colourband}
    \macro|gddU|
    \index{gddU@\lstinline+gddU+}
\end{colourband}

\subsection{In Place}

When using the drawing commands, \mpgeomdd uses the macro\label{gddEnPlace}
\begin{colourband}
\macro|gddInPlace|
\index{gddInPlace@\lstinline+gddInPlace+}
\end{colourband}
This macro specifies the necessary geometric transformations for placing the object, particularly the scaling factor relative to the \lstinline+gddU+ unit.

Internally, this macro is a \lstinline+scantoken+ of the global variable \variableGDD{gddW}\index{gddW@\lstinline+gddW+} (\typeMP{string}) which contains the transformations.

\subsection{Drawing Commands}\label{sec:trace}

The most common drawing macro is the \lstinline+trace+ macro.
\begin{colourband}
\macro|gddDraw(«object»)|
\begin{description}
  \item[\meta{object}:] 
  \begin{itemize}
    \item for the \MP{} side, a \typeMP{path}, a
  \typeMP{picture} or a \typeMP{pair}, in which case \lstinline+gddDraw+ will be
  equivalent to \lstinline+draw+;
    \item for the \mpgeomdd side,
  any of the 6 objects defined so far: \typeGDD{triangle},
  \typeGDD{segment}, \typeGDD{droite}, \typeGDD{cercle}, \typeGDD{ellipse},
  \typeGDD{parabole}, \typeGDD{hyperbole},
  \typeGDD{polygone}, \typeGDD{chemin},
  \typeGDD{courbe} or \typeGDD{vecteur} (for the latter, an arrow will be
  added to the end of the vector).
  \end{itemize}
\end{description}\index{gddDraw@\lstinline+gddDraw+}
\end{colourband}

When \lstinline+gddDraw+ is used on an \mpgeomdd object, the macro calls the \MP{} command \lstinline+draw+ with the placement mechanism described above.

\mpgeomdd provides a drawing with an arrow that no longer calls \lstinline+draw+
but \lstinline+drawarrow+.

\begin{colourband}
\macro|gddArrow(«object»)|
\begin{description}
  \item[\meta{object}:] 
  \begin{itemize}
    \item for the \MP{} side, a \typeMP{path}, a
  \typeMP{picture}, or a \typeMP{pair}, in which case \lstinline+trace+ will be
  equivalent to \lstinline+drawarrow+;
    \item for the \mpgeomdd side,
  any of the 6 objects defined so far: \typeGDD{triangle},
  \typeGDD{segment}, \typeGDD{droite}, \typeGDD{cercle}, \typeGDD{ellipse},
  \typeGDD{polygone}, \typeGDD{chemin},
  \typeGDD{courbe}, or \typeGDD{vecteur} (for the latter, an arrow will be
  added to the end of the vector).
  \end{itemize}
\end{description}\index{gddArrow@\lstinline+gddArrow+}
\end{colourband}

You can also color an object using the following macro.
\begin{colourband}
\macro|gddFill(«object»)|
\begin{description}
  \item[\meta{object}:] can be:
  \begin{itemize}
    \item for the \MP{} side, only a \typeMP{path} and in this case \lstinline+trace+ will be equivalent to \lstinline+fill+;
    \item for the \mpgeomdd side,
  any colorable object: \typeGDD{triangle},
   \typeGDD{cercle}, \typeGDD{ellipse}, \typeGDD{polygone}, \typeGDD{chemin}, or
  \typeGDD{courbe}.
  \end{itemize}
\end{description}\index{gddFill@\lstinline+gddFill+}
\end{colourband}


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.


You can also color with transparency with the following command.
\begin{colourband}
\macro|gddAlphaFill(«object»,«color»,«transparency coefficient»)|
\begin{description}
  \item[\meta{object}:] can be:
  \begin{itemize}
    \item for the \MP{} side, only a \typeMP{path} and in this case \lstinline+trace+ will be equivalent to \lstinline+fill+;
    \item for the \mpgeomdd side,
  any colorable object: \typeGDD{triangle},
   \typeGDD{cercle}, \typeGDD{ellipse}, \typeGDD{polygone}, \typeGDD{chemin}, or
  \typeGDD{courbe}.
  \end{itemize}
  \item[\meta{color}:] is a \typeMP{color}.
  \item[\meta{transparency coefficient}:] is a \typeMP{numeric} between 0 and 1, 0 for opaque coloring and 1 for invisible coloring.
\end{description}\index{gddAlphaFill@\lstinline+gddAlphaFill+}
\end{colourband}

In fact, with a classic use, transparency is simulated using code borrowed from Anthony Phan:
http://www-math.univ-poitiers.fr/~phan/metalpha.html
.
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.

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:

\begin{colourband}
\macro|gddHatch(«object»,«angle»,«spacing»,«type»)|\return{\typeMP{image}}
\begin{description}
  \item[\meta{object}:] can be:
  \begin{itemize}
    \item for the \MP{} side, only a \typeMP{path} and in this case \lstinline+trace+ will be equivalent to \lstinline+fill+;
    \item for the \mpgeomdd side,
  any colorable object: \typeGDD{triangle},
   \typeGDD{cercle}, \typeGDD{ellipse}, \typeGDD{polygone}, \typeGDD{chemin}, or
  \typeGDD{courbe}.
  \end{itemize}
  \item[\meta{angle}:] is the angle (\typeMP{numeric} in degrees) of the hatching lines.
  \item[\meta{spacing}:] is the space (\typeMP{numeric}) between each hatching line (in the unit of \mpgeomdd, so no unit should be specified).
  \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.
\end{description}\index{gddHatch@\lstinline+gddHatch+}
\end{colourband}

Note that the \lstinline+gddHatch+ macro returns an \typeMP{image}, so it should be
used in conjunction with the \lstinline+gddDraw+ macro.

To use the fourth type of line for hatching, you need to define its pattern using the following command:

\begin{colourband}
\macro|HatchPattern(«pattern»)|
\begin{description}
  \item[\meta{pattern}:] is the pattern that you would typically provide to the
  \lstinline+dashpattern+ command. We refer you to the \MP{} documentation. Note
  that the dimensions provided to the \lstinline+on+ and \lstinline+off+ commands
  will be scaled to the \lstinline+gddU+ unit of \mpgeomdd. Therefore, they should
  be considered as expressed in the \mpgeomdd unit.
\end{description}\index{HatchPattern@\lstinline+HatchPattern+}
\end{colourband}

Below, we illustrate some commands for drawing, coloring, and hatching.

\begin{ExempleMP}
input geom2d;

beginfig(1);
gddU:=0.6cm;
A = Point(-1,1); B = Point(3,2);
C1= Circle(origine,2);
C2 = Circle(A,2); C3 = Circle(B,3);

gddFill C1 withcolor LightCyan;
gddAlphaFill(C2,DarkRed,0.2);
gddAlphaFill(C3,DarkBlue,0.2);

T1 = Triangle((-1,-2),(2,-2),(0.2,1));
gddDraw gddHatch(T1,45,0.2,0) withPen(0.6,DarkRed);
gddDraw T1;
pE1 = Point(-2,-3); 
pE2 = Point(3,-4); 
E = EllipseF(pE1,pE2,3.9);
HatchPattern(on0.2 off0.3);
gddDraw gddHatch(E,-20,0.1,4);
gddDraw E;
gddDrawPoint pE1; gddDrawPoint pE2;
endfig;
\end{ExempleMP}


The above macros call a lower-level macro that returns the \typeMP{path} to be drawn or colored for all \mpgeomdd objects.

\begin{colourband}
\macro|gddObjectDrawing(«object»)|\return{\typeMP{path}}
\begin{description}
  \item[\meta{object}:]
   \typeGDD{triangle}, \typeGDD{segment}, \typeGDD{vecteur},
   \typeGDD{cercle}, \typeGDD{ellipse}, \typeGDD{parabole}, \typeGDD{hyperbole},\typeGDD{polygone}, \typeGDD{chemin}, or
  \typeGDD{courbe}.
\end{description}\index{gddObjectDrawing@\lstinline+gddObjectDrawing+}
\end{colourband}

If the object is not closed, \mpgeomdd provides the following macro that adds a
\lstinline+--cycle+ to the end of the path:
\begin{colourband}
\macro|gddClose(«object»)|\return{\typeMP{path}}\indication{closed with \lstinline+--cycle+}
\begin{description}
  \item[\meta{object}:]
  \begin{itemize}
    \item on the \MP side, \typeMP{path};
    \item on the \mpgeomdd side, \typeGDD{triangle}, \typeGDD{segment}, \typeGDD{vecteur},
   \typeGDD{cercle}, \typeGDD{chemin}, or
  \typeGDD{courbe}.
  \end{itemize}
\end{description}\index{gddClose@\lstinline+gddClose+}
\end{colourband}

You can specify the \emph{pen} used for drawings with the following command:

\begin{colourband}
  \macro|withPen(«size»,«color»)|
  \begin{description}
    \item[\meta{size}:] scaling factor (\typeMP{numeric}) of the \typeMP{pen}
    \lstinline+pencircle+ of \MP{};
    \item[\meta{color}:] color \typeMP{color} to use.
  \end{description}\index{withPen@\lstinline+withPen+}
\end{colourband}
  
This macro is a shortcut for the \emph{classic} \texttt{withpen
pencircle scaled ... withcolor ...}. You can, of course, always use the \MP{} commands for drawing.



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:

\begin{colourband}
\macro|gddDrawPoint(«point»)|
\begin{description}
  \item[\meta{point}:] \typeGDD{point} or \typeMP{pair}
\end{description}\index{gddDrawPoint@\lstinline+gddDrawPoint+}
\end{colourband}

This macro uses three internal parameters of \mpgeomdd for the size, color, and type of mark used
(\lstinline+gddTaillePoint+\index{gddTaillePoint@\lstinline+gddTaillePoint+}, \lstinline+gddCouleurPoint+\index{gddCouleurPoint@\lstinline+gddCouleurPoint+}
and \lstinline+gddPointeType+  \index{gddPointeType@\lstinline+gddPointeType+}
). These parameters can be modified with the following commands:
\begin{colourband}
\macro|SetPointSize(«n»)|
\begin{description}
  \item[\meta{n}:] \typeMP{numeric}, default value 3.
\end{description}
\index{SetPointSize@\lstinline+SetPointSize+}
\end{colourband}

\begin{colourband}
\macro|SetPointColor(«c»)| 
\begin{description}
  \item[\meta{c}:] \typeMP{color}, default value \lstinline+white+.
\end{description}
\index{SetPointColor@\lstinline+SetPointColor+}
\end{colourband}

There are two other types of point marking: the cross and the disk. To choose
another type of marking (using the same \lstinline+gddDrawPoint+ command), you
can use the following macro:
\begin{colourband}
  \macro|SetPointType(«s»)|
  \begin{description}
  \item[\meta{s}:] \typeMP{string}, can be \lstinline+"pointe"+
    (default behavior with a black circle filled with another color,
    white by default), \lstinline+"croix"+ (for a simple cross), or
    \lstinline+"disque"+ (for a solid disk).
  \end{description} 
  \index{SetPointType@\lstinline+SetPointType+}
\end{colourband}

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:

\begin{colourband}
\macro|gddDrawPoints(«pointA», «pointB», «pointC», etc.)|
\begin{description}
  \item[\meta{pointA}, \meta{pointB}, etc.:] list of \typeGDD{point} or
  \typeMP{pair} separated by commas.
\end{description}\index{gddDrawPoints@\lstinline+gddDrawPoints+}
\end{colourband}

\subsection{Clipping the drawings}

It is often necessary to restrict the drawings to a specific area of the plane $\R^2$.
For this, \mpgeomdd provides the command \lstinline+Window+:
\begin{colourband}
\macro|Window(«Xmin»,«Ymin»,«Xmax»,«Ymax»)|
\index{Window@\lstinline+Window+}
\end{colourband}
This function draws a rectangle with two opposite vertices at the points
\lstinline|(Xmin,Ymin)| and \lstinline|(Xmax,Ymax)| with the \MP{} color
\lstinline+background+ and clips the current picture around this frame (using the
\MP{} command \lstinline+clip currentpicture+).


You can also restrict drawings to the interior of a closed path derived from an \mpgeomdd object. To do this, use the following command:
\begin{colourband}
\macro|gddClip(«object»)|
\begin{description}
  \item[\meta{object}:] any \mpgeomdd \enquote{closed} object.
\end{description}
\index{gddClip@\lstinline+gddClip+}
\end{colourband}

Internally, the macro \lstinline|Window| modifies the
\hologo{MetaPost}\lstinline+extra_endfig+ variable.
To clear this character string, you can use the following command:
\begin{colourband}
\macro|EndWindow|
\index{EndWindow@\lstinline+EndWindow+}
\end{colourband}

\section{Types}\label{sec:types}

\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.

Here, we will describe each type of the \mpgeomdd extension, their respective properties, as well as methods directly associated with the object.

\subsection{The \typeGDD{point} type}

This type corresponds to a point in Euclidean space.

\subsubsection{Constructor}

To be clearer, here is the main function to create such an object:
%
\begin{mpcode}
vardef Point(expr a,b) =
  gddT[incr gddO] = "point";
  gddA[gddO] = a; gddB[gddO] = b; gddO
enddef;
\end{mpcode}

\begin{colourband}
\macro|Point(«x»,«y»)|\return{\typeGDD{point}}
\begin{description}
  \item[\meta{x}:] \typeMP{numeric};
  \item[\meta{y}:] \typeMP{numeric}.
\end{description}\index{Point@\lstinline+Point+}
\end{colourband}
\bigskip


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}.

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
\begin{mpcode}
A = Point(2,3);
\end{mpcode}
\variableGDD{A} then takes the current value of \variableGDD{gddO}. This is the identifier of the point.

A \typeGDD{point} can also be defined by its \emph{polar} coordinates with the following command.

\begin{colourband}
\macro|PolarPoint(«r»,«a»)|\return{\typeGDD{point}}
\begin{description}
  \item[\meta{r}:] \typeMP{numeric}, modulus of the point;
  \item[\meta{a}:] \typeMP{numeric}, angle with respect to the x-axis.
\end{description}\index{PolarPoint@\lstinline+PolarPoint+}
\end{colourband}
\bigskip

You can define a point in a coordinate system defined by an origin point and two vectors with the following function:
\begin{colourband}
\macro|PointInBasis(«x»,«y»,«o»,«i»,«j»)|\return{\typeGDD{point}}
\begin{description}
  \item[\meta{x}:] \typeMP{numeric} ;
  \item[\meta{y}:] \typeMP{numeric} ;
  \item[\meta{o}:] \typeGDD{point} origin of the coordinate system ;
  \item[\meta{i}:] \typeGDD{vecteur} (or \typeGDD{point}) defining the x-axis ;
  \item[\meta{j}:] \typeGDD{vecteur} (or \typeGDD{point}) defining the y-axis.
\end{description}\index{PointInBasis@\lstinline+PointInBasis+}
\end{colourband}

\bigskip

The following code illustrates the use of this command (with \typeGDD{point}s instead of \typeGDD{vecteur}s, type described later). 
\begin{mpcode}
O = Point(0,0);
I = Point(2,0);
J = PolarPoint(2,Pi/2);
A = PointInBasis(2,3,O,I,J);
\end{mpcode}

\subsubsection{Associated Macros}

You can retrieve the x-coordinate and y-coordinate of a point with the following commands:
\begin{colourband}
\macro|Xcoordinate(«a»)|\return{\typeMP{numeric}}
\begin{description}
  \item[\meta{a}:] \typeGDD{point}, \typeGDD{vecteur} or \typeMP{pair}.
\end{description}\index{Xcoordinate@\lstinline+Xcoordinate+}
\end{colourband}

\begin{colourband}
\macro|Ycoordinate(«a»)|\return{\typeMP{numeric}}
\begin{description}
  \item[\meta{a}:] \typeGDD{point}, \typeGDD{vecteur} or \typeMP{pair}.
\end{description}\index{Ycoordinate@\lstinline+Ycoordinate+}
\end{colourband}

You can add the x-coordinates, the y-coordinates, or, like vectors, points together with the following commands.
\begin{colourband}
\macro|XcoordinateSum(«a»,«b»)|\return{\typeMP{numeric}}
\begin{description}
  \item[\meta{a}:] \typeGDD{point} or \typeMP{pair};
  \item[\meta{b}:] \typeGDD{point} or \typeMP{pair}.
\end{description}\index{XcoordinateSum@\lstinline+XcoordinateSum+}
\end{colourband}
\begin{colourband}
\macro|YcoordinateSum(«a»,«b»)|\return{\typeMP{numeric}}
\begin{description}
  \item[\meta{a}:] \typeGDD{point} or \typeMP{pair};
  \item[\meta{b}:] \typeGDD{point} or \typeMP{pair}.
\end{description}\index{YcoordinateSum@\lstinline+YcoordinateSum+}
\end{colourband}
and
\begin{colourband}
\macro|PointSum(«a»,«b»)|\return{\typeGDD{point}}
\begin{description}
  \item[\meta{a}:] \typeGDD{point} or \typeMP{pair};
  \item[\meta{b}:] \typeGDD{point} or \typeMP{pair}.
\end{description}\index{PointSum@\lstinline+PointSum+}
\end{colourband}

You can also calculate the distance between two points using the following command:
\begin{colourband}
\macro|Length(«a»,«b»)|\return{\typeMP{numeric}}
\begin{description}
  \item[\meta{a}:] \typeGDD{point} or \typeMP{pair};
  \item[\meta{b}:] \typeGDD{point} or \typeMP{pair}.
\end{description}\index{Length@\lstinline+Length+}
\end{colourband}

You can calculate the midpoint between two points:
\begin{colourband}
\macro|MidPoint(«a»,«b»)|\return{\typeGDD{point}}
\begin{description}
  \item[\meta{a}:] \typeGDD{point} or \typeMP{pair};
  \item[\meta{b}:] \typeGDD{point} or \typeMP{pair}.
\end{description}\index{MidPoint@\lstinline+MidPoint+}
\end{colourband}

You can perform the rotation of a point around the origin $(0,0)$ with the following command:
\begin{colourband}
\macro|Rotation(«a»,«b»)|\return{\typeGDD{point}}
\begin{description}
  \item[\meta{a}:] \typeGDD{point} or \typeMP{pair};
  \item[\meta{b}:] \typeMP{numeric}, the angle of rotation in radians.
\end{description}\index{Rotation@\lstinline+Rotation+}
\end{colourband}

If you want to rotate a point around another point, you will use the following command:
\begin{colourband}
\macro|CenterRotation(«a»,«b»,«c»)|\return{\typeGDD{point}}
\begin{description}
  \item[\meta{a}:] \typeGDD{point} or \typeMP{pair};
  \item[\meta{b}:] \typeGDD{point} or \typeMP{pair}, center of rotation;
  \item[\meta{c}:] \typeMP{numeric}, the angle of rotation in radians.
\end{description}\index{CenterRotation@\lstinline+CenterRotation+}
\end{colourband}

We can calculate the isobarycenter of a list of points (or \typeMP{pair} of \MP) with the following command.
\begin{colourband}
\macro|IsoBarycenter(«a»,«b»,«c», etc.)|\return{\typeGDD{point}}
\begin{description}
  \item[\meta{a}:] \typeGDD{point} or \typeMP{pair};
  \item[\meta{b}:] \typeGDD{point} or \typeMP{pair};
  \item[] etc.
\end{description}\index{IsoBarycenter@\lstinline+IsoBarycenter+}
\end{colourband}

We can calculate the barycenter of a list of points associated with weights (but
here, it is not possible to use \MP{} \typeMP{pair}s).
\begin{colourband}
\macro|Barycenter((«A»,«a»),(«B»,«b»),(«C»,«c»), etc.)|\return{\typeGDD{point}}
\begin{description}
  \item[\meta{A}:] \typeGDD{point} ;
  \item[\meta{a}:] \typeMP{numeric}, weight associated with \meta{A} ;
  \item[\meta{B}:] \typeGDD{point} ;
  \item[\meta{b}:] \typeMP{numeric}, weight associated with \meta{B} ;
  \item[] etc.
\end{description}\index{Barycenter@\lstinline+Barycenter+}
\end{colourband}


You can determine the bisector of an angular sector defined by three points. The function returns a \typeGDD{droite}.
\begin{colourband}
\macro|AngleBisector(«A»,«B»,«C»)|\return{\typeGDD{droite}}
\begin{description}
  \item[\meta{A}:] \typeGDD{point} ;
  \item[\meta{B}:] \typeGDD{point} ;
  \item[\meta{C}:] \typeGDD{point}.
\end{description}\index{AngleBisector@\lstinline+AngleBisector+}
\end{colourband}

\begin{ExempleMP}
input geom2d;
beginfig(1);
A = Point(1,0);
B = Point(0,0);
C = Point(1,1);
D = AngleBisector(A,B,C);
gddDraw D;
gddMark.bot "A";
gddMark.bot "B";
gddMark.bot "C";
Window(-0.5,-0.5,2,2);
endfig;
\end{ExempleMP}


The \typeGDD{point} type is obviously related to the \MP{} \typeMP{pair} type.

\mpgeomdd provides macros that allow converting from \typeGDD{point} to
\typeMP{pair} and vice versa.
\begin{colourband}
\macro|PointTOPair(«a»,«b»)|\return{\typeMP{pair}}
\begin{description}
  \item[\meta{a}:] \typeMP{numeric}, x-coordinate;
  \item[\meta{b}:] \typeMP{numeric}, y-coordinate.
\end{description}\index{PointTOPair@\lstinline+PointTOPair+}
\end{colourband}

\begin{colourband}
\macro|PairTOPoint(«p»)|\return{\typeGDD{point}}
\begin{description}
  \item[\meta{p}:] \typeMP{pair}.
\end{description}\index{PairTOPoint@\lstinline+PairTOPoint+}
\end{colourband}

These two commands are complemented by two others that ensure an element is of a given type:
\begin{colourband}
\macro|PairImp(«p»)|\return{\typeGDD{pair}}
\begin{description}
  \item[\meta{p}:] \typeGDD{point} or \typeMP{pair}.
\end{description}\index{PairImp@\lstinline+PairImp+}
\end{colourband}


\begin{colourband}
\macro|PointImp(«p»)|\return{\typeGDD{point}}
\begin{description}
  \item[\meta{p}:] \typeGDD{point} or \typeMP{pair}.
\end{description}\index{PointImp@\lstinline+PointImp+}
\end{colourband}

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.

\begin{colourband}
\macro|PointOf(«o»,«t»)|\return{\typeGDD{point}}
\begin{description}
  \item[\meta{o}:] any \mpgeomdd object (even a \typeGDD{point} for which it returns itself);
  \item[\meta{t}:] \typeMP{numeric} between 0 and 1 (which parameterizes the object's path between 0 and 1).
\end{description}\index{PointOf@\lstinline+PointOf+}
\end{colourband}


\subsection{The \typeGDD{vecteur} type}

This type corresponds to vectors defined using two coordinates in Euclidean space.

\subsubsection{Constructors}

The constructor function for such an object is:
%
\begin{mpcode}
vardef Vector(expr a,b) =
  save n; n = incr gddO;
  gddT[n] = "vecteur"; gddA[n] = a; gddB[n] = b; n
enddef;
\end{mpcode}

\begin{colourband}
\macro|Vector(«a»,«b»)|\return{\typeGDD{vecteur}}
\begin{description}
  \item[\meta{a}:] \typeMP{numeric} ;
  \item[\meta{b}:] \typeMP{numeric}.
\end{description}\index{Vector@\lstinline+Vector+}
\end{colourband}
\bigskip

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.

A vector can also be defined from an \typeMP{pair} in \MP.
\begin{mpcode}
vardef VectorP(expr a) =
  save n; n = incr gddO;
  gddT[n] = "vecteur"; gddA[n] = xpart a; gddB[n] = ypart a; n
enddef;
\end{mpcode}

\begin{colourband}
\macro|VectorP(«a»)|\return{\typeGDD{vecteur}}
\begin{description}
  \item[\meta{a}:] \typeMP{pair}.
\end{description}\index{VectorP@\lstinline+VectorP+}
\end{colourband}
\bigskip

A vector can then be defined as follows:
\begin{ExempleMP}
input geom2d;
beginfig(1);
AB = Vector(2,3);
pair a;
a := (3,2);
A = VectorP(a);
gddDraw AB;
gddDraw A;
endfig;
\end{ExempleMP}

\subsubsection{Associated Macros}

Since \mpgeomdd objects are \typeMP{numeric}s, the classic operations of the
vector space cannot be written with the simple characters \lstinline-+-,
\lstinline+-+, and \lstinline-*-. 

\begin{colourband}
\macro|VectorSum(«a»,«b»)|\return{\typeGDD{vecteur}}
\begin{description}
  \item[\meta{a}:] \typeGDD{vecteur} ;
  \item[\meta{b}:] \typeGDD{vecteur}.
\end{description}\index{VectorSum@\lstinline+VectorSum+}
\end{colourband}
\bigskip


\begin{colourband}
\macro|VectorSubstract(«a»,«b»)|\return{\typeGDD{vecteur}}
\begin{description}
  \item[\meta{a}:] \typeGDD{vecteur} ;
  \item[\meta{b}:] \typeGDD{vecteur}.
\end{description}\index{VectorSubstract@\lstinline+VectorSubstract+}
\end{colourband}
\bigskip


\begin{colourband}
\macro|ScalarVector(«k»,«b»)|\return{\typeGDD{vecteur}}
\begin{description}
  \item[\meta{k}:] \typeMP{numeric} ;
  \item[\meta{b}:] \typeGDD{vecteur}.
\end{description}\index{ScalarVector@\lstinline+ScalarVector+}
\end{colourband}
\bigskip

We can then perform the classic operations on vectors.

\begin{ExempleMP}
input geom2d;
beginfig(1);
AB = Vector(2,3);
BC = Vector(1,0);
AC = VectorSum(AB,BC);
kAC = ScalarVector(3.0,AC);
gddDraw AB;
gddDraw BC;
gddDraw AC;
endfig;
\end{ExempleMP}

We can also calculate the dot product of two vectors with the following command.

\begin{colourband}
\macro|ScalarProduct(«a»,«b»)|\return{\typeMP{numeric}}
\begin{description}
  \item[\meta{a}:] \typeGDD{vecteur} ;
  \item[\meta{b}:] \typeGDD{vecteur}.
\end{description}\index{ScalarProduct@\lstinline+ScalarProduct+}
\end{colourband}
\bigskip

We can also calculate the Euclidean norm of a vector.
\begin{colourband}
\macro|Norm(«a»)|\return{\typeMP{numeric}}
\begin{description}
  \item[\meta{a}:] \typeGDD{vecteur}.
\end{description}\index{Norm@\lstinline+Norm+}
\end{colourband}
\bigskip

The following command returns the angle, in radians, between $[0,\uppi]$ formed
between two vectors. If we denote $u$ and $v$ as the two vectors in $\R^2$, the angle
calculated
\[\theta = \arccos \left(\frac{u\cdot v}{\|u\|\|v\|}\right).\]

\begin{colourband}
\macro|AngleBetweenVectors(«a»,«b»)|\return{\typeMP{numeric} (dans $[0,\uppi]$)}
\begin{description}
  \item[\meta{a}:] \typeGDD{vecteur} ;
  \item[\meta{b}:] \typeGDD{vecteur}.
\end{description}\index{AngleBetweenVectors@\lstinline+AngleBetweenVectors+}
\end{colourband}
\bigskip


\subsection{The \typeGDD{segment} type}
Segments are defined by two points in $\R^2$.

\subsubsection{Constructor}
The constructor function for this object is:
\begin{mpcode}
vardef Segment (expr a,b) =
  save n; n = incr gddO;
  gddT[n] = "segment"; gddA[n] = PointImp(a); gddB[n] = PointImp(b); n
enddef;
\end{mpcode}

\begin{colourband}
\macro|Segment(«a»,«b»)|\return{\typeGDD{segment}}
\begin{description}
  \item[\meta{a}:]  \typeGDD{point} ;
  \item[\meta{b}:]  \typeGDD{point}.
\end{description}\index{Segment@\lstinline+Segment+}
\end{colourband}

\bigskip

A segment is then defined as follows:
\begin{ExempleMP}
input geom2d;
beginfig(1);
A = Point(2,3);
B = Point(4,5);
C = Point(2,1);
AB = Segment(A,B);
BC = Segment(B,C);
AC = Segment(A,C);
gddArrow AB;
gddArrow BC;
gddArrow AC;
endfig;
\end{ExempleMP}

\subsubsection{Associated Macros}

You can calculate the length of a segment with the following macro.
\begin{colourband}
\macro|SegmentLength(«a»)|\return{\typeMP{numeric}}
\begin{description}
  \item[\meta{a}:]  \typeGDD{segment}.
\end{description}\index{SegmentLength@\lstinline+SegmentLength+}
\end{colourband}

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.
\begin{colourband}
\macro|SegmentTOVector(«a»)|\return{\typeGDD{vecteur}}
\begin{description}
  \item[\meta{a}:]  \typeGDD{segment}.
\end{description}\index{SegmentTOVector@\lstinline+SegmentTOVector+}
\end{colourband}



\subsection{The \typeGDD{droite} type}
A line is simply defined by two points.

\subsubsection{Constructor}

The constructor function for this object is as follows:
\begin{mpcode}
vardef Line (expr a,b) =
  save n; n = incr gddO;
  gddT[n] = "droite"; gddA[n] = PointImp(a); gddB[n] = PointImp(b); n
enddef;
\end{mpcode}
\begin{colourband}
\macro|Line(«a»,«b»)|\return{\typeGDD{droite}}
\begin{description}
  \item[\meta{a}:]  \typeGDD{point} ;
  \item[\meta{b}:]  \typeGDD{point}.
\end{description}\index{Line@\lstinline+Line+}
\end{colourband}
\bigskip


When representing lines (see section~\ref{sec:trace}), the \emph{infinite} nature of the line is managed by the global variable \lstinline+gddExtensionDroite+ 
\index{gddExtensionDroite@\lstinline+gddExtensionDroite+}
which defaults to 10.

You can modify it with the following command:
\begin{colourband}
\macro|SetLineExtension(«d»)|
\begin{description}
  \item[\meta{d}:]  \typeMP{numeric} (default value 10).
\end{description}\index{SetLineExtension@\lstinline+SetLineExtension+}
\end{colourband}
\bigskip


\subsubsection{Associated Macros}

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$.

\begin{colourband}
\macro|LineEquation(«a»)|\return{\typeMP{color}}
\begin{description}
  \item[\meta{a}:]  \typeGDD{droite}.
\end{description}\index{LineEquation@\lstinline+LineEquation+}
\end{colourband}

You can calculate the projection of a point onto a line with the following command.

\begin{colourband}
\macro|PointOnLineProjection(«p»,«a»)|\return{\typeGDD{point}}
\begin{description}
  \item[\meta{p}:] \typeGDD{point} ;
  \item[\meta{a}:]  \typeGDD{droite}.
\end{description}\index{PointOnLineProjection@\lstinline+PointOnLineProjection+}
\end{colourband}

You can obtain the relative distance of a point on a line with the following macro.
\begin{colourband}
\macro|PointLineRelativeDistance(«p»,«a»)|\return{\typeMP{numeric}}
\begin{description}
  \item[\meta{p}:] \typeGDD{point} ;
  \item[\meta{a}:]  \typeGDD{droite}.
\end{description}\index{PointLineRelativeDistance@\lstinline+PointLineRelativeDistance+}
\end{colourband}
The calculation of the distance from a point to a line is done with the following macro.
\begin{colourband}
\macro|PointLineDistance(«p»,«a»)|\return{\typeMP{numeric}}
\begin{description}
  \item[\meta{p}:] \typeGDD{point} ;
  \item[\meta{a}:]  \typeGDD{droite}.
\end{description}\index{PointLineDistance@\lstinline+PointLineDistance+}
\end{colourband}

The following macro allows obtaining the perpendicular line to a given line passing through a point.
\begin{colourband}
\macro|PerpendicularLine(«a»,«p»)|\return{\typeGDD{droite}}
\begin{description}
  \item[\meta{a}:]  \typeGDD{droite} ;
  \item[\meta{p}:] \typeGDD{point}.
\end{description}\index{PerpendicularLine@\lstinline+PerpendicularLine+}
\end{colourband}

Similarly, the following macro allows obtaining the parallel line to another passing through a point.
\begin{colourband}
\macro|ParallelLine(«a»,«p»)|\return{\typeGDD{droite}}
\begin{description}
  \item[\meta{a}:]  \typeGDD{droite} ;
  \item[\meta{p}:] \typeGDD{point}.
\end{description}\index{ParallelLine@\lstinline+ParallelLine+}
\end{colourband}

You can obtain the \typeGDD{point} of intersection of two lines with the
following macro.
\begin{colourband}
\macro|LinesIntersection(«a»,«b»)|\return{\typeGDD{point}}
\begin{description}
  \item[\meta{a}:]  \typeGDD{droite} ;
  \item[\meta{b}:] \typeGDD{droite}.
\end{description}\index{LinesIntersection@\lstinline+LinesIntersection+}
\end{colourband}

The following macro allows you to plot a point on a line with a certain
length (signed), similar to a compass.

\begin{colourband}
\macro|ReportOnLine(«P»,«D»,«l»)|\return{\typeGDD{point}}
\begin{description}
  \item[\meta{P}:]  \typeGDD{point} ;
  \item[\meta{D}:] \typeGDD{droite} ;
  \item[\meta{l}:] \typeMP{numeric} (can be negative).
\end{description}\index{ReportOnLine@\lstinline+ReportOnLine+}
\end{colourband}

The direction of the plot relative to point \meta{P} depends on the definition
of  
the line: for a line defined by two \typeGDD{point}s $A$ and $B$, the direction
of the plot will follow the vector $\overrightarrow{AB}$. To change direction,
simply multiply the distance parameter \meta{l} by $-1$.

Here is an example illustrating the use of some commands related to lines.

\begin{ExempleMP}
input geom2d;
beginfig(1);
A = Point(0,0);
B = Point(3,2);
AB = Line(A,B);
gddDraw AB;
gddDrawPoint A;
gddDrawPoint B;
C = Point(0,2);
DC = PerpendicularLine(AB,C);
gddDraw DC;
gddDrawPoint C;
D = PointOnLineProjection(C,AB);
gddDrawPoint D;
Window(-2,-2,4,4);
endfig;
\end{ExempleMP}



\subsection{The \typeGDD{cercle} type}
A circle could be defined by a point and a radius.

\subsubsection{Constructors}
The basic constructor function for this object is as follows:
\begin{mpcode}
vardef Circle (expr a,b) =
  save n; n = incr gddO;
  gddT[n] = "cercle"; gddA[n] = PointImp(a); gddB[n] = b; n
enddef;
\end{mpcode}
\begin{colourband}
\macro|Circle(«a»,«b»)|\return{\typeGDD{cercle}}
\begin{description}
  \item[\meta{a}:]  \typeGDD{point} or \typeMP{pair},
  center of the circle;
  \item[\meta{b}:] \typeMP{numeric}, radius of the circle.
\end{description}\index{Circle@\lstinline+Circle+}
\end{colourband}
\bigskip

Two other functions allow defining circles. The \foncGDD{CircleCP} function defines the circle by a center and a point through which the circle passes.
\begin{colourband}
\macro|CircleCP(«a»,«b»)|\return{\typeGDD{cercle}}
\begin{description}
  \item[\meta{a}:]  \typeGDD{point} or \typeMP{pair},
  center of the circle;
  \item[\meta{b}:]  \typeGDD{point},
  such that \meta{b}$-$\meta{a} is the radius.
\end{description}\index{CircleCP@\lstinline+CircleCP+}
\end{colourband}
\bigskip

We can also define a circle by two points defining its diameter. The corresponding function is as follows:
\begin{colourband}
\macro|CircleD(«a»,«b»)|\return{\typeGDD{cercle}}
\begin{description}
  \item[\meta{a}:]  \typeGDD{point} or \typeMP{pair} ;
  \item[\meta{b}:]  \typeGDD{point} or \typeMP{pair},
  such that $($\meta{a}$-$\meta{b}$)$ is the diameter of the circle.
\end{description}\index{CircleD@\lstinline+CircleD+}
\end{colourband}
\bigskip

You can also define a circle as the circle passing through three points with
the following macro.

\begin{colourband}
\macro|CircleThreePoints(«a»,«b»,«c»)|\return{\typeGDD{cercle}}
\begin{description}
  \item[\meta{a}:]  \typeGDD{point} ou \typeMP{pair} ;
  \item[\meta{b}:]  \typeGDD{point} ou \typeMP{pair} ;
  \item[\meta{c}:]  \typeGDD{point} ou \typeMP{pair}.
\end{description}\index{CircleThreePoints@\lstinline+CircleThreePoints+}
\end{colourband}
\bigskip



\begin{ExempleMP}
input geom2d;
beginfig(1);
A = Point(3,1);
B = Point(0,2);
O = Point(0,0);
r = 1.0;
COr = Circle(O,r);
COA = CircleCP(O,A);
CAB = CircleD(A,B);
COAB = CircleThreePoints(O,A,B);
gddDraw COr;
gddDraw COA;
gddDraw CAB;
gddDraw COAB;
gddDrawPoint A; gddDrawPoint B; gddDrawPoint O;
endfig;
\end{ExempleMP}

\subsubsection{Associated Macros}

Many macros are associated with circles.

You can retrieve the radius of a circle with the following command.

\begin{colourband}
\macro|Radius(«a»)|\return{\typeMP{numeric}}
\begin{description}
  \item[\meta{a}:]  \typeGDD{cercle}.
\end{description}\index{Radius@\lstinline+Radius+}
\end{colourband}
\bigskip

You can obtain the center (\typeGDD{point}) of a circle with the following command:
\begin{colourband}
\macro|Center(«a»)|\return{\typeGDD{point}}
\begin{description}
  \item[\meta{a}:]  \typeGDD{cercle}, \typeGDD{ellipse} or \typeGDD{hyperbole}.
\end{description}\index{Center@\lstinline+Center+}
\end{colourband}
\bigskip

We can compute the intersection between two circles using the following macro.

\begin{colourband}
\macro|CirclesIntersection(«a»,«b»)|\return{\typeGDD{point}}
\begin{description}
  \item[\meta{a}:]  \typeGDD{cercle} ;
  \item[\meta{b}:]  \typeGDD{cercle}.
\end{description}\index{CirclesIntersectionCercle@\lstinline+CirclesIntersection+}
\end{colourband}
\bigskip

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.

\begin{ExempleMP}
input geom2d;
beginfig(1);
A = Point(0,0);
CA = Circle(A,1);
B = Point(1.5,0);
CB = Circle(B,2);
D1 = CirclesIntersection(CA,CB);
D2 = CirclesIntersection(CB,CA);
gddDraw CA; gddDraw CB;
gddDrawPoint A; gddDrawPoint B; gddDrawPoint D1; gddDrawPoint D2;
endfig;
\end{ExempleMP}

If there is no intersection, the compilation will fail with the error
\texttt{! Pythagorean subtraction X.XXXX+-+X.XXXX has been replaced by 0}. If
the two circles are coincident, the error will be \texttt{! Division by zero.}.

\mpgeomdd also provides a macro to obtain the intersections between a
line and a circle.

\begin{colourband}
\macro|LineCircleIntersection(«d»,«c»,«n»)|\return{\typeGDD{point}}
\begin{description}
  \item[\meta{d}:]  \typeGDD{line} ;
  \item[\meta{c}:]  \typeGDD{circle} ;
  \item[\meta{n}:] \typeMP{numeric} which is 1 or 2 depending on the intersection
  point desired (if there is only one intersection point, both values return the same point).
\end{description}\index{LineCircleIntersection@\lstinline+LineCircleIntersection+}
\end{colourband}
\bigskip

If there is no intersection between the line and the circle, you will get
the error \texttt{! Intersection between line and circle does not exist}.

The following example illustrates this macro.
\begin{ExempleMP}
input geom2d;
beginfig(1);
A = Point(2,2);
C_A = Circle(A,1);
B = Point(0,1);
C = Point(4,2);
BC = Line(B,C);
E1 = LineCircleIntersection(BC,C_A,1);
gddDraw C_A;
gddDraw BC dashed evenly;
gddDrawPoint A; gddDrawPoint B; gddDrawPoint C; gddDrawPoint E1;
Window(-0.5,-0.5,5,4);
endfig;
\end{ExempleMP}


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.

\begin{colourband}
\macro|ExternalCommonTangent(«a»,«b»)|\return{\typeGDD{droite}}
\begin{description}
  \item[\meta{a}:]  \typeGDD{cercle} ;
  \item[\meta{b}:]  \typeGDD{cercle}.
\end{description}\index{ExternalCommonTangent@\lstinline+ExternalCommonTangent+}
\end{colourband}
\bigskip


\begin{colourband}
\macro|InternalCommonTangent(«a»,«b»)|\return{\typeGDD{droite}}
\begin{description}
  \item[\meta{a}:]  \typeGDD{cercle} ;
  \item[\meta{b}:]  \typeGDD{cercle}.
\end{description}\index{InternalCommonTangent@\lstinline+InternalCommonTangent+}
\end{colourband}
\bigskip


The following example illustrates the use of these two macros.
\begin{ExempleMP}[sidebyside=false]
input geom2d;
beginfig(1);
C1 = Circle((-2,0),2);
C2 = Circle((1.5,0),1);
T1 = ExternalCommonTangent(C1,C2);
T2 = ExternalCommonTangent(C2,C1);
T3 = InternalCommonTangent(C1,C2);
T4 = InternalCommonTangent(C2,C1);
gddDraw C1; gddDraw C2;
gddDraw T1; gddDraw T2;
gddDraw T3; gddDraw T4;

Window(-5,-3,6,3);
endfig;
\end{ExempleMP}

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}.}.
\begin{colourband}
\macro|RadicalAxis(«a»,«b»)|\return{\typeGDD{droite}}
\begin{description}
  \item[\meta{a}:]  \typeGDD{cercle} ;
  \item[\meta{b}:]  \typeGDD{cercle}.
\end{description}\index{RadicalAxis@\lstinline+RadicalAxes+}
\end{colourband}
\bigskip

The following macro calculates the radical center of three circles.
\begin{colourband}
\macro|RadicalCenter(«a»,«b»,«c»)|\return{\typeGDD{point}}
\begin{description}
  \item[\meta{a}:]  \typeGDD{cercle} ;
  \item[\meta{b}:]  \typeGDD{cercle} ;
  \item[\meta{c}:]  \typeGDD{cercle}.
\end{description}\index{RadicalCenter@\lstinline+RadicalCenter+}
\end{colourband}
\bigskip

The following macro calculates the axis of similarity of three circles.
\begin{colourband}
\macro|AxisOfSimilitude(«a»,«b»,«c»)|\return{\typeGDD{droite}}
\begin{description}
  \item[\meta{a}:]  \typeGDD{cercle} ;
  \item[\meta{b}:]  \typeGDD{cercle} ;
  \item[\meta{c}:]  \typeGDD{cercle}.
\end{description}\index{AxisOfSimilitude@\lstinline+AxisOfSimilitude+}
\end{colourband}
\bigskip

\subsection{The \typeGDD{ellipse} type}
\subsubsection{Constructors}

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.

The constructor code is as follows:
\begin{mpcode}
  vardef Ellipse(expr C,A,B) = 
  % C : centre
  % A : vertex
  % B : co-vertex  
  save n,a,b,c,e,_tmp,slope,_D,_K,_h,_ff; 
  pair _tmp;
  n = incr gddO;
  gddT[n] = "ellipse"; gddA[n] = PointImp(C); gddB[n] = PointImp(A);
  gddC[n] = PointImp(B);
  % calcul des deux foyers
  a = Longueur(C,A);
  b = Longueur(C,B);
  c = sqrt(a**2-b**2);
  e = c/a;
  _tmp = e*(Pt(A)-Pt(C));
  % les foyers
  gddD[n] = PairTOPoint(Pt(C)+_tmp);
  gddE[n] = PairTOPoint(Pt(C)-_tmp);
  gddX[n][1] = a;
  gddX[n][2] = b;
  gddX[n][3] = e;
  % angle du demi grand axe
  slope = angle(PairImp(A)-PairImp(C));
  gddX[n][4] = slope;
  % directrices 
  _h = (a*a-c*c)/c;
  % prejection sur la directice
  _ff = Droite(gddE[n],gddD[n]);
  _K = ReportSurDroite(gddD[n],_ff,_h);
  _D = DroitePerpendiculaire(_ff,_K);
  gddX[n][5] := _D; % on stock la directrice
  gddX[n][6] := SymetrieCentrale(_D,gddA[n]); % on stock la deuxième directrice
  n
enddef;
\end{mpcode}

\begin{colourband}
\macro|Ellipse(«c»,«a»,«b»)|\return{\typeGDD{ellipse}}
\begin{description}
  \item[\meta{c}:]  \typeGDD{point} or \typeMP{pair}, the center;
  \item[\meta{a}:]  \typeGDD{point} or \typeMP{pair}, the vertex;
  \item[\meta{b}:]  \typeGDD{point} or \typeMP{pair}, the co-vertex.
\end{description}\index{Ellipse@\lstinline+Ellipse+}
\end{colourband}
\bigskip

This macro is used as shown in the following example.
\begin{ExempleMP}
input geom2d;
beginfig(1);
C = Point(0,0);
A = Point(3,1);
B = Rotation((1.5,0.5),Pi/2);
E = Ellipse(C,A,B);
gddDraw E;
gddDrawPoint A; gddDrawPoint B; gddDrawPoint C;
endfig;
\end{ExempleMP}

An ellipse can be defined with its two foci and the semi-major axis using the following command:
\begin{colourband}
\macro|EllipseF(«A»,«B»,«a»)|\return{\typeGDD{ellipse}}
\begin{description}
  \item[\meta{A}:]  \typeGDD{point} or \typeMP{pair}, first focus;
  \item[\meta{B}:]  \typeGDD{point} or \typeMP{pair}, second focus;
  \item[\meta{a}:]  \typeGDD{numeric}, the semi-major axis.
\end{description}\index{EllipseF@\lstinline+EllipseF+}
\end{colourband}
\bigskip


This macro is used as shown in the following example.
\begin{ExempleMP}
input geom2d;
beginfig(1);
F1 = Point(3,1);
F2 = Point(1.5,0.5);
E = EllipseF(F1,F2,1.7);
gddDraw E;
gddDrawPoint F1; gddDrawPoint F2;
endfig;
\end{ExempleMP}

We can also define an ellipse from a focus, its directrix, and the eccentricity with the following command:
\begin{colourband}
\macro|EllipseFD(«F»,«D»,«e»)|\return{\typeGDD{ellipse}}
\begin{description}
  \item[\meta{F}:]  \typeGDD{point} or \typeMP{pair}, a focus;
  \item[\meta{D}:]  \typeGDD{droite}, the associated directrix;
  \item[\meta{e}:]  \typeGDD{numeric}, the eccentricity ($<1$).
\end{description}\index{EllipseFD@\lstinline+EllipseFD+}
\end{colourband}
\bigskip

\subsubsection{Associated Macros}

You can obtain the center (\typeGDD{point}) of an ellipse with the following command:
\begin{colourband}
  \macro|Center(«a»)|\return{\typeGDD{point}}
  \begin{description}
    \item[\meta{a}:]  \typeGDD{cercle}, \typeGDD{ellipse} or \typeGDD{hyperbole}.
  \end{description}\index{Center@\lstinline+Center+}
\end{colourband}

You can obtain the vertex and co-vertex with the following commands:
\begin{colourband}
\macro|Vertex(«a»)|\return{\typeGDD{point}}
\begin{description}
  \item[\meta{a}:]  \typeGDD{ellipse}.
\end{description}\index{Vertex@\lstinline+Vertex+}
\end{colourband}
\bigskip

\begin{colourband}
\macro|CoVertex(«a»)|\return{\typeGDD{point}}
\begin{description}
  \item[\meta{a}:]  \typeGDD{ellipse}.
\end{description}\index{CoVertex@\lstinline+CoVertex+}
\end{colourband}
\bigskip

The following command allows obtaining the two foci based on the integer passed as an argument.
\begin{colourband}
\macro|Focus(«a»,«n»)|\return{\typeGDD{point}}
\begin{description}
  \item[\meta{a}:]  \typeGDD{ellipse} ;
  \item[\meta{n}:] \typeMP{numeric}, integer which is 1 or 2 to obtain each focus.
\end{description}\index{Focus@\lstinline+Focus+}
\end{colourband}
\bigskip

You can obtain the semi-major axis and the semi-minor axis with the following commands.
\begin{colourband}
\macro|SemiMajorAxis(«a»)|\return{\typeMP{numeric}}
\begin{description}
  \item[\meta{a}:]  \typeGDD{ellipse}.
\end{description}\index{SemiMajorAxis@\lstinline+SemiMajorAxis+}
\end{colourband}
\bigskip


\begin{colourband}
\macro|SemiMinorAxis(«a»)|\return{\typeMP{numeric}}
\begin{description}
  \item[\meta{a}:]  \typeGDD{ellipse}.
\end{description}\index{SemiMinorAxis@\lstinline+SemiMinorAxis+}
\end{colourband}
\bigskip

We can get the excentricity, denoted by $e$, with the following command.

\begin{colourband}
\macro|Excentricity(«a»)|\return{\typeMP{numeric}}
\begin{description}
  \item[\meta{a}:]  \typeGDD{ellipse}, \typeGDD{parabole} ou \typeGDD{hyperbole}.
\end{description}\index{Excentricity@\lstinline+Excentricity+}
\end{colourband}
\bigskip

To obtain the inclination (slope of the line passing through the foci of the ellipse), use the following command.

\begin{colourband}
\macro|Slope(«a»)|\return{\typeMP{numeric}}
\begin{description}
  \item[\meta{a}:]  \typeGDD{ellipse}, \typeGDD{parabole}, or \typeGDD{hyperbole}.
\end{description}\index{Slope@\lstinline+Slope+}
\end{colourband}
\bigskip

You can obtain the directrices of the ellipse with the following command:

\begin{colourband}
\macro|Directrix(«a»,«n»)|\return{\typeGDD{droite}}
\begin{description}
  \item[\meta{a}:]  \typeGDD{ellipse}, \typeGDD{parabole}, or \typeGDD{hyperbole}
  ; 
  \item[\meta{n}:]  1 or 2 (\typeMP{numeric}), to choose one of the two
  directrices. 
\end{description}\index{Directrix@\lstinline+Directrix+}
\end{colourband}
\bigskip
To obtain the tangent (\typeGDD{droite}) at a point on the ellipse, use the following command.

\begin{colourband}
\macro|EllipseTangent(«e»,«p»)|\return{\typeGDD{droite}}
\begin{description}
  \item[\meta{e}:]  \typeGDD{ellipse};
  \item[\meta{p}:]  \typeGDD{point} or \typeMP{pair}.
\end{description}\index{EllipseTangent@\lstinline+EllipseTangent+}
\end{colourband}
\bigskip

\begin{ExempleMP}
input geom2d;
beginfig(1);
F1 = Point(3,1);
F2 = Point(1.5,0.5);
E = EllipseF(F1,F2,2.4);
gddDrawPoints F1, F2;
gddDraw E;
M' = PointOf(E,0.5);
D = EllipseTangent(E,M');
gddDraw D;
gddDrawPoints M', Foyer(E,1), Foyer(E,2);
Window(-0.2,-2.5,6,4);
endfig;
\end{ExempleMP}


To obtain the tangents (\typeGDD{droite}) passing through a point outside the
ellipse, use the following command. If the chosen point is not outside the
ellipse, a compilation error will occur.

\begin{colourband}
\macro|ExternalEllipseTangent(«e»,«p»,«n»)|\return{\typeGDD{droite}}
\begin{description}
  \item[\meta{e}:]  \typeGDD{ellipse} ;
  \item[\meta{p}:]  \typeGDD{point} or \typeGDD{pair} ;
  \item[\meta{n}:] \typeMP{numeric} which is 1 or 2 to choose the tangent among
  the two possible ones.
\end{description}\index{ExternalEllipseTangent@\lstinline+ExternalEllipseTangent+}
\end{colourband}
\bigskip

The points of tangency can be accessed as the second point in the definition of
the \typeGDD{droite} using the \variableGDD{gddB[]} table.

\begin{ExempleMP}
input geom2d;
beginfig(1);
F1 = Point(3,1);
F2 = Point(1.5,0.5);
E = EllipseF(F1,F2,2.4);
gddDrawPoint F1; gddDrawPoint F2;
gddDraw E;
M = Point(4,3);
D1 = ExternalEllipseTangent(E,M,1);
gddDraw D1;
gddDrawPoint gddB[D1];
D2 = ExternalEllipseTangent(E,M,2);
gddDraw D2;
gddDrawPoint gddB[D2];
gddDrawPoint M;
gddDrawPoint Focus(E,1);
gddDrawPoint Focus(E,2);
Window(-0.2,-2.5,6,4);
endfig;
\end{ExempleMP}

\subsection{The \typeGDD{parabole} type}

The basic constructor for the parabola defines this object using the focus and
the directrix. 

The constructor code is as follows:
\begin{mpcode}
vardef ParaboleFD(expr F,D) =
  % F : foyer (point)
  % D : directrice (droite)
  save u, v, w, d, i, n,_tmp,slope; 
  pair _tmp;
  n = incr gddO;
  (u,v,w) = EquationDroite(D);
  % ordonnée relative
  d := u * gddA[F] + v * gddB[F] + w;
  gddT[n] := "parabole"; 
  gddX[n][1] := D; % on stocke la directrice
  gddX[n][2] := D; % on stocke la directrice (compatibilité avec hyperbole)
  % sommet 
  _tmp := (((-d/2)*(u,v)) shifted PairImp(F));
  gddB[n] = PointImp(_tmp);
  gddC[n] = PointImp(_tmp);
  % le foyer (doublé pour compatibilité)
  gddD[n] := F;
  gddE[n] := F;
  gddX[n][3] := 1.0; % excentricité
  % angle du demi-grand axe
  slope = angle(PairImp(gddA[D])-PairImp(gddB[D]))+90;
  gddX[n][4] = slope;
  i := -gddC2Dparam-1;
  gddP[n] := (
    ((i*(v,-u)+((i*i-d*d)/(2d))*(u,v))
    for i:= -gddC2Dparam upto gddC2Dparam:
      ..(i*(v,-u)+((i*i-d*d)/(2d))*(u,v))
    endfor)) shifted PairImp(F);
   n
enddef;
\end{mpcode}
\begin{colourband}
  \macro|ParabolaFD(«f»,«d»)|\return{\typeGDD{path}}
  \begin{description}
    \item[\meta{f}:] is the focus (\typeGDD{point}) of the parabola;
    \item[\meta{d}:] is the directrix (\typeGDD{droite}) of the parabola.
  \end{description}
  \index{ParabolaFD@\lstinline+ParabolaFD+}
\end{colourband}

When representing a parabola, the \emph{infinite} nature is managed by the
global variable \lstinline+gddC2Dparam+, which defaults to 15.


To modify it, use the following command:
\begin{colourband}
\macro|SetConicCoef(«n»)|
\begin{description}
  \item[\meta{n}:] \typeMP{numeric}, parameter for drawing hyperbolas and
  parabolas (default value 15). 
\end{description}
\index{SetConicCoef@\lstinline+SetConicCoef+}
\end{colourband}

\subsubsection{Associated Functions}

The eccentricity, often denoted as $e$, can be obtained using the following command:

\begin{colourband}
\macro|Excentricity(«a»)|\return{\typeMP{numeric}}
\begin{description}
  \item[\meta{a}:]  \typeGDD{ellipse}, \typeGDD{parabole}, or \typeGDD{hyperbole}.
\end{description}\index{Excentricity@\lstinline+Excentricity+}
\end{colourband}
\bigskip

To obtain the slope (the slope of the axis of symmetry of the parabola), use the following command:

\begin{colourband}
\macro|Slope(«a»)|\return{\typeMP{numeric}}
\begin{description}
  \item[\meta{a}:]  \typeGDD{ellipse}, \typeGDD{parabole}, or \typeGDD{hyperbole}.
\end{description}\index{Slope@\lstinline+Slope+}
\end{colourband}
\bigskip
The vertex of the parabola can be obtained using the following command:

\begin{colourband}
\macro|ParabolaVertex(«a»,«n»)|\return{\typeGDD{point}}
\begin{description}
  \item[\meta{a}:]  \typeGDD{parabole} or \typeGDD{hyperbole};
  \item[\meta{n}:]  1 or 2 (\typeMP{numeric}), an argument useful for the
  hyperbola  which has two vertices. Here, the value of \meta{n} does not
  matter, as the unique   vertex will be returned.
\end{description}\index{ParabolaVertex@\lstinline+ParabolaVertex+}
\end{colourband}
\bigskip
The parabola's directrix can be obtained using the following command:

\begin{colourband}
\macro|Directrix(«a»,«n»)|\return{\typeGDD{droite}}
\begin{description}
  \item[\meta{a}:]  \typeGDD{ellipse}, \typeGDD{parabole}, or \typeGDD{hyperbole}; 
  \item[\meta{n}:]  1 or 2 (\typeMP{numeric}), an argument useful for the
  hyperbola   which has two directrices. Here, the value of \meta{n} does not
  matter,
  as the unique directrix will be returned.
\end{description}\index{Directrix@\lstinline+Directrix+}
\end{colourband}
\bigskip

\begin{ExempleMP}
input geom2d;
beginfig(1);
A = Point(0,0);
B = Point(3,2);
AB = Line(A,B);
F = Point(-1,1);
Para = ParabolaFD(F,AB);
gddDraw AB;
gddDraw Para;
gddDrawPoint ParabolaVertex(Para,1);
gddDrawPoint F;
Window(-4,-5,2,5);
endfig;
\end{ExempleMP}


\subsection{The \typeGDD{hyperbole} type}

The basic constructor for the hyperbola defines this object using the focus and
the directrix. 

The constructor code is as follows:
\begin{mpcode}
vardef HyperboleFD(expr F,D,e) =
  % F : foyer (point)
  % D : directrice (droite)
  % e : exentricité (numeric)
  % pm : +1 ou -1 pour les deux branches
  save u, v, w, d, i, n,_tmp,slope,aa,bb; 
  pair _tmp;
  n = incr gddO;

  (u,v,w) = EquationDroite(D);
  d := u * gddA[F] + v * gddB[F] + w;
  gddT[n] := "hyperbole"; 
  
  % sommets 
  _tmp := -(d+1*sqrt(e*e*d*d))/(e*e-1)*(u,v)shifted (ProduitScalaire(F,Vecteur(v,-u))*(v,-u));
  gddB[n] := PointImp(_tmp);
  _tmp := -(d-1*sqrt(e*e*d*d))/(e*e-1)*(u,v)shifted
  (ProduitScalaire(F,Vecteur(v,-u))*(v,-u));
  gddC[n] := PointImp(_tmp);
  % centre comme milieu des deux sommets
  gddA[n] = Milieu(gddB[n],gddC[n]);
  % le foyer (doublé pour compatibilité)
  gddD[n] := F;
  gddE[n] := RotationCentre(F, gddA[n], Pi);
  gddX[n][3] := e; % excentricité
  % directrices
  gddX[n][1] := D; % on stocke la directrice
  gddX[n][2] := Droite(RotationCentre(gddA[D], gddA[n], Pi),RotationCentre(gddB[D], gddA[n], Pi));
  % angle de l'axe
  slope = angle(PairImp(gddA[D])-PairImp(gddB[D]))+90;
  gddX[n][4] = slope;
  % cercle principale
  gddX[n][5] = CercleD(gddB[n],gddC[n]);
  % asymptotes
  aa = IntersectionDroiteCercle(D,gddX[n][5],1);
  bb = IntersectionDroiteCercle(D,gddX[n][5],2);
  gddX[n][6] = Droite(gddA[n],aa);
  gddX[n][7] = Droite(gddA[n],bb);
  % tracés des moitiés
  i := -gddC2Dparam-1;
  gddPX[n][1] := (
    (
    (i*(v,-u)-(d+sqrt(e*e*d*d+i*i*(e*e-1)))/(e*e-1)*(u,v))
    for i:= -gddC2Dparam upto gddC2Dparam:
      ..(i*(v,-u)-(d+sqrt(e*e*d*d+i*i*(e*e-1)))/(e*e-1)*(u,v))
    endfor
  ) shifted (ProduitScalaire(F,Vecteur(v,-u))*(v,-u))
  );
  gddPX[n][2] := (
    (
    (i*(v,-u)-(d-sqrt(e*e*d*d+i*i*(e*e-1)))/(e*e-1)*(u,v))
    for i:= -gddC2Dparam upto gddC2Dparam:
      ..(i*(v,-u)-(d-sqrt(e*e*d*d+i*i*(e*e-1)))/(e*e-1)*(u,v))
    endfor
  ) shifted (ProduitScalaire(F,Vecteur(v,-u))*(v,-u))
  );
  n
enddef;
\end{mpcode}

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.
\begin{colourband}
  \macro|HyperbolaFD(«f»,«d»,«e»)|\return{\typeGDD{hyperbole}}
  \begin{description}
    \item[\meta{f}:] is the focus (\typeGDD{point}) of the hyperbola;
    \item[\meta{d}:] is the directrix (\typeGDD{droite}) of the hyperbola;
    \item[\meta{e}:] is the eccentricity of the hyperbola. 
  \end{description}
  \index{HyperbolaFD@\lstinline+HyperbolaFD+}
\end{colourband}

You can also define a hyperbola using its two foci and the distance between
a vertex and the center of the hyperbola (bifocal definition).

\begin{colourband}
  \macro|HyperbolaF(«f1»,«f2»,«a»)|\return{\typeGDD{hyperbole}}
  \begin{description}
    \item[\meta{f1}:] is one focus (\typeGDD{point}) of the hyperbola;
    \item[\meta{f2}:] is the second focus (\typeGDD{point}) of the hyperbola;
    \item[\meta{a}:] is half the distance between the two vertices of the hyperbola. 
  \end{description}
  \index{HyperbolaF@\lstinline+HyperbolaF+}
\end{colourband}

\subsubsection{Associated Functions}

You can obtain the center (\typeGDD{point}) of a hyperbola with the following command:
\begin{colourband}
  \macro|Center(«a»)|\return{\typeGDD{point}}
  \begin{description}
    \item[\meta{a}:]  \typeGDD{cercle}, \typeGDD{ellipse}, or \typeGDD{hyperbole}.
  \end{description}\index{Center@\lstinline+Center+}
\end{colourband}


The eccentricity, often denoted as $e$, can be obtained using the following command.

\begin{colourband}
\macro|Excentricity(«a»)|\return{\typeMP{numeric}}
\begin{description}
  \item[\meta{a}:]  \typeGDD{ellipse}, \typeGDD{parabole}, or \typeGDD{hyperbole}.
\end{description}\index{Excentricity@\lstinline+Excentricity+}
\end{colourband}
\bigskip


To obtain the inclination (slope of the line passing through the foci of the hyperbola), use the following command.

\begin{colourband}
\macro|Slope(«a»)|\return{\typeMP{numeric}}
\begin{description}
  \item[\meta{a}:]  \typeGDD{ellipse}, \typeGDD{parabole}, or \typeGDD{hyperbole}.
  \end{description}\index{Slope@\lstinline+Slope+}
\end{colourband}
\bigskip


The vertices of the hyperbola can be obtained using the following command:

\begin{colourband}
\macro|HyperbolaVertex(«a»,«n»)|\return{\typeGDD{point}}
\begin{description}
  \item[\meta{a}:]  \typeGDD{parabola} or \typeGDD{hyperbola};
  \item[\meta{n}:]  1 or 2 (\typeMP{numeric}), to choose one of the two vertices.
\end{description}\index{HyperbolaVertex@\lstinline+HyperbolaVertex+}
\end{colourband}
\bigskip

You can obtain the directrices of the hyperbola with the following command:

\begin{colourband}
\macro|Directrix(«a»,«n»)|\return{\typeGDD{droite}}
\begin{description}
  \item[\meta{a}:]  \typeGDD{ellipse}, \typeGDD{parabole}, or \typeGDD{hyperbole}
  ; 
  \item[\meta{n}:]  1 or 2 (\typeMP{numeric}), to choose one of the two
  directrices. 
\end{description}\index{Directrix@\lstinline+Directrix+}
\end{colourband}
\bigskip

To obtain the \emph{principal circle} of the hyperbola, you can use the
following command:

\begin{colourband}
  \macro|PrincipalCircle(«h»)|\return{\typeGDD{cercle}}
  \begin{description}
    \item[\meta{h}:]  \typeGDD{hyperbole}.
  \end{description}\index{PrincipalCircle@\lstinline+PrincipalCircle+}
\end{colourband}
\bigskip

You can also obtain the two asymptotes of the hyperbola with the following command:

\begin{colourband}
  \macro|HyperbolaAsymptote(«h»,«n»)|\return{\typeGDD{droite}}
  \begin{description}
    \item[\meta{h}:]  \typeGDD{hyperbole} ;
    \item[\meta{n}:]  1 or 2 (\typeMP{numeric}), to choose one of the two
    asymptotes. 
  \end{description}\index{HyperbolaAsymptote@\lstinline+HyperbolaAsymptote+}
\end{colourband}
\bigskip

Because a hyperbola consists of two disjoint parts, you cannot directly use the
\lstinline+gddDraw+ command on the object as with other \mpgeomdd objects. Instead,
you must use the following command to obtain the \typeMP{path} associated with
one of the two parts of the hyperbola.

\begin{colourband}
  \macro|SemiHyperbola(«h»,«n»)|\return{\typeGDD{path}}
  \begin{description}
    \item[\meta{h}:]  \typeGDD{hyperbole};
    \item[\meta{n}:]  1 or 2 (\typeMP{numeric}), to choose one of the two parts.
  \end{description}\index{SemiHyperbola@\lstinline+SemiHyperbola+}
\end{colourband}
\bigskip


\begin{ExempleMP}
input geom2d;
beginfig(1);
A = Point(0,0);
B = Point(3,2);
AB = Line(A,B);
F = Point(-1,1);
Hyper = HyperbolaFD(F,AB,1.5);
gddDraw AB;
gddDraw SemiHyperbola(Hyper,1);
gddDraw SemiHyperbola(Hyper,2);
gddDraw Directrix(Hyper,2);
gddDraw PrincipalCircle(Hyper) dashed evenly;
gddDraw HyperbolaAsymptote(Hyper,1) dashed evenly;
gddDraw HyperbolaAsymptote(Hyper,2) dashed evenly;
gddDrawPoint Center(Hyper);
gddDrawPoint Focus(Hyper,1);
gddDrawPoint Focus(Hyper,2);
gddDrawPoint HyperbolaVertex(Hyper,1);
gddDrawPoint HyperbolaVertex(Hyper,2);
Window(-3,-5,3,5);
endfig;
\end{ExempleMP}

\subsection{The \typeGDD{triangle} type}

Triangles are defined by three points in $\R^2$.

\subsubsection{Constructor}
The constructor function for this object is as follows:
\begin{mpcode}
vardef Triangle (expr a,b,c) =
  save n; n = incr gddO; gddT[n] = "triangle";
  gddA[n] = PointImp(a); gddB[n] = PointImp(b); gddC[n] = PointImp(c); n
enddef;
\end{mpcode}

\begin{colourband}
\macro|Triangle(«a»,«b»,«c»)|\return{\typeMP{numeric}}
\begin{description}
  \item[\meta{a}:]  \typeGDD{point} ;
  \item[\meta{b}:]  \typeGDD{point} ;
  \item[\meta{c}:]  \typeGDD{point}.
\end{description}\index{Triangle@\lstinline+Triangle+}
\end{colourband}


\bigskip

Here, we see the use of the third table \variableGDD{gddC} to store the third point.

A triangle is then defined as follows:
\begin{ExempleMP}
input geom2d;
beginfig(1);
A = Point(3,1);
B = Point(1,3);
C = Point(0,0);
ABC = Triangle(A,B,C);
gddDraw ABC;
endfig;
\end{ExempleMP}

\subsubsection{Associated Macros}

The following macro calculates the area of a triangle.
\begin{colourband}
\macro|TriangleArea(«a»)|\return{\typeMP{numeric}}
\begin{description}
  \item[\meta{a}:]  \typeGDD{triangle}.
\end{description}\index{TriangleArea@\lstinline+TriangleArea+}
\end{colourband}

We can also calculate the orthocenter of a triangle using the following command.
\begin{colourband}
\macro|Orthocenter(«a»)|\return{\typeGDD{point}}
\begin{description}
  \item[\meta{a}:]  \typeGDD{triangle}.
\end{description}\index{Orthocenter@\lstinline+Orthocenter+}
\end{colourband}

The following macro calculates the inscribed circle of a triangle.
\begin{colourband}
\macro|InscribedCircle(«a»)|\return{\typeGDD{cercle}}
\begin{description}
  \item[\meta{a}:]  \typeGDD{triangle}.
\end{description}\index{InscribedCircle@\lstinline+InscribedCircle+}
\end{colourband}

You can also obtain the circumscribed circle with the following macro.
\begin{colourband}
\macro|CircumscribedCircle(«a»)|\return{\typeGDD{cercle}}
\begin{description}
  \item[\meta{a}:]  \typeGDD{triangle}.
\end{description}\index{CircumscribedCircle@\lstinline+CircumscribedCircle+}
\end{colourband}
We can also calculate the escribed circles. Let \(A\), \(B\), and \(C\) be three points
defining a triangle \(ABC\)\footnote{Of course, the points can have different names.}. 
The following command allows obtaining one of the three escribed circles, as desired.
\begin{colourband}
\macro|EscribedCircle(«a»,«n»)|\return{\typeGDD{cercle}}
\begin{description}
  \item[\meta{a}:]  \typeGDD{triangle};
  \item[\meta{n}:]  \typeMP{numeric} which can be 1, 2, or 3. If \meta{n}$=1$, it is
  the escribed circle tangent to the side \([BC]\) of the triangle; if \meta{n}$=2$, it is
  the one tangent to the side \([AC]\); and if \meta{n}$=3$, it is the one tangent to the side \([AB]\).
\end{description}\index{EscribedCircle@\lstinline+EscribedCircle+}
\end{colourband}
You can also obtain the Euler circle of a triangle with the following command.
\begin{colourband}
\macro|EulerCircle(«a»)|\return{\typeGDD{cercle}}
\begin{description}
  \item[\meta{a}:]  \typeGDD{triangle}.
\end{description}\index{EulerCircle@\lstinline+EulerCircle+}
\end{colourband}

Here is an example illustrating some of the macros related to triangles.
\begin{ExempleMP}
input geom2d;
beginfig(1);
A = Point(3,1);
B = Point(1,3);
C = Point(0,0);
AB = Line(A,B);
BC = Line(B,C);
ABC = Triangle(A,B,C);
gddDraw AB dashed evenly;
gddDraw BC dashed evenly;
gddDraw ABC withPen(1.5,black);
Euler = EulerCircle(ABC);
gddDraw Euler withPen(1,DarkRed);
C_E1 = EscribedCircle(ABC,2);
gddDraw C_E1 withPen(1,LightBlue);
C_C = CircumscribedCircle(ABC);
gddDraw C_C withPen(1,LightCoral);
Window(-1,-4,4,4);
endfig;
\end{ExempleMP}

\subsection{The \typeGDD{polygon} type}
Polygons are defined by $N$ points in $\R^2$.

\subsubsection{Constructors}

The constructor function for this object is as follows:
\begin{mpcode}
vardef Polygon e(text plist) =
  save n,_point,i; n = incr gddO; gddT[n] = "polygone";
  i:=1;
  for _point = plist:
    gddX[gddO][i] = PointImp(_point);
    i:=i+1;
  endfor
  gddA[n] = i-1; % number of sides
  gddB[n] = IsoBarycenter(plist); % center
  n
enddef;
\end{mpcode}

\begin{colourband}
\macro|Polygon(«list»)|\return{\typeGDD{polygone}}
\begin{description}
  \item[\meta{list}:] is a list of \typeGDD{point} or \typeMP{pair}.
\end{description}\index{Polygon@\lstinline+Polygon+}
\end{colourband}


\bigskip
Here, we see the use of the \emph{double} table \variableGDD{gddX} to store
the $N$ points.

A polygon is then defined as follows:
\begin{ExempleMP}
input geom2d;
beginfig(1);
A = Point(2,0);
B = Point(3,1);
C = Point(0,2);
D = Point(0,0);
P = Polygon(A,B,C,D);
gddDraw P;
endfig;
\end{ExempleMP}

You can also construct regular polygons with the following command.
\begin{colourband}
\macro|RegularPolygon(«N»,«radius»,«rotation»,«translation»)|\return{\typeGDD{polygone}}
\begin{description}
  \item[\meta{N}:] integer (\typeMP{numeric}) indicating the number of points;
  \item[\meta{radius}:] \typeMP{numeric}, radius of the circumscribed circle;
  \item[\meta{rotation}:]  \typeMP{numeric}, rotation of the polygon;
  \item[\meta{translation}:]  \typeGDD(point) or \typeGDD{vecteur} (or even
  \typeMP{pair}), displacement of the polygon's center.
\end{description}\index{RegularPolygon@\lstinline+RegularPolygon+}
\end{colourband}

\begin{ExempleMP}
input geom2d;
beginfig(1);
P = RegularPolygon(7,3,0,origine);
gddDraw P;
endfig;
\end{ExempleMP}

\subsubsection{Associated Macros}

You can obtain the number of sides of a polygon with the following command.

\begin{colourband}
\macro|PolygonNumberOfSides(«a»)|\return{\typeMP{numeric}}
\begin{description}
  \item[\meta{a}:]  \typeGDD{polygone}.
\end{description}\index{PolygonNumberOfSides@\lstinline+PolygonNumberOfSides+}
\end{colourband}
\bigskip

You can access the different vertices of the polygon, numbered starting from 1, using the following macro.

\begin{colourband}
\macro|PolygonPoint(«a»,«i»)|\return{\typeGDD{point}}
\begin{description}
  \item[\meta{a}:]  \typeGDD{polygone};
  \item[\meta{i}:] \typeMP{numeric}, an integer greater than or equal to 1, allowing access to the $i$\textsuperscript{th} point of the polygon.
\end{description}\index{PolygonPoint@\lstinline+PolygonPoint+}
\end{colourband}
\bigskip

\subsection{The \typeGDD{chemin} type} 

For this particular type (french translation of \emph{path}), \mpgeomdd stores
the \typeMP{path} in the reserved \variableGDD{gddP} table. Thus, the constructor
function for this type of object is as follows:
\begin{mpcode}
vardef Chemin (expr p) =
gddT[incr gddO] = "chemin"; gddP[gddO] = p; gddO
enddef;
\end{mpcode}
\begin{colourband}

We defined the english macro \lstinline+Path+ for the english interface. 

\macro|Path(«p»)|\return{\typeGDD{chemin}}
\begin{description}
  \item[\meta{p}:] a \typeMP{path} from \MP
\end{description}\index{Path@\lstinline+Path+}
\end{colourband}


\subsubsection{Associated Macros}

The following macro constructs, from a list of \typeGDD{point}s, a polyline of
type \typeGDD{chemin}.

\begin{colourband}
  \macro|Polyline(«list»)|\return{\typeGDD{chemin}}
  \begin{description}
    \item[\meta{list}:] is a list of \typeGDD{point} or \typeMP{pair}.
  \end{description}\index{Polyline@\lstinline+Polyline+}
\end{colourband}

\subsection{The \typeGDD{courbe} type}

For this particular type, \mpgeomdd stores
a string (a filename to be used with the \fichier{graph.mp} extension) in the reserved \variableGDD{gddS} table.

\subsubsection{Constructor}

The constructor function for this type of object is as follows:
\begin{mpcode}
vardef CourbeDat (expr s) =
  gddT[incr gddO] = "courbe"; gddS[gddO] = s; gddO
enddef;
\end{mpcode}

The engilsh interface uses the macro \lstinline+CurveData+.

\begin{colourband}
\macro|CurveData(«s»)|\return{\typeGDD{courbe}}
\begin{description}
  \item[\meta{s}:] a filename in the form of a \typeMP{string} in \MP
\end{description}\index{CurveData@\lstinline+CurveData+}
\end{colourband}

\bigskip

\section{Circle Arc}

With \mpgeomdd{}, several commands allow working with circle arcs. First, you
can choose to represent only a circle arc from a previously defined
\typeGDD{cercle}. This is done using the following command, which takes as
arguments a \typeGDD{cercle} and two angles in radians, and returns a
\typeMP{path} in \MP{} corresponding to the circle arc between the two given
angles (angle 0 being parallel to the $Ox$ axis).

\begin{colourband}
\macro|gddDrawCircleArc(«C»,«a»,«b»)|\return{\typeMP{path}}
\begin{description}
  \item[\meta{C}:] \typeGDD{cercle} from which we want to represent an arc;
  \item[\meta{a}:] first angle in radians (\typeMP{numeric});
  \item[\meta{b}:] second angle in radians (\typeMP{numeric}).
\end{description}\index{gddDrawCircleArc@\lstinline+gddDrawCircleArc+}
\end{colourband}

\begin{ExempleMP}
input geom2d;
beginfig(1);
C = Circle(origin,2);
gddDraw C;
gddDraw gddDrawCircleArc(C,Pi/3,Pi) withPen(2,DarkRed);
endfig;
\end{ExempleMP}
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.

\begin{colourband}
\macro|Arc(«P»,«r»,«a»,«b»)|\return{\typeGDD{path}}
\begin{description}
  \item[\meta{P}:] \typeGDD{point} or \typeMP{pair}, center of the circular arc;
  \item[\meta{r}:] radius of the circular arc (\typeMP{numeric});
  \item[\meta{a}:] first angle in radians (\typeMP{numeric});
  \item[\meta{b}:] second angle in radians (\typeMP{numeric}).
\end{description}\index{Arc@\lstinline+Arc+}
\end{colourband}


\begin{ExempleMP}
input geom2d;
beginfig(1);
A = Point(2,2);
Ac = Arc(A,2,Pi/3,Pi);
gddDrawPoint A;
gddDraw Ac;
endfig;
\end{ExempleMP}

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]$.
\begin{colourband}
\macro|ArcBetweenPoints(«P»,«r»,«A»,«B»,«s»)|\return{\typeGDD{path}}
\begin{description}
  \item[\meta{P}:] \typeGDD{point} or \typeMP{pair}, center of the circular arc;
  \item[\meta{r}:] radius of the circular arc (\typeMP{numeric});
  \item[\meta{A}:] first \typeGDD{point} or \typeMP{pair};
  \item[\meta{B}:] second \typeGDD{point} or \typeMP{pair};
  \item[\meta{s}:] \typeMP{numeric}, $-1$ or $1$ depending on the chosen direction.
\end{description}\index{ArcBetweenPoints@\lstinline+ArcBetweenPoints+}
\end{colourband}

\begin{ExempleMP}
input geom2d;
beginfig(1);
C = Point(0,0);
A = Point(2,2);
B = Point(0,3);
Cab = ArcBetweenPoints(C,1,A,B,1);
Cba = ArcBetweenPoints(C,1,A,B,-1);
gddDraw Segment(C,A);
gddDraw Segment(C,B);
gddDrawPoint A; gddDrawPoint B; gddDrawPoint C;
gddArrow Cab;
gddArrow Cba withPen(1,DarkRed);
endfig;
\end{ExempleMP}

\section{Some Macros}

This section groups together some macros that are not specific to a type. 
\bigskip

The following macro allows calculating an intersection point between two
\mpgeomdd objects. It is essentially a wrapper around the \MP{} primitive
\lstinline|intersectionpoint| applied to the \emph{drawn} objects (using
\lstinline+gddTraceObjet+). 

\begin{colourband}
\macro|PointIntersection(«o»,«b»)|\return{\typeGDD{point}}
\begin{description}
  \item[\meta{o}:] a \mpgeomdd object;
  \item[\meta{b}:] a \mpgeomdd object.
\end{description}\index{PointIntersection@\lstinline+PointIntersection+}
\end{colourband}

\section{Some Transformations}

\subsection{Homothety}

You can perform a homothety on any \mpgeomdd object using the following command.

\begin{colourband}
\macro|Homothety(«p»,«o»,«k»)|\return{same type as \meta{p}}
\begin{description}
  \item[\meta{p}:] a \mpgeomdd object;
  \item[\meta{o}:] \typeGDD{point} or \typeMP{pair}, center of the homothety;
  \item[\meta{k}:] \typeMP{numeric}, scaling factor of the homothety.
\end{description}\index{Homothety@\lstinline+Homothety+}
\end{colourband}

\begin{ExempleMP}
input geom2d;
beginfig(1);
A = Point(1,2);
B = Point(0,2);
C_B = Circle(B,1);
T = Triangle((1,1),(0,0),(0,1));
C_H = Homothety(C_B, A, 2);
T_H = Homothety(T, A ,-1);
gddDraw C_B; gddDraw C_H;
gddDraw T; gddDraw T_H;
gddDrawPoint A; gddDrawPoint B;
endfig;
\end{ExempleMP}


\subsection{Axial Symmetry}

You can perform an axial symmetry on any \mpgeomdd object using the following command.

\begin{colourband}
\macro|AxialSymmetry(«p»,«d»)|\return{same type as \meta{p}}
\begin{description}
  \item[\meta{p}:] a \mpgeomdd object;
  \item[\meta{d}:] \typeGDD{droite} defining the axis of symmetry.
\end{description}\index{AxialSymmetry@\lstinline+AxialSymmetry+}
\end{colourband}

\begin{ExempleMP}
input geom2d;
beginfig(1);
A = Point(1,2);
B = Point(0,2);
C_B = Circle(B,1);
T = Triangle((1,1),(0,0),(0,1));
D = Line((-1,0),(3,-1));
C_H = AxialSymmetry(C_B, D);
T_H = AxialSymmetry(T, D);
gddDraw C_B; gddDraw C_H;
gddDraw T; gddDraw T_H;
gddDraw D;
gddDrawPoint A; gddDrawPoint B;
Window(-2.5,-3.5,3,3.2);
endfig;
\end{ExempleMP}


\subsection{Central Symmetry}

You can perform a central symmetry on any \mpgeomdd object using the following command.

\begin{colourband}
\macro|CentralSymmetry(«p»,«d»)|\return{same type as \meta{p}}
\begin{description}
  \item[\meta{p}:] a \mpgeomdd object;
  \item[\meta{d}:] \typeGDD{point} defining the center of symmetry.
\end{description}\index{CentralSymmetry@\lstinline+CentralSymmetry+}
\end{colourband}

\begin{ExempleMP}
input geom2d;
beginfig(1);
A = Point(1,2);
B = Point(0,2);
C_B = Circle(B,1);
T = Triangle((1,1),(0,0),(0,1));
D = Point(-1,0);
C_H = CentralSymmetry(C_B, D);
T_H = CentralSymmetry(T, D);
gddDraw C_B; gddDraw C_H;
gddDraw T; gddDraw T_H;
gddDrawPoint D;
gddDrawPoint A; gddDrawPoint B;
Window(-3.5,-3.5,3,3.2);
endfig;
\end{ExempleMP}
\subsection{Inversion}

You can compute the inversion of a point, a circle, or a line with respect to a circle using the following macro:
\begin{colourband}
\macro|Inverse(«p»,«c»)|\return{\typeGDD{point}}
\begin{description}
  \item[\meta{p}:]  \typeGDD{point}, \typeGDD{cercle}, or \typeGDD{droite};
  \item[\meta{c}:]  \typeGDD{cercle}.
\end{description}\index{Inverse@\lstinline+Inverse+}
\end{colourband}
\bigskip

\begin{ExempleMP}
input geom2d;
beginfig(1);
  A = Point(2,2);
  C = Circle(A,2);
  gddDraw C;
  gddMark.rt "A";
  B = Point(-0.5,1);
  D = Inverse(B,C);
  drawoptions(withcolor DarkRed);
  gddMark.rt "B";  gddMark.rt "D";

  drawoptions(withcolor DarkBlue);
  E = Point(3,1);
  CE = Circle(E,0.5);
  gddDraw CE;
  gddMark.rt "E";
  iCE = Inverse(CE,C);
  gddDraw iCE;

  drawoptions(withcolor DarkGreen);
  d = Line((3,3),(4,2));
  gddDraw d;
  Cd = Inverse(d,C);
  gddDraw Cd;
  Window(-1,-1,5.5,6);
endfig;
\end{ExempleMP}

\subsection{Similirity with center (direct)}

One can compute a similarity centered at a point with a given ratio. This is done using the following macro.

\begin{colourband}
\macro|CenterSimilarity(«p»,«d»,«a»,«k»)|\return{same type as \meta{p}}
\begin{description}
  \item[\meta{p}:] a \mpgeomdd{} object;
  \item[\meta{d}:] a \typeGDD{point} defining the center of the similarity;
  \item[\meta{a}:] angle (in radians, \typeMP{numeric}) of the similarity;
  \item[\meta{k}:] similarity factor (\typeMP{numeric}).  
\end{description}\index{CenterSimilarity@\lstinline+CenterSimilarity+}
\end{colourband}

\begin{ExempleMP}
input geom2d;
beginfig(1);
A = Point(1,2);
B = Point(0,2);
C_B = Circle(B,1);
ratioSimi = 0.4;
angleSimi = Pi/3; 
T = Triangle((1,1),(0,0),(0,1));
D = Point(-1,0);
C_H = CenterSimilarity(C_B, D, angleSimi, ratioSimi);
T_H = CenterSimilarity(T, D, angleSimi, ratioSimi);
gddDraw C_B; gddDraw C_H;
gddDraw T; gddDraw T_H;
endfig;
\end{ExempleMP}

\section{Annotations and Labels}

\subsection{Right Angle Marks}

\mpgeomdd provides the following macro to mark a right angle formed by three points:
\begin{colourband}
\macro|OrthoSign(«a»,«b»,«c»,«x»)|
\begin{description}
  \item[\meta{a},\meta{b},\meta{c}:] are the three \typeGDD{point}s forming the right angle $\widehat{ABC}$;
  \item[\meta{x}:] is the \enquote{size} (\typeMP{numeric}) of the right angle mark.
\end{description}\index{OrthoSign@\lstinline+OrthoSign+}
\end{colourband}
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:
\begin{colourband}
\macro|Mark(«a»,«b»,«n»)|
\begin{description}
  \item[\meta{a}:] first \typeGDD{point} forming
  the segment to be marked;
  \item[\meta{b}:] second \typeGDD{point} forming
  the segment to be marked;
  \item[\meta{n}:] is the type (\typeMP{numeric}) of mark, there are four
  \meta{n}$=1$, $2$, $3$, or $4$.
\end{description}\index{Mark@\lstinline+Mark+}
\end{colourband}
You can also mark any type of line with the following macro:
\begin{colourband}
\macro|LineMark(«a»,«n»)|
\begin{description}
  \item[\meta{a}:] can be any \mpgeomdd object or even a \typeMP{path} in \MP;
  \item[\meta{n}:] is the type (\typeMP{numeric}) of mark, there are four types:
  \meta{n}$=1$, $2$, $3$, or $4$.
\end{description}\index{LineMark@\lstinline+LineMark+}
\end{colourband}
    
  
\begin{ExempleMP}
input geom2d;
beginfig(1);
A = Point(4,0);
B = Point(0,0);
C = Point(0,2);
gddDraw Segment(B,A);
gddDraw Segment(B,C);
gddMark.bot "A";
gddMark.bot "B";
gddMark.lft "C";
gddDraw OrthoSign(A,B,C,0.5);
gddDraw Mark(A,B,1);
gddDraw LineMark(Segment(B,C),3);
endfig;
\end{ExempleMP}
  
  \subsection{Labels}

  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.

  Additionally, \mpgeomdd provides some commands to make life easier.

  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.
  \begin{colourband}
  \macro|gddMark.«place» "«name»"|
  \begin{description}
    \item[\meta{place}:] can be the classic placements of \MP{}:
    \lstinline+top+, \lstinline+bot+, \lstinline+rt+,
    \lstinline+lft+, \lstinline+urt+, \lstinline+ulft+, \lstinline+lrt+, \lstinline+llft+.
    \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.
  \end{description}\index{gddMark@\lstinline+gddMark+}
  \end{colourband}

  \mpgeomdd also provides an adaptation to the classic \lstinline+label+ of \MP{}.

  \begin{colourband}
  \macro|gddLabel.«place»(«content»,«point»)|
  \begin{description}
    \item[\meta{place}:] can be the classic placements of \MP{}:
    \lstinline+top+, \lstinline+bot+, \lstinline+rt+,
    \lstinline+lft+, \lstinline+urt+, \lstinline+ulft+, \lstinline+lrt+, \lstinline+llft+.
    \item[\meta{content}:] typically what is given to \lstinline+label+, a string,
    or a \typeMP{picture} (which can be produced, for example, with
    \lstinline+btex ... etex+ or, since \package{latexmp} is loaded by \mpgeomdd,
    \lstinline+textext()+).
    \item[\meta{point}:] must be a \typeGDD{point} from \mpgeomdd.
  \end{description}\index{gddLabel@\lstinline+gddLabel+}
  \end{colourband}

You can also label a \typeGDD{chemin}, a \typeGDD{courbe}, or a
\typeMP{path} using the following macro:

\begin{colourband}
\macro|PathTag.«place»(«content»,«path»,«position»)|
\begin{description}
  \item[\meta{place}:] can be the classic placements of \MP{}:
  \lstinline+top+, \lstinline+bot+, \lstinline+rt+,
  \lstinline+lft+, \lstinline+urt+, \lstinline+ulft+, \lstinline+lrt+, \lstinline+llft+.
  \item[\meta{content}:] typically what is given to \lstinline+label+, a string,
  or a \typeMP{picture} (which can be produced, for example, with
  \lstinline+btex ... etex+ or, since \package{latexmp} is loaded by \mpgeomdd,
  \lstinline+textext()+).
  \item[\meta{path}:] must be a \typeGDD{chemin}, a \typeGDD{courbe}, or
  a \typeMP{path}.
\end{description}\index{PathTag@\lstinline+PathTag+}
\end{colourband}


\begin{ExempleMP}
input geom2d;
beginfig(1);
A = Point(0,0);
B_23 = Point(3,3);
alpha = Point(0,2);
gddDraw Segment(A,B_23);
C = MidPoint(A,B_23);
gddDrawPoint C;
gddLabel.top(textext("Midpoint"),C);
gddMark.top "A";
gddMark.urt "B_23";
gddMark.llft "alpha";
P = Path(Pt(A)..Pt(alpha)..Pt(B_23));
gddDraw P;
PathTag.top("Test",P,0.6);
endfig;
\end{ExempleMP}


\section{Coordinate System}

\mpgeomdd provides a set of commands to facilitate the drawing of coordinate systems.

The main command is the definition of the coordinate system, that is, the box in which the drawing will be represented.
\begin{colourband}
  \macro|Frame(«l»,«h»,«ox»,«oy»,«ux»,«uy»)|
  \begin{description}
    \item[\meta{l}:] \typeMP{numeric}, width of the coordinate system (in \lstinline+gddU+ units);
    \item[\meta{h}:] \typeMP{numeric}, height of the coordinate system (in \lstinline+gddU+ units);
    \item[\meta{ox}:] \typeMP{numeric}, distance (in \lstinline+gddU+ units) from the origin (\typeGDD{point} $(0,0)$) to the left edge;
    \item[\meta{oy}:] \typeMP{numeric}, distance (in \lstinline+gddU+ units) from the origin (\typeGDD{point} $(0,0)$) to the bottom edge;
    \item[\meta{ux}:] \typeMP{numeric}, unit of the $(Ox)$ axis (in \lstinline+gddU+ units);
    \item[\meta{uy}:] \typeMP{numeric}, unit of the $(Oy)$ axis (in \lstinline+gddU+ units).
  \end{description}\index{Frame@\lstinline+Frame+}
\end{colourband}


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.

This macro is accompanied by two others, also \emph{silent}, which serve only to:
\begin{itemize}
\item save the current \typeMP{picture};
\item build a \typeMP{picture} with the content found between \lstinline+gddBegin+ and \lstinline+gddEnd+;
\item crop (with \lstinline+clip+) the \typeMP{picture} to the frame of the constructed coordinate system;
\item add the current \typeMP{picture} to the saved one;
\item finally, restore the behavior of \lstinline+gddInPlace+ as it was before using \lstinline+Frame+.
\end{itemize}

These two commands are called \lstinline+gddBegin+ and \lstinline+gddEnd+.

\begin{colourband}
\macro|gddBegin|
\index{gddBegin@\lstinline+gddBegin+}
\end{colourband}

\begin{colourband}
\macro|gddEnd|
\index{gddEnd@\lstinline+gddEnd+}
\end{colourband}

Thus, it is very easy to illustrate that, up to a change of orthogonal basis, a circle is an ellipse.


\begin{ExempleMP}
input geom2d;
beginfig(1);
A = Point(1,1);
CA = Circle(A,2);
Frame(5,5,1,1,1,0.5);
gddBegin;
gddDraw CA;
gddEnd;
endfig;
\end{ExempleMP}

There are two commands available to draw the axes of the coordinate system. The first draws the axes passing through the origin.
\begin{colourband}
\macro|Axis|\indication{draws a set of elements on the coordinate system}
\index{Axis@\lstinline+Axis+}
\end{colourband}

This command also adds the labels for the $x$-axis and $y$-axis, which are stored in the following dedicated global variables:
\begin{colourband}
\macro|gddXlabel|\indication{\typeMP{string}, default value \lstinline+"$x$"+}
\index{gddXlabel@\lstinline+gddXlabel+}
\end{colourband}

\begin{colourband}
\macro|gddYlabel|\indication{\typeMP{string}, default value \lstinline+"$y$"+}
\index{gddYlabel@\lstinline+gddYlabel+}
\end{colourband}

Note, these commands must be used before calling \lstinline+gddBegin+.

The following example illustrates how to draw the axes.

\begin{ExempleMP}
input geom2d;
beginfig(1);
A = Point(1,1);
CA = Circle(A,2);
Frame(5,5,1,1,1,1);
gddYlabel:="$z$";
Axis;
gddBegin;
gddDraw CA;
gddEnd;
endfig;
\end{ExempleMP}

You can also define a coordinate system using a syntax that allows you to specify the minimum and maximum abscissas and ordinates.

\begin{colourband}
  \macro|FrameMinMax(«xmin»,«xmax»,«ymin»,«ymax»,«ux»,«uy»)|
  \begin{description}
    \item[\meta{xmin}:] \typeMP{numeric}, minimum abscissa (in \lstinline+gddU+ units).
    \item[\meta{xmax}:] \typeMP{numeric}, maximum abscissa (in \lstinline+gddU+ units).
    \item[\meta{ymin}:] \typeMP{numeric}, minimum ordinate (in \lstinline+gddU+ units).
    \item[\meta{ymax}:] \typeMP{numeric}, maximum ordinate (in \lstinline+gddU+ units).
    \item[\meta{ux}:] \typeMP{numeric}, unit of the $(Ox)$ axis (in \lstinline+gddU+ units).
    \item[\meta{uy}:] \typeMP{numeric}, unit of the $(Oy)$ axis (in \lstinline+gddU+ units).
  \end{description}\index{FrameMinMax@\lstinline+FrameMinMax+}
\end{colourband}

\begin{ExempleMP}
input geom2d;
beginfig(1);
A = Point(1,1);
CA = Circle(A,2);
FrameMinMax(-1,4,-1,4,1,1);
Axis;
gddBegin;
gddDraw CA;
gddEnd;
endfig;
\end{ExempleMP}

\mpgeomdd also provides a way to draw axes on the edge of the frame with the following command.
\begin{colourband}
\macro|SideAxis|\indication{draws a set of elements on the coordinate system}
\index{SideAxis@\lstinline+SideAxis+}
\end{colourband}

\begin{ExempleMP}
input geom2d;
beginfig(1);
A = Point(1,1);
CA = Circle(A,2);
FrameMinMax(-1,4,-1,4,1,1);
SideAxis;
gddBegin;
gddDraw CA;
gddEnd;
endfig;
\end{ExempleMP}


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.

\begin{colourband}
\macro|Graduations|\indication{draws a set of elements on the coordinate system}
\index{Graduations@\lstinline+Graduations+}
\end{colourband}


\begin{colourband}
\macro|SideGraduations|\indication{draws a set of elements on the coordinate system}
\index{SideGraduations@\lstinline+SideGraduations+}
\end{colourband}

Use the version consistent with the chosen axes.
\begin{ExempleMP}
input geom2d;
beginfig(1);
A = Point(1,1);
CA = Circle(A,2);
FrameMinMax(-1,4,-1,4,1,1);
SideAxis;
SideGraduations;
gddBegin;
gddDraw CA;
gddEnd;
endfig;
\end{ExempleMP}

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).
\begin{colourband}
\macro|Units(«unit»)|\indication{draws a set of elements on the coordinate system}
\begin{description}
  \item[\meta{unit}:] \typeMP{numeric}, value to be displayed on both axes.
\end{description}
\index{Units@\lstinline+Units+}
\end{colourband}
\begin{ExempleMP}
input geom2d;
beginfig(1);
A = Point(1,1);
CA = Circle(A,2);
FrameMinMax(-1,4,-1,4,1,1);
Axis;
gddBegin;
  Graduations;
  Units(2);
  gddDraw CA;
gddEnd;
endfig;
\end{ExempleMP}
You can also add a grid to your coordinate system with the following macro.
\begin{colourband}
\macro|FrameGrid|\indication{draws a set of elements on the coordinate system}
\index{FrameGrid@\lstinline+FrameGrid+}
\end{colourband}
In the following example, the color of the grid is set using the
\hologo{MetaPost} \lstinline+drawoptions+ command.
\begin{ExempleMP}
input geom2d;
beginfig(1);
A = Point(1,1);
CA = Circle(A,2);
FrameMinMax(-1,4,-1,4,1,1);
drawoptions(withcolor LightGrey);
FrameGrid;
drawoptions();
Axis;
gddBegin;
  Graduations;
  Units(1);
  gddDraw CA;
gddEnd;
endfig;
\end{ExempleMP}
You can also add a frame to the coordinate system with the following macro.
\begin{colourband}
  \macro|FrameBox|\return{\typeMP{path}}
  \index{FrameBox@\lstinline+FrameBox+}
\end{colourband}
  In the following example, the color of the grid is set using the
  \hologo{MetaPost} \lstinline+drawoptions+ command.
  \begin{ExempleMP}
input geom2d;
beginfig(1);
A = Point(1,1);
CA = Circle(A,2);
FrameMinMax(-1,4,-1,4,1,1);
drawoptions(withcolor LightGrey);
FrameGrid;
drawoptions();
Axis;
gddBegin;
  Graduations;
  Units(1);
  gddDraw CA;
  gddDraw FrameBox withcolor OrangeRed;
gddEnd;
endfig;
  \end{ExempleMP}

  \section{Some Mathematical Constants and Functions}

  \mpgeomdd defines two mathematical constants, \lstinline+Pi+ and \lstinline+_E+
  \index{Pi@\lstinline+Pi+}\index{_E@\lstinline+_E+}, for the constants
  $\uppi\simeq 3.14159265$ and $\mathrm{e}=2.71828183$.

  In addition, the package defines some mathematical functions of a real variable:
\begin{colourband}
\macro|sin(«x»)| \index{sin@\lstinline+sin+}
\macro|cos(«x»)| \index{cos@\lstinline+cos+}
\macro|tan(«x»)| \index{tan@\lstinline+tan+}
\macro|exp(«x»)| \index{exp@\lstinline+exp+}
\macro|ln(«x»)|  \index{ln@\lstinline+ln+}
\macro|cosh(«x»)| \index{ch@\lstinline+ch+}
\macro|sinh(«x»)| \index{sh@\lstinline+sh+}
\macro|tanh(«x»)| \index{th@\lstinline+th+}
\macro|arcsin(«x»)| \index{arcsin@\lstinline+arcsin+}
\macro|arccos(«x»)| \index{arccos@\lstinline+arccos+}
\macro|arctan(«x»)|  \index{arctan@\lstinline+arctan+}
\end{colourband}
\section{Representation of Curves and Functions}

\mpgeomdd{} also provides some macros to facilitate the simple representation of curves and mathematical functions.

\subsection{Function of a Real Variable}

To represent a function of a real variable, use the following macro:
\begin{colourband}
  \macro|Plot(«function»)(«ti»,«tf»,«n»)|\return{\typeMP{path}}
  \begin{description}
    \item[\meta{function}:] is a \MP{} macro that defines the mathematical function of a real variable to be represented;
    \item[\meta{ti}:] is the initial value (\typeMP{numeric}) of the variable from which to start building the representation of the function;
    \item[\meta{tf}:] is the final value (\typeMP{numeric}) of the variable up to which to build the representation of the function;
    \item[\meta{n}:] is the number of steps (\typeMP{numeric}) used for the discretization of the representation.
  \end{description}
  \index{Plot@\lstinline+Plot+}
\end{colourband}

\begin{ExempleMP}
input geom2d;
beginfig(1);
FrameMinMax(-2Pi,2Pi,-1.1,1.1,0.4,1);
Axis;
gddBegin;
  Graduations;
  gddDraw Plot(cos,-2Pi,2Pi,100);
gddEnd;
endfig;
\end{ExempleMP}

\subsection{Parametric Curve}

To represent a plane curve defined by two functions describing the abscissa and ordinate as functions of a parameter, use the following macro:
\begin{colourband}
  \macro|Curve(«abscissa_function»)(«ordinate_function»)(«ti»,«tf»,«n»)|\return{\typeMP{path}}
  \begin{description}
    \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;
    \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;
    \item[\meta{ti}:] is the initial value (\typeMP{numeric}) of the variable from which to start building the representation of the function;
    \item[\meta{tf}:] is the final value (\typeMP{numeric}) of the variable up to which to build the representation of the function;
    \item[\meta{n}:] is the number of steps (\typeMP{numeric}) used for the discretization of the representation.
  \end{description}
  \index{Curve@\lstinline+Curve+}
\end{colourband}

\begin{ExempleMP}
input geom2d;
vardef f_x(expr t)= cos(t) enddef;
vardef f_y(expr t)= sin(2*t) enddef;

beginfig(1);
FrameMinMax(-1.1,1.1,-1.1,1.1,2,2);
Axis;
gddBegin;
  Graduations;
  gddDraw Curve(f_x,f_y,-2Pi,2Pi,100);
gddEnd;
endfig;
\end{ExempleMP}

  To represent a plane curve defined by a function describing the polar coordinates as a function of a parameter, use the following macro:
  \begin{colourband}
    \macro|PolarCurve(«function»)(«ti»,«tf»,«n»)|\return{\typeMP{path}}
    \begin{description}
      \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;
      \item[\meta{ti}:] is the initial value (\typeMP{numeric}) of the variable from which to start building the representation of the function;
      \item[\meta{tf}:] is the final value (\typeMP{numeric}) of the variable up to which to build the representation of the function;
      \item[\meta{n}:] is the number of steps (\typeMP{numeric}) used for the discretization of the representation.
    \end{description}
    \index{PolarCurve@\lstinline+PolarCurve+}
  \end{colourband}


\begin{ExempleMP}
input geom2d;
a := 2;
vardef cardioid(expr t)= a*(1+cos(t)) enddef;
beginfig(1);
FrameMinMax(-1.1,4.1,-2.8,2.8,1,1);
Axis;
gddBegin;
  Graduations;
  gddDraw PolarCurve(cardioid,0,2Pi,100);
gddEnd;
endfig;
\end{ExempleMP}


\subsection{Vector Fields}

\mpgeomdd provides macros for representing vector fields.

First, you can plot vector fields associated with a first-order differential equation for a function $y$ of the variable $x$:
\[y'=F(x,y).\]
The associated macro is as follows:
\begin{colourband}
  \macro|VectorField(«function»)(«x»,«y»,«px»,«py»,«dx»,«color»)|\return{\typeMP{path}}
  \begin{description}
    \item[\meta{function}:] is a \MP{} macro that defines a mathematical function from $\R^2$ to $\R$;
    \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$;
    \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$;
    \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;
    \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;
    \item[\meta{dx}:] is the norm (\typeMP{numeric}), in \variableGDD{gddU} units, of the vectors in the vector field;
    \item[\meta{color}:] is the (\typeMP{color}) used to draw the vectors.
  \end{description}
  \index{VectorField@\lstinline+VectorField+}
\end{colourband}

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}).
\begin{ExempleMP}
input geom2d;
vardef F(expr x,y) = x - 2 * x * y enddef;
vardef f(expr x) = 1/2 + a * exp(- x*x) enddef;
beginfig(1);
FrameMinMax(-2.5,2.5,-2.8,2.8,1,1);
Axis;
gddBegin;
Graduations;
ahlength := 1;
VectorField(F,0,0,0.2,0.2,0.1,0.5white);
% Integral curves
for n = 0 upto 16:
  a := (n/2) - 4;
  gddDraw Plot(f,-2.5,2.5,50)
  withPen(1,(0.7,0.2,0.2));
endfor
gddEnd;
endfig;
\end{ExempleMP}

Similarly, you can plot vector fields of a function from
$\R^2$ to $\R^2$. 
The associated macro is as follows:
\begin{colourband}
  \macro|VectorFieldDD(«function»)(«x»,«y»,«px»,«py»,«dx»,«color»)|\return{\typeMP{path}}
  \begin{description}
    \item[\meta{function}:] is a \MP{} macro that defines a mathematical function from $\R^2$ to $\R^2$ (thus returning a \typeMP{pair});
    \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$;
    \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$;
    \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;
    \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;
    \item[\meta{dx}:] is the norm (\typeMP{numeric}), in \variableGDD{gddU} units, of the vectors in the vector field;
    \item[\meta{color}:] is the (\typeMP{color}) used to draw the vectors.
  \end{description}
  \index{VectorFieldDD@\lstinline+VectorFieldDD+}
\end{colourband}


  \begin{ExempleMP}[sidebyside=false]
input geom2d;
gddXlabel := "$\theta$";
gddYlabel := "$\dot\theta$";
numeric b,c;
b:=0.5;
c=1.0;

vardef F(expr x,y) = (y,-b*y-c*sin(x)) enddef;

beginfig(1);
Frame(10,6,2,4,2,2);
Axis;
Units(1);
gddBegin;
Graduations;
trajectory := CurveData("solution0",0);
VectorFieldDD(F,0.5,0.5,0.2,0.2,0.15,0.5white);
gddDraw trajectory withPen(1,(0.7,0.2,0.2));
gddDrawPoint Point(0,0) withPen(1,(0.7,0.2,0.2));
gddDrawPoint Point(3.1415,0) withPen(1,(0.7,0.2,0.2));
gddEnd;
endfig;
\end{ExempleMP}





\section{SVG Colors (\texttt{svgnames})}

\begin{mplibcode}
input exemples/svgnames/palette.mp
\end{mplibcode}


\pagestyle{empty}
\begin{landscape}
  \section{Gallery}
  \subsection{Coordinate System and External Tangents}
  \begin{minipage}{0.5\linewidth}
    \begin{center}
      \begin{mplibcode}
        input exemples/cercles/cercles2-en.mp;
      \end{mplibcode}
    \end{center}
  \end{minipage}
  \begin{minipage}{0.5\linewidth}
    \lstinputlisting[basicstyle=\ttfamily\small]{exemples/cercles/cercles2-en.mp}
  \end{minipage}
\end{landscape}

\begin{landscape}
  \subsection{Vector in a Coordinate System}

  \begin{multicols}{2}
    \begin{center}
      \begin{mplibcode}
        input exemples/reperes/reperes2-en.mp;
      \end{mplibcode}
    \end{center}
    \lstinputlisting[basicstyle=\ttfamily\scriptsize]{exemples/reperes/reperes2-en.mp}
  \end{multicols}
\end{landscape}

\begin{landscape}
  \subsection{Pascal’s Theorem}

  \begin{multicols}{2}
    \begin{center}
      \begin{mplibcode}
        input exemples/divers/pascalline-en.mp;
      \end{mplibcode}
    \end{center}
    \lstinputlisting[basicstyle=\ttfamily\scriptsize]{exemples/divers/pascalline-en.mp}
  \end{multicols}
\end{landscape}

\begin{landscape}
  \subsection{Hyperbola}

  \begin{multicols}{2}
    \begin{center}
      \begin{mplibcode}
        input exemples/coniques/hyper-en.mp;
      \end{mplibcode}
    \end{center}
    \lstinputlisting[basicstyle=\ttfamily\scriptsize]{exemples/coniques/hyper-en.mp}
  \end{multicols}
\end{landscape}

\begin{landscape}
  \subsection{Astroid as an Envelope of Lines}

  \begin{multicols}{2}
    \begin{center}
      \begin{mplibcode}
        input exemples/courbes/cp01-en.mp;
      \end{mplibcode}
    \end{center}
    \lstinputlisting[basicstyle=\ttfamily\scriptsize]{exemples/courbes/cp01-en.mp}
  \end{multicols}
\end{landscape}


\begin{landscape}
  \subsection{Lissajous Curve}

  \begin{multicols}{2}
    \begin{center}
      \begin{mplibcode}
        input exemples/courbes/cp02-en.mp;
      \end{mplibcode}
    \end{center}
    \lstinputlisting[basicstyle=\ttfamily\scriptsize]{exemples/courbes/cp02-en.mp}
  \end{multicols}
\end{landscape}

\begin{landscape}
  \subsection{Function Study}

  \begin{multicols}{2}
    \begin{center}
      \begin{mplibcode}
        input exemples/courbes/cp05-en.mp;
      \end{mplibcode}
    \end{center}
    \lstinputlisting[basicstyle=\ttfamily\scriptsize]{exemples/courbes/cp05-en.mp}
  \end{multicols}
\end{landscape}

\begin{landscape}
  \subsection{Bicorne}

  \begin{multicols}{2}
    \begin{center}
      \begin{mplibcode}
        input exemples/courbes/cp08-en.mp;
      \end{mplibcode}
    \end{center}
    \lstinputlisting[basicstyle=\ttfamily\scriptsize]{exemples/courbes/cp08-en.mp}
  \end{multicols}
\end{landscape}

\begin{landscape}
  \subsection{A function et its derivatives}

  \begin{multicols}{2}
    \begin{center}
      \begin{mplibcode}
        input exemples/fonctions/fonction2-en.mp;
      \end{mplibcode}
    \end{center}
    \lstinputlisting[basicstyle=\ttfamily\scriptsize]{exemples/fonctions/fonction2-en.mp}
  \end{multicols}
\end{landscape}

\begin{landscape}
  \subsection{Cardioid}

  \begin{multicols}{2}
    \begin{center}
      \begin{mplibcode}
        input exemples/polaires/pol02-en.mp;
      \end{mplibcode}
    \end{center}
    \lstinputlisting[basicstyle=\ttfamily\scriptsize]{exemples/polaires/pol02-en.mp}
  \end{multicols}
\end{landscape}

\begin{landscape}
  \subsection{Axis of similitude}
  \begin{center}
    \begin{mplibcode}
      input exemples/cercles/axessimilitude-en.mp;
    \end{mplibcode}
  \end{center}
  \begin{multicols}{2}
    \lstinputlisting[basicstyle=\ttfamily\scriptsize]{exemples/cercles/axessimilitude-en.mp}
  \end{multicols}
\end{landscape}


\begin{landscape}
  \subsection{Cubic Drawing}
  \begin{multicols}{2}
    \begin{center}
      \begin{mplibcode}
        input exemples/cubiques/K001-en.mp;
      \end{mplibcode}
    \end{center}
    \lstinputlisting[basicstyle=\ttfamily\scriptsize]{exemples/cubiques/K001-en.mp}
  \end{multicols}
\end{landscape}

\begin{landscape}
  \subsection{Apollonius}

  \begin{multicols}{2}
    \begin{center}
      \begin{mplibcode}
        input exemples/triangles/apollonius-en.mp;
      \end{mplibcode}
    \end{center}
    \lstinputlisting[basicstyle=\ttfamily\scriptsize]{exemples/triangles/apollonius-en.mp}
  \end{multicols}
\end{landscape}

\begin{landscape}
  \subsection{Ogive Working Drawing}

    \begin{multicols}{2}
      \begin{center}
        \begin{mplibcode}
          input exemples/construction/ogiveentiers-en.mp;
        \end{mplibcode}
      \end{center}
      \lstinputlisting[basicstyle=\ttfamily\scriptsize]{exemples/construction/ogiveentiers-en.mp}
    \end{multicols}
\end{landscape}

\begin{landscape}
  \subsection{Pedal Triangle}

  Figure 21 of~\cite{toeplitz}.
  \begin{center}
    \begin{mplibcode}
      input exemples/triangles/pedale-en.mp;
    \end{mplibcode}
  \end{center}
  \begin{multicols}{2}
    \lstinputlisting[basicstyle=\ttfamily\scriptsize]{exemples/triangles/pedale-en.mp}
  \end{multicols}
\end{landscape}
\newpage

\begin{landscape}
  \subsection{Pappus Chain}

  Pappus chain with geometric inverse.
  \begin{multicols}{2}
    \begin{mplibcode}
      input exemples/cercles/pappuschain-en.mp;
    \end{mplibcode}

    \lstinputlisting[basicstyle=\ttfamily\scriptsize]{exemples/cercles/pappuschain-en.mp}
  \end{multicols}
\end{landscape}
\newpage
\begin{landscape}
  \subsection{The Pythagoras tree using similarity}

  Constructing the Pythagoras tree by similarity.  
  This code is inspired by the construction proposed by MicMath on his Twitch channel.
  \begin{multicols}{2}
    \begin{mplibcode}
      input exemples/transformations/arbrePythagore-en.mp;
    \end{mplibcode}

    \lstinputlisting[basicstyle=\ttfamily\scriptsize]{exemples/transformations/arbrePythagore-en.mp}
  \end{multicols}
\end{landscape}

\newpage

\section{Historique}
\begin{description}
  \item[december 2025:] Added the \lstinline+EndWindow+ macro, added the
  center-based similarity macros \lstinline+CenterSimilarity+, added the
  “Pythagoras Tree” example, fixed bugs, and improved the documentation. 
  Use of \lstinline+withtransparency+ for the command \lstinline+gddAlphaFill+ when \mpgeomdd is used with \hologo{LuaTeX} and \package{luamplib}.Version 1.4.
  \item[may 2025:] translation into English of macros, documentation and examples.
\end{description}

\printbibliography
\addcontentsline{toc}{section}{Références}%Including it as a chapter
\printindex
\addcontentsline{toc}{section}{Index}%Including it as a chapter


\end{document}
