\documentclass[a4paper,11pt,leqno]{article}
\usepackage{amsmath}
\usepackage{color}
\usepackage{graphics}
\usepackage{bez123}
\usepackage{times}
\usepackage{mathptm}
\usepackage{mflogo}
\usepackage{url}

\begin{document}
\title{Drawing an elliptical arc using polylines, quadratic or cubic
B\'ezier curves}
\author{L. Maisonobe\thanks{luc@spaceroots.org}}
\date{July 21, 2003}
\maketitle
\tableofcontents
\clearpage

\section{Introduction}
When dealing with three dimensional geometry, one often needs to draw
some sketch with circles or arcs seen from an arbitrary point of
view. They appear as ellipses and arcs of ellipses when displayed on a
two dimensions plane such as paper or screen. The classical graphical
languages or libraries provide primitives for drawing several objects
like rectangles or circles. Lot of them can also handle ellipses, but
only when their axes are aligned with the device axes, and sometimes
only for complete ellipses (with the notable exception of SVG which
has two commands, \texttt{A} and \texttt{a}, to add a general ellipse
arc to the current path)

Hence, drawing these objects involve dealing with low level
graphics. An algorithm based on Bresenham's principles has been
published in the Foley and Van Dam book, it has been implemented by
Andrew W. Fitzgibbon in C++ and is available with the PC Games
Programmers Encyclopedia library (pcgpe) version
1.0\footnote{\url{ftp://x2ftp.oulu.fi/pub/msdos/programming/gpe/pcgpe10.zip}},
in the \texttt{conic.cc} file. The same file can be viewed
online\footnote{\url{http://www.flashdaddee.com/Books-Technical/win/Conics.htm}}.
Unfortunately, one needs both good starting and ending points,
i.e. exactly the same pixels the algorithm would have chosen by
itself. Failing to do this result in strange spiral-like
shapes. Another problem with such an algorithm is that it is at pixel
level only and do not handle dashes or line width.

Another method is to use intermediate level objects like polylines or
B\'ezier curves to approximate the ellipse. In this paper, we will
describe how this can be done, depending on the available primitives
and for any user defined accuracy.

Using these intermediate level curves has several advantages. The
first one is that the user can often use his own coordinate system and
use floating point numbers, he does not consider pixels at
all. Another advantage is that the graphical packages handles high
level features with such objects, like filling closed shapes, drawing
with various pens (both pen shape and pen size can be customized) and
drawing with various line styles (continuous lines, dashed lines with
several dash patterns). Since each object can contain a lot of
individual pixels, the description of the elliptical arc is also much
shorter than specifying each pixel individually. Of course, for a
given accuracy, polylines are less efficient than cubic B\'ezier
curves for example, so the description size will depend on the
available features of the underlying graphical package.

Three cases will be considered: lines (all graphical packages can
handle them), quadratic B\'ezier curves (available for example in
\LaTeXe) and cubic B\'ezier curves (available in \LaTeXe\ when the
\texttt{bez123} extension is loaded, \MF, PDF, PostScript, Java
\textsc{api}, \textsc{svg} ...).

The last version of this document is always available in the
spaceroots downloads page
\url{http://www.spaceroots.org/downloads.html}. It can be browsed
on-line or retrieved as a PDF, compressed PostScript or LaTeX source
file.

\section{Definitions}
\subsection{parametric curves}
A parametric curve is a curve which is defined by a two dimensional
equation $P$ of one parameter $t$. The two coordinates of the vector
$P(t)$ are the $x$ and $y$ coordinates of the point of the curve
corresponding to a particular value of the parameter.

One curve can be defined by several different parametric equations
like $P_1$ and $P_2$. This means that for each $t_1$ in the range of
the first equation, another value $t_2$ in the range of the second
equation can be found such that $P_1(t_1)=P_2(t_2)$. The relationship
between $t_1$ and $t_2$ can be either simple or very complex depending
on the equations. The $f$ function that transforms $t_1$ into $t_2$,
$t_2=f(t_1)$, is monotonic. If $t_2$ increases when $t_1$ increases,
the two equations define the same orientation for the curve, otherwise
they define opposite orientations.

\subsubsection{tangent}
The unit tangent vector can be computed from the first derivative of
the parametric equation: $\vec{T}=P'(t)/||P'(t)||$, which means its
coordinates are:

\begin{equation*}
\vec{T} \left\{\begin{aligned}
\frac{x'}{\sqrt{x'^2+y'^2}}\\
\frac{y'}{\sqrt{x'^2+y'^2}}
\end{aligned}\right.
\end{equation*}

This unit tangent vector is an intrinsic property of the curve, it is
independant of the parametric equations used as long as they define the
same orientation. If two different orientations are used, they will
define opposite unit tangent vectors.

\subsubsection{curvature}
The curvature of a curve is the inverse of the curvature radius. It is
null for a straight line (infinite curvature radius). For a parametric
curve, it can be computed from the first and second derivatives of the
defining equation:

\begin{equation*}
C = \frac{|x'y''-y'x''|}{(x'^2+y'^2)^{3/2}}
\end{equation*}
In fact, we will be more interested in the signed curvature, which we
define as being positive when the curve turns left and negative when
it turns right when following the curve in the direction of parameter
increase:

\begin{equation}\label{eqn:signed-curvature}
\widetilde{C} = \frac{x'y''-y'x''}{(x'^2+y'^2)^{3/2}}
\end{equation}
The signed curvature is also an intrinsic geometrical property of the
curve at the point considered, it is independant of the parametric
equations used as long as they define the same orientation. If two
different orientations are used, they will define opposite signed
curvatures.

\subsection{ellipse}
First, lets introduce some notations. Figure~\ref{fig:notations} shows
an arc and the ellipse it belongs to. The ellipse $\mathcal{E}$ is
defined by its center ($c_x$, $c_y$), its semi-major axis ($a$), its
semi-minor axis ($b$) and its orientation ($\theta$). The arc is
defined by its start and end angles ($\lambda_1$ and $\lambda_2$,
assuming $\lambda_1<\lambda_2\le\lambda_1+2\pi$). If $a=b$, then the
ellipse is a circle and the $\theta$ direction is irrelevant.

\begin{figure}[htbp]
\begin{center}\begin{minipage}{125mm}
\caption{\label{fig:notations}notations}
\setlength{\unitlength}{0.1mm}\begin{picture}(1250,720)
  \textcolor[gray]{0.5}{
    \put(0,150){\vector(1,0){1200}}\put(1210,170){\mbox{$x$}}
    \put(320,0){\vector(0,1){700}}\put(290,700){\mbox{$y$}}
  }%

  \textcolor[rgb]{0.13,0.55,0.13}{
    \put(100,60){\line(5,3){1000}}
    \put(720,160){\line(-3,5){240}}
    \put(702.9,188.5){\line(5,3){435}}
    \put(1028.75,617.25){\line(3,-5){107}}
    \put(1100,550){\mbox{$b$}}
    \put(920,290){\mbox{$a$}}
    \qbezier(400,150)(400,191.5)(378.6,227.2)
    \put(410,185){\mbox{$\theta$}}
    \put(992.95,595.77){\circle{10}}\put(992,565){\mbox{$F_2$}}
    \put(207.05,124.23){\circle{10}}\put(220,100){\mbox{$F_1$}}
  }%

  \put(600,150){\line(0,1){210}}\put(560,160){\mbox{$c_x$}}
  \put(320,360){\line(1,0){280}}\put(325,375){\mbox{$c_y$}}

  \textcolor[rgb]{0.15,0.13,0.73}{
    \put(910,680){\mbox{$P_1$}}
    \put(345,465){\mbox{$P_2$}}
    \qbezier(600,360)(770.65,513.11)(941.31,666.23)
    \qbezier(771.50,462.90)(761.65,479.31)(748.86,493.56)
    \put(770,490){\mbox{$\lambda_1$}}
    \qbezier(600,360)(491.465,406.98)(382.93,453.96)
    \qbezier(685.75,411.45)(654.33,463.81)(593.41,459.78)
    \qbezier(593.41,459.78)(532.48,455.76)(508.23,399.72)
    \put(600,470){\mbox{$\lambda_2$}}
    \cbezier(941.31,666.23)(806.01,686.85)(568.95,596.73)(382.93,453.96)
  }%

  \textcolor[rgb]{0.26,0.63,0.73}{
    \put(160,300){\mbox{$\mathcal{E}$}}
    \cbezier(382.93,453.96)(222.09,330.52)(134.74,194.84)(165.05,115.53)
    \cbezier(165.05,115.53)(195.35,36.21)(337.17,29.34)(518.79,98.38)
    \cbezier(518.79,98.38)(700.40,167.42)(885.01,298.39)(979.25,425.05)
    \cbezier(979.25,425.05)(1073.50,551.72)(1058.29,648.41)(941.31,666.23)
  }%

\end{picture}\end{minipage}\end{center}
\end{figure}

The two points $F_1$ and $F_2$ are the focii of the ellipse. The
distance between these points and the center of the ellipse is
$\sqrt{a^2-b^2}$. This means that with our notation, the coordinates
of these points are:

\begin{equation*}
F_1 \left\{\begin{gathered}
           c_x -\sqrt{a^2-b^2}\cos\theta\\
           c_y -\sqrt{a^2-b^2}\sin\theta
           \end{gathered}
    \right.
\qquad
F_2 \left\{\begin{gathered}
           c_x +\sqrt{a^2-b^2}\cos\theta\\
           c_y +\sqrt{a^2-b^2}\sin\theta
           \end{gathered}
    \right.
\end{equation*}

If the ellipse is a circle, then the two points $F_1$ and $F_2$ are
both at the center. These points have the following interesting
property:

\begin{equation}\label{eqn:focus-points}
d(P,F_1)+d(P,F_2) = 2a\quad\forall P \in \mathcal{E}
\end{equation}
This property is one classical way to define the ellipse.


\subsubsection{parametric equation}
The elliptical arc can be seen as a parametric curve, each point is
defined as an explicit vectorial function of one parameter $E(\eta)$
giving the two coordinates $x$ and $y$ of the point. We will use as a
parameter the $\eta$ angle computed such that:
\begin{align*}\label{eqn:lambda-eta}
&\left\{\begin{aligned}
r\cos\lambda &= a\cos\eta\\
r\sin\lambda &= b\sin\eta
\end{aligned}\right.\\
\Rightarrow&\left\{\begin{aligned}
\eta    &= \arctan_2\left(\frac{\sin\lambda}{b},\frac{\cos\lambda}{a}\right)\\
\lambda &= \arctan_2(b\sin\eta, a\cos\eta)
\end{aligned}\right.
\end{align*}

where $\lambda$ is the geometrical angle considered between one end of
the semi-major axis and the current point, counted from the center of
the ellipse (see $\lambda_1$ and $\lambda_2$ in the figure). This
$\eta$ angle is a theoretical angle, it has no representation on the
preceding figure (except if the ellipse is really a circle, of
course).

Using this angle, the ellipse parametric equation is:

\begin{equation}\label{eqn:E0}
E(\eta)\left\{\begin{gathered}
  c_x + a\cos\theta\cos\eta - b\sin\theta\sin\eta\\
  c_y + a\sin\theta\cos\eta + b\cos\theta\sin\eta
              \end{gathered}
       \right.
\end{equation}
The derivatives of the parametric curve are:

\begin{equation}\label{eqn:E1}
E'(\eta)\left\{\begin{gathered}
  -a\cos\theta\sin\eta - b\sin\theta\cos\eta\\
  -a\sin\theta\sin\eta + b\cos\theta\cos\eta
              \end{gathered}
       \right.
\end{equation}
and

\begin{equation}\label{eqn:E2}
E''(\eta)\left\{\begin{gathered}
  -a\cos\theta\cos\eta + b\sin\theta\sin\eta\\
  -a\sin\theta\cos\eta - b\cos\theta\sin\eta
              \end{gathered}
       \right.
\end{equation}

\subsection{B\'ezier curves}
B\'ezier curves are parametric polynomial\footnote{it is also possible
to define rational B\'ezier curves, however they are not widely
supported by graphical packages, so they will not be discussed here,
despite they allow to represent \emph{exactly} elliptical arcs} curves
that are widely used in graphical packages. They are often used to
approximate another curve, the match being perfect at both
endpoints. In order to match position, slope and curvature, a third
degree polynomial is needed, these are the classical B\'ezier curves
or cubic B\'ezier curves. If only position and slope need to match, a
second degree polynomial is sufficient, the corresponding curves are
quadratic B\'ezier curves. As an extension, we will also consider line
segments to be linear B\'ezier curves defined by a first degree
polynomial and matching only position of endpoints.

The polynomials underlying B\'ezier curves are very simple when their
constants are defined in terms of control points. These polynomials
are called Bernshte\u{\i}n polynomials. The range of the $t$ parameter
is between 0 and 1. When $t=0$, we are at the start point of the
B\'ezier curve which should match the start point of the approximated
curve. When $t=1$, we are at the end point of the B\'ezier curve which
should match the end point of the approximated curve. All graphical
packages that support B\'ezier curves define them by the control
points only, the Bernshte\u{\i}n polynomials are used internally and
are not available at user level.

\subsubsection{linear B\'ezier curves}
For linear B\'ezier curves, there are only two control points which
are the endpoints of the curve, $P_1$ and $P_2$. The Bernshte\u{\i}n
polynomial and its first derivatives are:
\begin{equation}\label{eqn:B1}
\left\{\begin{aligned}
B_1(t)   &= (1-t) P_1 + t P_2 \\
B_1'(t)  &= P_2 - P_1 \\
B_1''(t) &= 0
\end{aligned}\right.
\end{equation}
\begin{figure}[htbp]
\begin{center}\begin{minipage}{60mm}
\caption{\label{fig:linear-bezier}linear B\'ezier curve}
\setlength{\unitlength}{1mm}\begin{picture}(60,24)
\textcolor[rgb]{0.09,0.32,0.12}{
  \qbezier(10,10)(30,16)(50,22)
}%1
\textcolor[gray]{0.5}{
  \put(10,10){\circle{2}}\put(12,5){\mbox{$P_1$}}
  \put(50,22){\circle{2}}\put(52,20){\mbox{$P_2$}}
}%
\end{picture}
\end{minipage}\end{center}\end{figure}

\subsubsection{quadratic B\'ezier curves}
For quadratic B\'ezier curves, there are three control points. The
first two control points are the two endpoints of the curve, $P_1$ and
$P_2$. The last control point is an intermediate point $Q$ which
controls the direction of the tangents of the curve at both ends.
This point is generally away from the curve itself. The
Bernshte\u{\i}n polynomial and its first derivatives are:

\begin{equation}\label{eqn:B2}
\left\{\begin{aligned}
B_2(t)   &= (1-t)^2 P_1 + 2t(1-t) Q + t^2 P_2 \\
B_2'(t)  &= -2\left[(1-t) P_1 - (1-2t) Q - t P_2\right] \\
B_2''(t) &= 2\left[P_1 - 2 Q + P_2\right]
\end{aligned}\right.
\end{equation}

\begin{figure}[htbp]
\begin{center}\begin{minipage}{60mm}
\caption{\label{fig:quadratic-bezier}quadratic B\'ezier curve}
\setlength{\unitlength}{1mm}\begin{picture}(60,35)
\textcolor[rgb]{0.09,0.32,0.12}{
  \qbezier(10,10)(30,30)(50,10)
}%1
\textcolor[gray]{0.5}{
  \put(10,10){\line(1,1){20}}
  \put(30,30){\line(1,-1){20}}
  \put(10,10){\circle{2}}\put(12,7){\mbox{$P_1$}}
  \put(30,30){\circle{2}}\put(34,29){\mbox{$Q$}}
  \put(50,10){\circle{2}}\put(52,7){\mbox{$P_2$}}
}%
\end{picture}
\end{minipage}\end{center}\end{figure}

\subsubsection{cubic B\'ezier curves}
Cubic B\'ezier curves are the \emph{classical} B\'ezier curves, the
lower degree curves presented before should be seen as extensions
of classical B\'ezier curves to low degrees.

For cubic B\'ezier curves, there are four control points. The first
two are the two endpoints of the curve, $P_1$ and $P_2$. The two
remaining ones are intermediate points $Q_1$ and $Q_2$. These
intermediate points control the tangent and the curvature at both
ends. The Bernshte\u{\i}n polynomial and its first derivatives are:

\begin{equation}\label{eqn:B3}
\left\{\begin{aligned}
B_3(t)   &= (1-t)^3 P_1 + 3t(1-t)^2 Q_1 + 3t^2(1-t) Q_2 + t^3 P_2 \\
B_3'(t)  &= -3\left[(1-t)^2 P_1 - (1-t)(1-3t) Q_1 - t(2-3t) Q_2 - t^2 P_2\right] \\
B_3''(t) &= 6\left[(1-t) P_1 - (2-3t) Q_1 + (1-3t) Q_2 + t P_2\right]
\end{aligned}\right.
\end{equation}

\begin{figure}[htbp]
\begin{center}\begin{minipage}{60mm}
\caption{\label{fig:cubic-bezier}cubic B\'ezier curve}
\setlength{\unitlength}{1mm}\begin{picture}(60,25)
\textcolor[rgb]{0.09,0.32,0.12}{
  \cbezier(10,3)(20,23)(40,3)(50,23)
}%1
\textcolor[gray]{0.5}{
  \put(10,3){\line(1,2){10}}
  \put(40,3){\line(1,2){10}}
  \put(10,3){\circle{2}}\put(14,5){\mbox{$P_1$}}
  \put(20,23){\circle{2}}\put(21,20){\mbox{$Q_1$}}
  \put(40,3){\circle{2}}\put(34,5){\mbox{$Q_2$}}
  \put(50,23){\circle{2}}\put(43,20){\mbox{$P_2$}}
}%
\end{picture}
\end{minipage}\end{center}\end{figure}

\section{Approximation}
\subsection{principles}\label{sec:principles}

The approximation principle is very simple: replace the real
elliptical arc by a set of connected B\'ezier curves. The degree of
the curves (linear, quadratic or cubic) is chosen according to the
underlying graphical package and the number of curves and connecting
points are chosen according to the required accuracy. Each curve will
begin and end exactly on the elliptical arc.

We will describe algorithms to build B\'ezier curves matching an
elliptical arc at both ends, and algorithms to compute quickly an
upper bound of the approximation error for these curves. The
approximation error estimation algorithms will allow to compute the
error directly from the sub-arcs characteristics, without building the
B\'ezier curve beforehand. In the linear case also, the exact error
will be computed rather than an upper bound.

A simple iterative process can be used to build the appropriate curves
set. Simply compute the error which would result from splitting the
arc into $1$, $2$, $4$ $\ldots$ $2^{n}$ equal lengths parts in terms
of the curve parameter $\eta$, and stop the loop when this error drops
below the user-defined threshold. Then, build the corresponding
$2^{n}$ B\'ezier curves.

This process is not optimal in the sense that it can split the arc in
more parts than strictly needed. However it is very simple to
implement and very fast. Also since the error decreases a lot as the
arc length decreases, very few iterations will be needed in practical
cases.

\subsection{linear B\'ezier curve}\label{sec:linear-algorithms}
\subsubsection{control points choice}\label{sec:linear-points-choice}
Finding the two control points of the quadratic B\'ezier curve is
trivial, since we want the B\'ezier curve endpoints to match the
elliptical arc endpoints:

\begin{align*}
B_1(0) &= E(\eta_1) \Rightarrow P_1 = E(\eta_1)\\
B_1(1) &= E(\eta_2) \Rightarrow P_2 = E(\eta_2)
\end{align*}

\begin{center}
\framebox[0.86\textwidth]{\parbox{0.81\textwidth}{%
\vspace{2ex}The control points $P_1$ and $P_2$ of a linear B\'ezier
curve approximating an elliptical arc should be chosen as follows:
\begin{align*}
P_1 &= E(\eta_1)\\
P_2 &= E(\eta_2)
\end{align*}
}}
\end{center}

\subsubsection{error estimation}\label{sec:linear-error}
Since the ellipse curve always has a positive curvature and since the
linear B\'ezier curve is a straight line, the distance between the
ellipse and its approximation is null at both arc ends and reaches its
maximal value for one point $E(\eta)$ between the endpoints. At this
point, the tangent to the ellipse is parallel to the line, as depicted
in figure~\ref{fig:linear-error}.

\begin{figure}[htbp]
\begin{center}\begin{minipage}{70mm}
\caption{\label{fig:linear-error}error of a linear approximation}
\setlength{\unitlength}{0.1mm}\begin{picture}(700,510)
  \textcolor[rgb]{0.15,0.13,0.73}{
    \put(530,30){\circle{20}}
    \put(120,440){\circle{20}}
    \qbezier(530,30)(540,160)(390,310)
    \qbezier(390,310)(280,420)(120,440)
    \put(550,40){\mbox{$E(\eta_1)$}}
    \put(100,460){\mbox{$E(\eta_2)$}}
    \put(400,320){\mbox{$E(\eta)$}}
    \put(390,310){\vector(-1,1){100}}
  }%

  \textcolor[gray]{0.5}{
    \put(530,30){\line(-1,1){410}}
  }%

  \textcolor[rgb]{0.13,0.55,0.13}{
    \put(360,280){\vector(-1,-1){40}}
    \put(350,270){\vector(1,1){40}}
    \put(325,285){\mbox{$\varepsilon_1$}}
  }%

\end{picture}\end{minipage}\end{center}
\end{figure}

Using the ellipse parametric equation (\ref{eqn:E0}) and its
derivative (\ref{eqn:E1}), we can find $\eta$:
\begin{align*}
&\det\big(E'(\eta),E(\eta_2)-E(\eta_1)\big)=0\\
\Leftrightarrow&x'_\eta\big(y_2-y_1\big)-y'_\eta\big(x_2-x_1\big)=0\\
\Leftrightarrow
&-ab \big(\cos\eta (\cos\eta_2-\cos\eta_1)+\sin\eta (\sin\eta_2-\sin\eta_1)\big)=0\\
\Leftrightarrow
&\cos(\eta_2-\eta)=\cos(\eta-\eta_1)\\
\Leftrightarrow
&\eta_1=\eta_2\quad\text{or}\quad\eta=\frac{\eta_1+\eta_2}{2}\\
\end{align*}
where $x'_\eta$ and $y'_\eta$ are the coordinates of $E'(\eta)$ and
$x_i$ and $y_i$ are the coordinates of $E(\eta_i)$.

Obviously, the second solution is the one we were looking for. Given
this value of $\eta$, we compute the error $\varepsilon$ as the
distance between $E(\eta)$ (coordinates $x_\eta$ and $y_\eta$) and the
line passing through $E(\eta_1)$ and $E(\eta_2)$.

\begin{center}
\framebox[0.8\textwidth]{\parbox{0.75\textwidth}{%
\vspace{2ex}The error resulting from the approximation of an ellipse
arc by a linear B\'ezier curve is:
\begin{align*}
\varepsilon_1&=\frac{|x_\eta(y_2-y_1)-y_\eta(x_2-x_1)+x_2y_1-x_1y_2|}
                    {\sqrt{(x_2-x_1)^2+(y_2-y_1)^2}}
\intertext{where}
\eta&=\frac{\eta_1+\eta_2}{2}
\end{align*}}}
\end{center}

\subsection{quadratic B\'ezier curve}\label{sec:quadratic-algorithms}
\subsubsection{control points choice}\label{sec:quadratic-points-choice}
Since we want the B\'ezier curve endpoints to match the elliptical arc
endpoints, finding the first two control points of the quadratic
B\'ezier curve is done as for linear B\'ezier curves, :

\begin{align*}
B_2(0) &= E(\eta_1) \Rightarrow P_1 = E(\eta_1)\\
B_2(1) &= E(\eta_2) \Rightarrow P_2 = E(\eta_2)
\end{align*}
Matching of the B\'ezier curve and elliptical arc slopes at start
point allows us to define the remaining control point using one scalar
parameter:

\begin{equation*}
B_2'(0) = k E'(\eta_1) \Rightarrow 2(Q - P_1) = k E'(\eta_1)\\
\end{equation*}
In order to have the same orientation for the elliptical arc and its
approximation, $k$ should be positive. Replacing $k$ by $\alpha=k/2$
leads to the simple definition of $Q$:

\begin{equation*}
Q = P_1 + \alpha E'(\eta_1) \qquad \alpha > 0
\end{equation*}

We find $\alpha$ by stating the B\'ezier curve slope should also match
the arc slope at end point:
\begin{align*}
&B_2'(1) = \tilde{k} E'(\eta_2)\\
\Rightarrow &2(P_2 - Q) = \tilde{k} E'(\eta_2)\\
 \Rightarrow &\det\left(P_2-P_1-\alpha E'(\eta_1),E'(\eta_2)\right)=0\\
\Rightarrow &(x_2-x_1-\alpha x'_1)y'_2-(y_2-y_1-\alpha y'_1)x'_2=0\\
\Rightarrow &\alpha=\frac{(x_2-x_1)y'_2-(y_2-y_1)x'_2}{x'_1y'_2-y'_1x'_2}\\
\Rightarrow &\alpha=\frac{1-\cos(\eta_2-\eta_1)}{\sin(\eta_2-\eta_1)}\\
\Rightarrow &\alpha=\tan\left(\frac{\eta_2-\eta_1}{2}\right)\\
\intertext{where $x'_{\eta_i}$ and $y'_{\eta_i}$ are the coordinates
of $E'(\eta_i)$. It is easy to verify that this also implies the
symmetrical expression:} &Q
= P_2 - \tan\left(\frac{\eta_2-\eta_1}{2}\right)E'(\eta_2)
\end{align*}

If we have preprocessed our arcs to ensure
$\eta1<\eta_2\le\eta_1+\pi/2$, we know that $0<=\alpha<=1$. This
implies that the orientation is right at both endpoints and also that
$\alpha$ can be computed without loss of
accuracy. Equations~(\ref{eqn:E0}) and (\ref{eqn:E1}) show that both
$E(\eta)$ and $E'(\eta)$ are bounded by $a$, so this preprocessing
also ensures $Q$ does not escape far away from points $P_1$ and $P_2$
(this could generate numerical overflows in some graphical packages).

\begin{center}
\framebox[0.8\textwidth]{\parbox{0.75\textwidth}{%
\vspace{2ex}The control points $P_1$, $Q$ and $P_2$ of a quadratic
B\'ezier curve approximating an elliptical arc should be chosen as
follows:
\begin{align*}
P_1 &= E(\eta_1)\\
P_2 &= E(\eta_2)\\
Q   &= P_1 + \tan\left(\frac{\eta_2-\eta_1}{2}\right) E'(\eta_1)\\
\intertext{which is equivalent to}
Q   &= P_2 - \tan\left(\frac{\eta_2-\eta_1}{2}\right) E'(\eta_2)
\end{align*}
}}
\end{center}

\subsubsection{error estimation}\label{sec:quadratic-error}

Since both the arc and the approximation can be described by
parametric equations $B_2(t)$ and $E(\eta)$, we could try to find for
each point $B_2(t)$ the closest point $E(\eta_t)$ such that
$d\left(B_2(t),E(\eta_t)\right) =
\min_{\eta}\{d\left(B_2(t),E(\eta)\right)\}$ and to use this
$t\leftrightarrow\eta_t$ mapping to find the maximal error along the
elliptical arc $\varepsilon_2 =
\max_t\{d\left(B_2(t),E(\eta_t)\right)\}$. This method is accurate,
but involves lots of computation. A more practical method consist in
building once and for all an analytical model
$\tilde{\varepsilon}_2(a, b, \eta_1,\eta_2)$ approximating
$\varepsilon_2$ and use it.

We first compute the true error by embedding two equation solvers. The
first solver is used to compute $\eta_{t}$ for any given $t$ (in other
words it performs the mapping), using a specific algorithm described
in another paper. The second solver is used to find the value of the
$t$ parameter which leads to the maximal error. It is necessary to use
very robust algorithms for this purpose, because the notion of
\emph{closest point} is not continuous, so $\eta_{t}$ seen as a
function of $t$ is not continuous. A trivial example is given by a
point $P(t)$ traveling along the minor axis. When this point crosses
the ellipse center, $\eta_{t}$ jumps from $-\pi/2$ to $+\pi/2$. The
\emph{distance} to the closest point, however, is continuous, only its
first derivative is discontinuous. These embedded solvers allow us to
compute for $\varepsilon_2$ for any arc, its value depend on $a$, $b$,
$\eta_1$ and $\eta2$.

The next step involves identifying the behaviour of the error when the
various parameters change. Using the semi major axis as a scaling
parameter and plotting some curves, we first identify canonical
parameters: the error model will be :
\begin{equation}\label{eqn:error-model}
\tilde{\varepsilon}_2 = a \times f(b/a,\eta,\Delta\eta)
\end{equation}
where
\begin{equation*}
\eta=\frac{\eta_1+\eta_2}{2}
\quad\text{and}\quad
\Delta\eta=\eta_2-\eta_1
\end{equation*}

For $\Delta\eta$ between $1/20$ and $\pi/2$, the error appears to be
almost a power of $\Delta\eta$, so we refine our model:
\begin{equation}\label{eqn:scaled-error-model}
f(b/a,\eta,\Delta\eta) = e^{c_0(b/a,\eta)+ c_1(b/a,\eta)\Delta\eta}
\end{equation}
This behaviour seems to be valid also outside of the given interval.
However, if $\Delta\eta$ gets too small, some numerical problems
prevent from computing accurately the very tiny real errors. This
interval should be compliant with classical needs.

For symmetry reasons, it is sufficient to study the behaviour of the
origin and slope functions $c_0$ and $c_1$ for $\eta$ between $0$ and
$\pi/2$. The functions decrease from a maximum value at $0$ to a
minimum value at $\pi/2$. The peak near the maximum can be very sharp
for flat ellipses ($b\ll a$). This is because the curvature is very
important and changes rapidly near the semi major axis ends. We will
use several functions $\cos(2k\eta)$ to represent this behaviour. Our
model becomes:
\begin{equation}\label{eqn:origin-slope-decomposition}
c_i(b/a,\eta) = \sum_{j=0}^{j=3}r_{i,j}(b/a)\cos(2j\eta)
\end{equation}

Finally, the coefficients functions $r_{k,i}$ present various
asymptotic behaviours when $b/a$ varies from 0 to 1. In order to get a
good fit, we describe the functions as rational functions with a
quadratic numerator and linear denominator:
\begin{equation}\label{eqn:harmonic-coefficients-decomposition}
r_{i,j}(b/a)= \frac{\mu_{i,j,0}\left(\frac{b}{a}\right)^2
                   +\mu_{i,j,1}\left(\frac{b}{a}\right)
                   +\mu_{i,j,2}}
                   {\left(\frac{b}{a}\right)+\mu_{i,j,3}}
\end{equation}

In fact, two sets of $\mu_{i,j,k}$ coefficients were used, one set for
$b/a$ between $0$ and $1/4$, and one set for $b/a$ between $1/4$ and
$1$. The coefficients are given by
tables~\ref{table:coeffs-quadratic-low} and
\ref{table:coeffs-quadratic-high}.

These coefficients were computed by curve fitting means. This imply
that for some points $(b/a,\eta,\Delta\eta)$ this model gives errors
larger than the real ones, and at other points it gives smaller errors
($\varepsilon_{2,\text{min}} \le \tilde{\varepsilon}_2 \le
\varepsilon_{2,\text{max}}$).  Multiplying this least square model by
a suitable safety rational fraction $s(b/a)$, we obtain an upper bound
of the error: $\varepsilon_2 \le s(b/a)\tilde{\varepsilon}_2$.

\begin{center}
\framebox[0.9\textwidth]{\parbox{0.85\textwidth}{%
\vspace{2ex}The error resulting from the approximation of an ellipse arc by a
quadratic B\'ezier curve is bounded as follows:
\begin{align*}
\varepsilon_2 &\le \left(\frac{0.02\left(\frac{b}{a}\right)^2
                   +2.83\left(\frac{b}{a}\right)
                   +0.125
                   }{\left(\frac{b}{a}\right)+0.01}\right)
              a e^{c_0+ c_1(\eta_2-\eta_1)}\\
\intertext{where}
c_i &= \sum_{j=0}^{j=3}
                 \frac{\mu_{i,j,0}\left(\frac{b}{a}\right)^2
                   +\mu_{i,j,1}\left(\frac{b}{a}\right)
                   +\mu_{i,j,2}}
                   {\left(\frac{b}{a}\right)+\mu_{i,j,3}}\cos\big(j(\eta_1+\eta_2)\big)\\
\end{align*}
and the $\mu_{i,j,k}$ coefficients are given by
tables~\ref{table:coeffs-quadratic-low} and
\ref{table:coeffs-quadratic-high}}}%
\end{center}
 
This bound correctly overestimates the error, but is not too
conservative. The cumulative distribution function of
$\varepsilon_2/(s(b/a)\tilde{\varepsilon}_2)$ is quite smooth and the
mean value of the ratio is $0.538$.

\begin{table}[p]
\caption{error coefficients for quadratic B\'ezier $(0 < b/a < 1/4)$}
\label{table:coeffs-quadratic-low}
\begin{center}\begin{tabular}{|c|c||c|c|c|c|}
\hline
$i$ & $j$ & $\mu_{i,j,0}$ & $\mu_{i,j,1}$ & $\mu_{i,j,2}$ & $\mu_{i,j,3}$ \\
\hline
\hline
0 & 0 &  3.92478   & -13.5822    & -0.233377    & 0.0128206   \\
0 & 1 & -1.08814   &   0.859987  &  0.000362265 & 0.000229036 \\
0 & 2 & -0.942512  &   0.390456  &  0.0080909   & 0.00723895  \\
0 & 3 & -0.736228  &   0.20998   &  0.0129867   & 0.0103456   \\
\hline
1 & 0 & -0.395018  &   6.82464   &  0.0995293   & 0.0122198   \\
1 & 1 & -0.545608  &   0.0774863 &  0.0267327   & 0.0132482   \\
1 & 2 &  0.0534754 &  -0.0884167 &  0.012595    & 0.0343396   \\
1 & 3 &  0.209052  &  -0.0599987 & -0.00723897  & 0.00789976  \\
\hline
\end{tabular}\end{center}
\end{table}

\begin{table}[p]
\caption{error coefficients for quadratic B\'ezier $(1/4 \le b/a \le 1)$}
\label{table:coeffs-quadratic-high}
\begin{center}\begin{tabular}{|c|c||c|c|c|c|}
\hline
$i$ & $j$ & $\mu_{i,j,0}$ & $\mu_{i,j,1}$ & $\mu_{i,j,2}$ & $\mu_{i,j,3}$ \\
\hline
\hline
0 & 0 &  0.0863805 & -11.5595    & -2.68765   &  0.181224   \\
0 & 1 &  0.242856  &  -1.81073   &  1.56876   &  1.68544    \\
0 & 2 &  0.233337  &  -0.455621  &  0.222856  &  0.403469   \\
0 & 3 &  0.0612978 &  -0.104879  &  0.0446799 &  0.00867312 \\
\hline
1 & 0 &  0.028973  &   6.68407   &  0.171472  &  0.0211706  \\
1 & 1 &  0.0307674 &  -0.0517815 &  0.0216803 & -0.0749348  \\
1 & 2 & -0.0471179 &   0.1288    & -0.0781702 &  2.0        \\
1 & 3 & -0.0309683 &   0.0531557 & -0.0227191 &  0.0434511  \\
\hline
\end{tabular}\end{center}
\end{table}

\clearpage
\subsection{cubic B\'ezier curve}\label{sec:cubic-algorithms}
\subsubsection{control points choice}\label{sec:cubic-points-choice}
Since we want the B\'ezier curve endpoints to match the elliptical arc
endpoints, finding the first two control points of the cubic B\'ezier
curve is done as for linear B\'ezier curves:

\begin{align*}
B_3(0) &= E(\eta_1) \Rightarrow P_1 = E(\eta_1)\\
B_3(1) &= E(\eta_2) \Rightarrow P_2 = E(\eta_2)
\end{align*}
Matching of the B\'ezier curve and elliptical arc slopes at endpoints
allows us to define the two remaining control points using only two
scalar parameters:

\begin{align*}
B_3'(0) &= k_1 E'(\eta_1) \Rightarrow 3(Q_1 - P_1) = k_1 E'(\eta_1)\\
B_3'(1) &= k_2 E'(\eta_2) \Rightarrow 3(P_2 - Q_2) = k_2 E'(\eta_2)
\end{align*}
In order to have the same orientation for the elliptical arc and its
approximation, $k_1$ and $k_2$ should both be positive. Replacing the
$k_1$ and $k_2$ scalars by $\alpha_1=k_1/3$ and $\alpha_2=k_2/3$ leads
to the simple definition of $Q_1$ and $Q_2$:

\begin{align*}
Q_1 &= P_1 + \alpha_1 E'(\eta_1) \qquad \alpha_1 > 0\\
Q_2 &= P_2 - \alpha_2 E'(\eta_2) \qquad \alpha_2 > 0
\end{align*}
With these definitions of the control points, the first and second
derivatives of the B\'ezier curves are:

\begin{xalignat*}{2}
B_3'(0)  &= 3(Q_1 - P_1)
         &= &\phantom{-}3\alpha_1 E'(\eta_1)\\
B_3''(0) &= 6[Q_2-2Q_1+P_1]
         &= &\phantom{-}6[E(\eta_2) - E(\eta_1) - 2 \alpha_1 E'(\eta_1) - \alpha_2 E'(\eta_2)]\\
B_3'(1)  &= 3(P_2 - Q_2)
         &= &\phantom{-}3\alpha_2 E'(\eta_2)\\
B_3''(1) &= 6[P_2-2Q_2+Q_1]
         &= &-6[E(\eta_2) - E(\eta_1) - \alpha_1 E'(\eta_1) - 2 \alpha_2 E'(\eta_2)]
\end{xalignat*}
introducing these derivatives in equation~(\ref{eqn:signed-curvature})
gives the signed curvatures at B\'ezier curve endpoints:

\begin{equation}
\label{eqn:cubic-bezier-curvature}\left\{\begin{aligned}
\widetilde{C}_B(0) &=
\frac{2 [x'_1(y_2 - y_1) - y'_1(x_2 - x_1)]
      + 2 \alpha_2 [x'_2 y'_1 - x'_1 y'_2]}
     {3 \alpha_1^2 ({x'_1}^2+{y'_1}^2)^{3/2}} \\
\widetilde{C}_B(1) &=
\frac{-2 [x'_2(y_2 - y_1) - y'_2(x_2 - x_1)]
      +2 \alpha_1 [x'_2 y'_1 - x'_1 y'_2]}
     {3 \alpha_2^2 ({x'_2}^2+{y'_2}^2)^{3/2}} \\
\end{aligned}\right.
\end{equation}

The curvatures of the elliptical arc at endpoints are computed the
same way, introducing the ellipse parametric equation
derivatives~(\ref{eqn:E1}) and (\ref{eqn:E2}) into
equation~(\ref{eqn:signed-curvature}):

\begin{equation}
\label{eqn:elliptical-arc-curvature}\left\{\begin{aligned}
\widetilde{C}_E(\eta_1) &=
\frac{x'_1 y''_1 - y'_1 x''_1}{({x'_1}^2+{y'_1}^2)^{3/2}} \\
\widetilde{C}_E(\eta_2) &=
\frac{x'_2 y''_2 - y'_2 x''_2}{({x'_2}^2+{y'_2}^2)^{3/2}}
\end{aligned}\right.
\end{equation}
where $x''_{\eta_i}$ and $y''_{\eta_i}$ are the coordinates of $E''(\eta_i)$.

In order to find the values of $\alpha_1$ and $\alpha_2$, we state
that the signed curvature of the B\'ezier curve and elliptical arc at
endpoints should be the same, so we combine
systems~(\ref{eqn:cubic-bezier-curvature}) and
(\ref{eqn:elliptical-arc-curvature}):
\begin{equation*}
\left\{
\begin{aligned}
2 [x'_1(y_2 - y_1) - y'_1(x_2 - x_1)]
+ 2 \alpha_2 [x'_2 y'_1 - x'_1 y'_2]
- 3 \alpha_1^2 [x'_1 y''_1 - y'_1 x''_1] &= 0\\
-2 [x'_2(y_2 - y_1) - y'_2(x_2 - x_1)]
+2 \alpha_1 [x'_2 y'_1 - x'_1 y'_2]
-3 \alpha_2^2 [x'_2 y''_2 - y'_2 x''_2] &= 0
\end{aligned}\right.
\end{equation*}

This system can be further simplified by using the ellipse parametric
equation~(\ref{eqn:E0}) and its derivatives~(\ref{eqn:E1}) and
(\ref{eqn:E2}) which imply the following relations:

\begin{equation*}
\left\{\begin{aligned}
x'_1(y_2 - y_1) - y'_1(x_2 - x_1) &= \phantom{-}a b (1-\cos(\eta_2-\eta_1))\\
x'_2 y'_1 - x'_1 y'_2 &= - a b \sin(\eta_2-\eta_1)\\
x'_1 y''_1 - y'_1 x''_1 &= \phantom{-}a b\\
x'_2(y_2 - y_1) - y'_2(x_2 - x_1) &= -ab (1-\cos(\eta_2-\eta_1))\\
x'_2 y''_2 - y'_2 x''_2 &= \phantom{-}a b
\end{aligned}\right.
\end{equation*}
So after simplifying by $a b$, the system becomes:

\begin{equation*}
\left\{\begin{aligned}
2(1-\cos(\eta_2-\eta_1)) - 2\alpha_2\sin(\eta_2-\eta_1) - 3\alpha_1^2 = 0 \\
2(1-\cos(\eta_2-\eta_1)) - 2\alpha_1\sin(\eta_2-\eta_1) - 3\alpha_2^2 = 0
\end{aligned}\right.
\end{equation*}
Introducing $\tau=\tan\left(\frac{\eta_2-\eta_1}{2}\right)$ and
multiplying by $1+\tau^2$ this can be written:

\begin{equation*}
\left\{\begin{aligned}
4\tau^2 - 4\tau\alpha_2 - 3(1+\tau^2)\alpha_1^2 = 0 \\
4\tau^2 - 4\tau\alpha_1 - 3(1+\tau^2)\alpha_2^2 = 0
\end{aligned}\right.
\end{equation*}
Subtracting one equation from the other, we obtain:

\begin{equation*}
(\alpha_2-\alpha_1) \big(3(1+\tau^2)(\alpha_1 +\alpha_2) - 4\tau\big) = 0
\end{equation*}
This implies the system has two sets of solutions. Since we have
preprocessed our arcs to ensure $\eta1<\eta_2\le\eta_1+\pi/2$, we know
that $0<=\tau<=1$, so $\tau$ can be computed without loss of accuracy
and $\tau^2$ can be extracted from square roots without sign
change. The first set of solutions is:

\begin{align*}
&\left\{\begin{aligned}
  &\alpha_2 = \alpha_1\\
  &3(1+\tau^2)\alpha_1^2 + 4\tau \alpha_1 - 4\tau^2 = 0
\end{aligned}\right.\\
\Rightarrow
&\left\{\begin{aligned}
  &\alpha_1 = \left(\frac{2\tau}{1+\tau^2}\right)\left(\frac{-1\pm\sqrt{4+3\tau^2}}{3}\right)\\
  &\alpha_2 = \left(\frac{2\tau}{1+\tau^2}\right)\left(\frac{-1\pm\sqrt{4+3\tau^2}}{3}\right)
\end{aligned}\right.\\
\intertext{and the second set is:}
&\left\{\begin{aligned}
  &\alpha_2 = \frac{4\tau}{3(1+\tau^2)}-\alpha_1\\
  &3(1+\tau^2)\alpha_1^2 - 4\tau \alpha_1 + \frac{4\tau^2(1-3\tau^2)}{3(1+\tau^2)} = 0
\end{aligned}\right.\\
\Rightarrow
&\left\{\begin{aligned}
  &\alpha_1 = \left(\frac{2\tau}{1+\tau^2}\right)\left(\frac{1\pm \tau\sqrt{3}}{3}\right)\\
  &\alpha_2 = \left(\frac{2\tau}{1+\tau^2}\right)\left(\frac{1\mp \tau\sqrt{3}}{3}\right)
\end{aligned}\right.
\end{align*}
It is obvious that all these solutions are real ones. For the first
set of solutions it is also obvious that one solution is always
positive while the other one is always negative. Remembering we are
only interested in positive solutions, we can choose the positive one.
For the second set of solutions, one solution becomes negative or null
when $\tau\ge1/\sqrt{3}$, i.e. if $\eta_2-\eta_1\ge\frac{\pi}{3}$.

The full set of positive solutions is therefore:
\begin{equation}
\left\{\begin{aligned}
\alpha_1&=
\sin(\eta_2-\eta_1)
\frac{\sqrt{4+3\tan^2\left(\frac{\eta_2-\eta_1}{2}\right)}-1}{3}\\
\alpha_2&=
\sin(\eta_2-\eta_1)
\frac{\sqrt{4+3\tan^2\left(\frac{\eta_2-\eta_1}{2}\right)}-1}{3}\\
\end{aligned}\right.
\end{equation}
or (only if $\eta_2-\eta_1<\frac{\pi}{3}$):

\begin{equation}
\left\{\begin{aligned}
\alpha_1&=
\sin(\eta_2-\eta_1)
\frac{1+\tan\left(\frac{\eta_2-\eta_1}{2}\right)\sqrt{3}}{3}\\
\alpha_2&=
\sin(\eta_2-\eta_1)
\frac{1-\tan\left(\frac{\eta_2-\eta_1}{2}\right)\sqrt{3}}{3}
\end{aligned}\right.
\end{equation}
or (only if $\eta_2-\eta_1<\frac{\pi}{3}$):

\begin{equation}
\left\{\begin{aligned}
\alpha_1&=
\sin(\eta_2-\eta_1)
\frac{1-\tan\left(\frac{\eta_2-\eta_1}{2}\right)\sqrt{3}}{3}\\
\alpha_2&=
\sin(\eta_2-\eta_1)
\frac{1+\tan\left(\frac{\eta_2-\eta_1}{2}\right)\sqrt{3}}{3}
\end{aligned}\right.
\end{equation}

Some tests show that all these solutions are acceptable, there is not
a unique way to set up a cubic B\'ezier curve with the matching
criteria we have chosen. Since the first solution is both the simplest
one ($\alpha_1 = \alpha_2$) and has the wider applicability domain, we
will use this one only and forget the other solutions.

\begin{center}
\framebox[0.84\textwidth]{\parbox{0.8\textwidth}{%
\vspace{2ex}The control points $P_1$, $Q_1$, $Q_2$ and $P_2$ of a
cubic B\'ezier curve approximating an elliptical arc should be chosen
as follows:
\begin{align*}
P_1 &= E(\eta_1)\\
P_2 &= E(\eta_2)\\
Q_1 &= P_1 + \alpha E'(\eta_1)\\
Q_2 &= P_2 - \alpha E'(\eta_2)\\
\intertext{where}
\alpha&=\sin(\eta_2-\eta_1)
       \frac{\sqrt{4+3\tan^2\left(\frac{\eta_2-\eta_1}{2}\right)}-1}{3}
\end{align*}
}}
\end{center}

\subsubsection{error estimation}\label{sec:cubic-error}

The method used to estimate the error of cubic B\'ezier is exactly the
same as the one explained in section~\ref{sec:quadratic-error} for
quadratic B\'ezier curves. The coefficients are given by
tables~\ref{table:coeffs-cubic-low} and \ref{table:coeffs-cubic-high}.

As before, we introduce a safety rational fraction $s(b/a)$ to obtain
an upper bound of the error: $\varepsilon_3\le
s(b/a)\tilde{\varepsilon}_3$.

\begin{center}
\framebox[0.9\textwidth]{\parbox{0.85\textwidth}{%
\vspace{2ex}The error resulting from the approximation of an ellipse
arc by a cubic B\'ezier curve is bounded as follows:
\begin{align*}
\varepsilon_3 &\le \left(\frac{0.001\left(\frac{b}{a}\right)^2
                   +4.98\left(\frac{b}{a}\right)
                   +0.207
                   }{\left(\frac{b}{a}\right)+0.0067}\right)
              a e^{c_0+ c_1(\eta_2-\eta_1)}\\
\intertext{where}
c_i &= \sum_{j=0}^{j=3}
                 \frac{\mu_{i,j,0}\left(\frac{b}{a}\right)^2
                   +\mu_{i,j,1}\left(\frac{b}{a}\right)
                   +\mu_{i,j,2}}
                   {\left(\frac{b}{a}\right)+\mu_{i,j,3}}\cos\big(j(\eta_1+\eta_2)\big)\\
\end{align*}
Where the $\mu_{i,j,k}$ coefficients are given by
tables~\ref{table:coeffs-cubic-low} and \ref{table:coeffs-cubic-high}.
}}
\end{center}

This bound correctly overestimates the error, but is not too
conservative, the cumulative distribution function of
$\varepsilon/(s(b/a)\tilde{\varepsilon})$ is quite smooth and the
corresponding mean value is $0.623$.

\begin{table}[p]
\caption{error coefficients for cubic B\'ezier $(0 < b/a < 1/4)$}
\label{table:coeffs-cubic-low}
\begin{center}\begin{tabular}{|c|c||c|c|c|c|}
\hline
$i$ & $j$ & $\mu_{i,j,0}$ & $\mu_{i,j,1}$ & $\mu_{i,j,2}$ & $\mu_{i,j,3}$ \\
\hline
\hline
0 & 0 &  3.85268   & -21.229      & -0.330434   & 0.0127842  \\
0 & 1 & -1.61486   &   0.706564   &  0.225945   & 0.263682   \\
0 & 2 & -0.910164  &   0.388383   &  0.00551445 & 0.00671814 \\
0 & 3 & -0.630184  &   0.192402   &  0.0098871  & 0.0102527  \\
\hline
1 & 0 & -0.162211  &   9.94329    &  0.13723    & 0.0124084  \\
1 & 1 & -0.253135  &   0.00187735 &  0.0230286  & 0.01264    \\
1 & 2 & -0.0695069 &  -0.0437594  &  0.0120636  & 0.0163087  \\
1 & 3 & -0.0328856 &  -0.00926032 & -0.00173573 & 0.00527385 \\
\hline
\end{tabular}\end{center}
\end{table}

\begin{table}[p]
\caption{error coefficients for cubic B\'ezier $(1/4 \le b/a \le 1)$}
\label{table:coeffs-cubic-high}
\begin{center}\begin{tabular}{|c|c||c|c|c|c|}
\hline
$i$ & $j$ & $\mu_{i,j,0}$ & $\mu_{i,j,1}$ & $\mu_{i,j,2}$ & $\mu_{i,j,3}$ \\
\hline
\hline
0 & 0 &  0.0899116 & -19.2349    & -4.11711    &  0.183362   \\
0 & 1 &  0.138148  &  -1.45804   &  1.32044    &  1.38474    \\
0 & 2 &  0.230903  &  -0.450262  &  0.219963   &  0.414038   \\
0 & 3 &  0.0590565 &  -0.101062  &  0.0430592  &  0.0204699  \\
\hline
1 & 0 &  0.0164649 &   9.89394   &  0.0919496  &  0.00760802 \\
1 & 1 &  0.0191603 &  -0.0322058 &  0.0134667  & -0.0825018  \\
1 & 2 &  0.0156192 &  -0.017535  &  0.00326508 & -0.228157   \\
1 & 3 & -0.0236752 &   0.0405821 & -0.0173086  &  0.176187   \\
\hline
\end{tabular}\end{center}
\end{table}

\clearpage\section{Implementation}
An implementation in the Java language of the algorithms explained in
this paper is available in source form as a stand-alone file at
\url{http://www.spaceroots.org/documents/ellipse/EllipticalArc.java}.

It is designed as an implementation of the \texttt{java.awt.Shape}
interface and can therefore be drawn easily as any of the more
traditional shapes provided by the standard Java API.

This class differs from the \texttt{java.awt.geom.Ellipse2D} in the
fact it can handles parts of ellipse in addition to full ellipses and
it can handle ellipses which are not aligned with the x and y
reference axes of the plane.

Another improvement is that this class can handle degenerated cases
like for example very flat ellipses (semi-minor axis much smaller than
semi-major axis) and drawing of very small parts of such ellipses at
very high magnification scales. This imply monitoring the drawing
approximation error for extremely small values. Such cases occur for
example while drawing orbits of comets near the perihelion.

When the arc does not cover the complete ellipse, the lines joining
the center of the ellipse to the endpoints can optionally be included
or not in the outline, hence allowing to use it for pie-charts
rendering. If these lines are not included, the curve is not naturally
closed.

\end{document}
