%% License: GPL
%% Date (YY-MM-DD): 04-07-09
%% Author: Tobias N"ahring
%% 
\documentclass{article}
\usepackage{amsmath}
\usepackage{pstricks}
\usepackage{pst-bezier}
\usepackage{pstcol}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\catcode`\�=\active
\newif\ifHilight
\def�{%
  \ifHilight%
  \color{black}%
  \Hilightfalse%
  \else%
  \color{red}%
  \Hilighttrue%
  \fi%
}
\catcode`\�=\active
\def�{\textit}

\def\beginEx{
  \mbox{}\\[5ex]
  \mbox{}\hfill
  \begin{minipage}{0.48\linewidth}
}

\def\midEx{
  \end{minipage}\hfill
  \begin{minipage}{0.48\linewidth}
}
\def\endEx{\end{minipage}\hfill\mbox{}\\[5ex]}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\vp{{\vec{p}}}
\def\vl{{\vec{l}}}
\def\vr{{\vec{r}}}

\psset{gridcolor=green,subgridcolor=yellow}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\title{Documentation of `\texttt{pst-bezier.tex}'}
\author{Tobias N{\"a}hring\\\texttt{www.tn-home.de}}
\maketitle
\tableofcontents

\section{Introduction}
The \texttt{pstricks} package provides (essentially) two main macros for
drawing curves: \verb=\pscurve= and \verb=\psbezier=. Both macros
employ Bezier splines.

The \verb=\pscurve= macro takes multiple interpolated points as
arguments. Thus, it is easy to draw long multiply bent curves. The
problem with \verb=\pscurve= is that there is no easy
way\footnote{Note that some control is possible via the
  \texttt{curvature} option.} to change the automatically computed
control points without simultaneously changing the interpolated
points.

The \verb=\psbezier= macro gives full control over the
interpolation points and the control points of one Bezier polynominal
of degree three (two interpolated points and two control
points).

If one demands for the access to certain control points of one
multiply bent curve one has to use multiple instances of the
\verb=\psbezier= macro.  With this approache each inner interpolation
point of the curve has to be input twice. Furthermore, if one needs
smooth joints one has to compute control points symmetrically to the
corresponding interpolation points for every joint even if one does
not care so much about the exact tangential direction at some of those
joints.  That can be rather tedious.

The \verb=\bcurve= macro of \verb=pst-bezier.sty= is intented to
demonstrate a way to combine the nice properties of the macros
\verb=\pscurve= and \verb=\psbezier=.  It provides an easy input
format to describe `arbitrarily' many interpolation points of a curve
and to fix the control points at some freely selected interpolation
points.

Note, that \verb=pst-bezier.sty= is \textbf{no final package} (e.g.
the automatical computation of the control points is not as refined as
that one for the macro \verb=\pscurve=). To emphase that, the macro
\verb=\bcurve= does not fit into the name conventions of
\texttt{pstricks}. I would be pleased if the features of
\texttt{pst-bezier.tex} could be implemented into
\texttt{pstricks-add.tex}. But, because of lack of spare time, I
cannot promise to do any further work on that project.

\section{Installation and usage of \texttt{pst-bezier.tex}}
\paragraph{Installation:}
As prerequisites for \texttt{pst-bezier} you need resent working
versions of \LaTeX{} and \texttt{pstricks}. The files
\texttt{pst-bezier.tex} and \texttt{pst-bezier.sty} must be somewhere
in your \TeX-input path. Further more, the file
\texttt{pst-bezier.pro} must be in some path, where \texttt{dvips} can
find it.

\paragraph{Usage:}
As usual, load the packages \texttt{pstricks} and \texttt{pst-bezier}
in that order via the \verb=\usepackage= macro.

Now you are ready to use the \verb=\bcurve= macro within your document
body. This macro is described in the next section with all its options.

Whith the following simple \LaTeX-source code you can test whether you have
correctly installed the package:
\begin{verbatim}
\documentclass{minimal}
\usepackage{pstricks}
\usepackage{�pst-bezier�}
\begin{document}
 \begin{pspicture}(6,4)
   �\bcurve(1,2)(5,2)� % Draw just one straight line.
 \end{pspicture}
\end{document}
\end{verbatim}

\section{The \texttt{\textbackslash bcurve} macro}
In the most simple form you can specify any number of interpolation
points as the argument of \verb=\bcurve=.
\beginEx
\begin{verbatim}
\bcurve(1,1)(2,2)(3,1)(4,2)
\end{verbatim}
\midEx
\begin{pspicture}(5,3)
  \psgrid
  \bcurve(1,1)(2,2)(3,1)(4,2)
\end{pspicture}
\endEx
As usual, options can be specified within brackets.
\beginEx
\begin{verbatim}
\bcurve[showpoints=true]%
(1,1)(2,2)(3,1)(4,2)
\end{verbatim}
\midEx
\begin{pspicture}(5,3)
  \psgrid
  \bcurve[showpoints=true](1,1)(2,2)(3,1)(4,2)
\end{pspicture}
\endEx
As you can see in the above example, the \texttt{showpoints} feature works
(partially) with \verb=bcurve=.

The next figure shows again the curve from the first example. This
time labels are added to the points (this is just for the following
description,
it is not a feature of \verb=\bcurve=).\\[5ex]
\mbox{}\hfill
\begin{pspicture}(5,3)
  \psgrid
  \bcurve[showpoints=true](1,1)(2,2)(3,1)(4,2)
  \uput[-90](1,1){$\vp_{0}=\vl_{1}$}
  \uput[90](1.5,2){$\vr_{1}$}
  \uput[90](2,2){$\vp_{1}$}
  \uput[90](2.5,2){$\vl_{2}$}
  \uput[-90](2.5,1){$\vr_{2}$}
  \uput[-90](3,1){$\vp_{2}$}
  \uput[-90](3.5,1){$\vl_{3}$}
  \uput[90](4,2){$\vr_{3}=\vp_{3}$}
\end{pspicture}\hfill\mbox{}\\[5ex]

The points labelled with $\vp_{k}$ $(k=0,\dots,3)$ are the
interpolation points, these ones labelled with $\vl_{1},\hdots,\vl_{3}$,
and these ones labelled with $\vr_{1},\hdots,\vr_{3}$ are the left and
right control points, respectively.

Between each consecutive pair $\vp_{k-1},\vp_{k}$ of interpolation
points the \verb=\bcurve= macro draws a cubic Bezier spline.
The control points  $\vl_{k}$ and $\vr_{k}$ determine the tangential
direction of the bezier spline at the interpolation points. More
exactly, the bezier spline from $\vp_{k-1}$ to $\vp_{k}$ is tangent to
the vector $\vl_{k}-\vp_{k-1}$ at the point $\vp_{k-1}$ and tantengial
to the vektor $\vr_{k}-\vp_{k}$ at the point $\vp_{k}$.

Without any optional modifier arguments (described later in this text)
the control points are computed automatically
from the interpolation points by the formulas\footnote{Note that this
  method is very crude. To compute the curve such that the curvature
  is continuous would require solving a nonlinear system of
  equations. That is not implemented yet.}
\begin{align*}
  \vl_{1}&= \vp_{0}\\
  \vl_{k}&= t_{k}(\vp_{k}-\vp_{k-2})&&\text{for }k=2,\hdots,n\\
  \vr_{k}&= t_{k}(\vp_{k-1}-\vp_{k+1})&&\text{for }k=1,\hdots,n-1\\
  \vr_{n}&= \vp_{n}
\end{align*}
where $t_{k}$ $(k=1,\hdots,n)$ are real coefficients which are called
tension and which default to the value $\texttt{bcurveTension}=0.25$.

You can change the appearance of the curve by several modifiers.
First of all you can directly set the left and right control points
via the modifiers \texttt{�l(�x,�y)�} and \texttt{�r(�x,�y)�}, resp., as
shown in the next two examples. The unmodified curve is drawn in the
background in {\color{blue}blue} color.
\beginEx
\begin{verbatim}
\psset{showpoints=true}
\bcurve(1,1)�l(2,1)�%
   (2,2)(3,1)�r(4,1)�(4,2)
\end{verbatim}
\midEx
\pspicture(5,3)
\psgrid
\psset{showpoints=true}
\bcurve[linecolor=blue,linewidth=0.01](1,1)%
  (2,2)(3,1)(4,2)
\bcurve(1,1)l(2,1)%
   (2,2)(3,1)r(4,1)(4,2)
\uput[-90](2,1){$�\vl_{1}�$}
\uput[-90](4,1){$�\vr_{3}�$}
\endpspicture
\endEx
\beginEx
\begin{verbatim}
\bcurve(1,1)%
  (2,2)�l(2,1)�(3,1)(4,2)
\end{verbatim}
\midEx
\pspicture(5,3)
\psgrid
\psset{showpoints=true}
\bcurve[linecolor=blue,linewidth=0.01](1,1)%
  (2,2)(3,1)(4,2)
\bcurve(1,1)%
  (2,2)l(2,1)(3,1)(4,2)
\uput[-90](2,1){$�\vl_{2}�$}
\endpspicture
\endEx
\beginEx
On the right hand side the last example is shown once more without grid and
with \texttt{showpoints=false}. There, you see that there is a corner at the second
interpolation point.
\midEx
\pspicture(5,3)
\bcurve(1,1)%
  (2,2)l(2,1)(3,1)(4,2)
\endpspicture
\endEx

If you change some left control point $\vl_{k}$ with the help of the
\texttt{�L(�x,�y)�} modifier then the control point
$\vr_{k-1}$ is set symmetrically to $\vl_{k}$ with respect to the
interpolation point $\vp_{k-1}$. In that way you get a smooth joint as
demonstrated in the next example.
\beginEx
\begin{verbatim}
\bcurve(1,1)%
  (2,2)�L(2,1)�(3,1)(4,2)
\end{verbatim}
\midEx
\pspicture(5,3)
\psgrid
\bcurve[linecolor=blue,linewidth=0.01](1,1)%
  (2,2)(3,1)(4,2)
\psset{showpoints=true}
\bcurve(1,1)%
  (2,2)L(2,1)(3,1)(4,2)
\uput[-90](2,1){$�\vl_{2}�$}
\uput[0](2,2){$\vp_{1}$}
\uput[0](2,3){$�\vr_{1}�$}
\endpspicture
\endEx

With the \verb=�t{�t}�= modifier you can change the tension of the
automatically computed control points of the current Bezier spline.

\beginEx
\begin{verbatim}
\bcurve(1,1)%
  (2,2)�t{0.5}�(3,1)(4,2)
\end{verbatim}
\midEx
\pspicture(5,3)
\psgrid
\psset{showpoints=true}
\bcurve[linecolor=blue,linewidth=0.01](1,1)%
  (2,2)(3,1)(4,2)
\bcurve(1,1)%
  (2,2)t{0.5}(3,1)(4,2)
\endpspicture
\endEx

As you can see from the example both control points of the current
spline are affected by the \verb=t{�t}= modifier.

If you want to change the tension of just the left or right control
point you can use the \verb=�tl{�t}�= or \verb=�tr{�t}�= modifier,
respectively, as demonstrated in the following two examples.
\beginEx
\begin{verbatim}
\bcurve(1,1)%
  (2,2)�tl{0.5}�(3,1)(4,2)
\end{verbatim}
\midEx
\pspicture(5,3)
\psgrid
\psset{showpoints=true}
\bcurve[linecolor=blue,linewidth=0.01](1,1)%
  (2,2)(3,1)(4,2)
\bcurve(1,1)%
  (2,2)tl{0.5}(3,1)(4,2)
\endpspicture
\endEx
\beginEx
\begin{verbatim}
\bcurve(1,1)%
  (2,2)�tr{0.5}�(3,1)(4,2)
\end{verbatim}
\midEx
\pspicture(5,3)
\psgrid
\psset{showpoints=true}
\bcurve[linecolor=blue,linewidth=0.01](1,1)%
  (2,2)(3,1)(4,2)
\bcurve(1,1)%
  (2,2)tr{0.5}(3,1)(4,2)
\endpspicture
\endEx

The \verb=ts{�t}= modifier changes the tension of the left and right
control points next to the interpolation point which stands in front
of the modifier. In the next example a negative tension value leads to
a rather surprising effect.  \beginEx
\begin{verbatim}
\bcurve(1,1)%
  (2,2)�ts{-0.5}�(3,1)(4,2)
\end{verbatim}
\midEx
\pspicture(5,3)
\psgrid
\psset{showpoints=true}
\bcurve[linecolor=blue,linewidth=0.01](1,1)%
  (2,2)(3,1)(4,2)
\bcurve(1,1)%
  (2,2)ts{-0.5}(3,1)(4,2)
\endpspicture
\endEx

The default value of the tension can be set with the option
\texttt{�bcurveTension�} as in the following example.

\beginEx
\begin{verbatim}
\bcurve[�bcurveTension=0.5�]%
  (1,1)(2,2)(3,1)(4,2)
\end{verbatim}
\midEx
\pspicture(5,3)
\psgrid
\psset{showpoints=true}
\bcurve[linecolor=blue,linewidth=0.01](1,1)%
  (2,2)(3,1)(4,2)
\bcurve[bcurveTension=0.5](1,1)%
  (2,2)(3,1)(4,2)
\endpspicture
\endEx

You can set this option also with the help of the \verb=\psset=
macro.

It is even possible to change the value of \verb=bcurveTension= in the
middle of a \verb=bcurve=. Just use the modifier \verb=T{�t}= for
that purpose as shown in the following example.

\beginEx
\begin{verbatim}
\bcurve(1,1)(2,2)(3,1)(4,2)%
  �T{0.5}�(4,4)(3,5)(2,4)(1,5)
\end{verbatim}
\midEx
\pspicture(5,6)
\psgrid
\psset{showpoints=true}
\bcurve[linecolor=blue,linewidth=0.01](1,1)%
  (2,2)(3,1)(4,2)(4,4)(3,5)%
  (2,4)(1,5)
\bcurve(1,1)(2,2)(3,1)(4,2)%
  T{0.5}(4,4)(3,5)(2,4)(1,5)
\endpspicture
\endEx

Certainly, you can use the \verb=T{�t}= modifier several times in one
curve. (Try it for yourself.)

The \texttt{linestyle} and \texttt{fillstyle} options (and several
more) are respected by \verb=\bcurve= as the following example shows.

\beginEx
\begin{verbatim}
\bcurve[�linestyle=dashed,�%
  linewidth=3pt,%
  dash=0.5 0.2,%
  �fillstyle=solid,�%
  �fillcolor=blue�](1,1)%
  (2,2)(3,1)(4,2)
\endpspicture
\end{verbatim}
\midEx
\pspicture(5,3)
\psgrid
\bcurve[linestyle=dashed,%
  linewidth=3pt,%
  dash=0.5 0.2,%
  fillstyle=solid,%
  fillcolor=blue](1,1)%
  (2,2)(3,1)(4,2)
\endpspicture
\endEx

\section{Things that do not work (`known bugs')}
As already mentioned this project is something like an experiment. So,
there are many things that do not work.
\begin{itemize}
\item Newlines inside the argument list are not ignored.
\item The control points are computed in a rather crude way (see
  above). The \texttt{curvature} option is not recognised.
\item If \texttt{fillstyle} is set to \texttt{solid} and
  \texttt{showpoints} to \texttt{true} then the fill
  color covers the interpolation and control points.
\item Arrowheads do not work.
\end{itemize}
\end{document}

