Submission time
[ipdf/sam.git] / chapters / Background_Spline.tex
1
2 Splines are continuous curves formed from piecewise polynomial segments. A polynomial of $n$th degree is defined by $n$ constants $\{a_0, a_1, ... a_n\}$ and:
3 \begin{align}
4         y(x) &= \displaystyle\sum_{k=0}^n a_k x^k
5 \end{align}
6
7  \begin{comment}
8 Splines may be rasterised by sampling of $y(x)$ at a number of points $x_i$ and drawing straight lines between  $(x_i, y_i)$ and $(x_{i+1}, y_{i+1})$ as discussed in Section \ref{Straight Lines}.
9
10 There are many different ways to define a spline.One approach is to specify ``knots'' on the curve and choosing a fixed $n$ ($n = 3$ for ``cubic'' splines) solve for the cooefficients to generate polynomials passing through the points. Alternatively, special polynomials may be defined using ``control'' points which themselves are not part of the curve; these are convenient for graphical based editors.\end{co B{\'e}zier splines are the most straight forward way to define a curve in the standards considered in Section \ref{Document Representations}. A spline defined from two cubic B{\'e}ziers is shown in Figure \ref{spline.pdf}
11 \end{comment}
12
13 Cubic and Quadratic B{\'e}zier Splines are used to define curved paths in the PostScript\cite{plrm}, PDF\cite{pdfref17} and SVG\cite{svg2011-1.1} standards which we will discuss in Section \ref{Document Representations}.  Cubic B{\'e}ziers are also used to define vector fonts for rendering text in these standards and the {\TeX}  typesetting language \cite{knuth1983metafont, knuth1984texbook}. Although he did not derive the mathematics, the usefulness of B{\'e}zier curves was realised by Pierre B{\'e}zier who used them in the 1960s for the computer aided design of automobile bodies\cite{bezier1986apersonal}. 
14
15 A B{\'e}zier Curve of degree $n$ is defined by $n$ ``control points'' $\left\{P_0, ... P_n\right\}$. 
16 Points $P(t) = (x(t), y(t))$ along the curve are defined by:
17 \begin{align}
18         P(t) &= \displaystyle\sum_{j=0}^{n} B_j^n(t) P_j
19 \end{align}
20 Where $t \epsilon [0,1]$ is a control parameter. The polynomials $B_j^n(t)$ are Bernstein Basis Polynomials which are defined as:
21 \begin{align}
22         B_j^n(t) &=  \left(^n_j\right) t^j\left(1-t\right)^{n-j} \quad \quad j=0,1,...,n \\
23         \text{Where } \left(^n_j\right) &= \frac{n!}{n!(n-j)!} \quad \text{ (The Binomial Coefficients)}
24 \end{align}
25 From these definitions it should be apparent that in all cases, $P(0) = P_0$ and $P(1) = P_n$. An $n = 1$ B{\'e}zier Curve is a straight line.
26
27 Algorithms for rendering B{\'e}zier's may simply sample $P(t)$ for suffiently many values of $t$ --- enough so that the spacing between successive points is always less than one pixel distance. Alternately, a smaller number of points may be sampled with the resulting points connected by straight lines using one of the algorithms discussed in Section \ref{Straight Lines}.
28
29 De Casteljau's algorithm of 1959 is often used for approximating B{\'e}ziers\cite{computergraphics2, knuth1983metafont}. This algorithm subdivides the original $n$ control points $\left\{P_0, ... P_n\right\}$ into $2n$ points $\left\{Q_0, ... Q_n\right\}$ and $\left\{R_0, ... R_n\right\}$; when iterated, the produced points will converge to $P(t)$. As a tensor equation this subdivision can be expressed as\cite{goldman_thefractal}:
30 \begin{align}
31         Q_i = \left(\frac{\left(^n_j\right)}{2^j}\right) P_i &\text{ and }      R_i = \left(\frac{\left(^{n-j}_{n-k}\right)}{2^{n-j}}\right) P_i
32 \end{align}
33
34
35 In much of the literature it is taken as trivial that it is only necessary to specify the control points of a B{\'e}zier in order to be able to render it at any level of detail\cite{knuth1983metafont, computergraphics2}. Recently, Goldman presented an argument that B{\'e}zier's could be considered as fractal in nature, because the De Casteljau algorithm may be modified to be expressed the polynomial $P(t)$ as the result of iterated function system\cite{goldman_thefractal}. If this argument is correct, any primitive that can be described soley in terms of B{\'e}zier Curves may also be considered as fractal in nature. Ideally all these primitives may be rendered at any level of detail or ``zoom'' desired; however, computation of the pixel locations of the curve will be subject to the precision limits of the numerical representation which is used; we discuss these issues in Section \ref{Number Representations}.
36
37
38 \begin{figure}[H]
39 \centering
40 \begin{minipage}[t]{0.3\textwidth}
41 \begin{figure}[H]
42         \centering
43         \includegraphics[width=0.7\textwidth]{figures/spline_labelled.pdf}
44 \end{figure}
45 \end{minipage}
46 \begin{minipage}[t]{0.3\textwidth}
47 \begin{minted}{xml}
48 <!-- DOM element in SVG used to construct the spline -->
49 <path d="M 0,300 
50         C 0,300 200,210 90,140 
51         -20,70 200,0 200,0"
52         style="stroke:#000000; stroke-width:1px; 
53         fill:none;"/>
54 \end{minted}
55 \begin{minted}{postscript}
56 % PostScript commands for a similar spline
57 0 300 moveto 
58 0 300 200 210 90 140 curveto 
59 -20 70 200 0 200 0 curveto stroke 
60 \end{minted}
61 \end{minipage}
62 \begin{minipage}[t]{0.3\textwidth}
63 \begin{figure}[H]
64         \centering
65         \includegraphics[width=0.7\textwidth]{figures/spline.pdf}
66 \end{figure}
67 \end{minipage}
68         \caption{Constructing a Spline from two cubic B{\'e}ziers \\ (a) Showing the Control Points (b) Representations in SVG and PostScript (c) Rendered Spline}\label{spline.pdf}
69 \end{figure}

UCC git Repository :: git.ucc.asn.au