- Building Bezier segments
- Data structures
- Algorithms
- License
- Installation
- Tutorial
- Reference
- FAQ
- Technical details
- Changes
- Related projects

6 Technical details | |

→ | 6.2 Algorithms |

In this section we use *x* and *y* for coordinates in
the diagram ("on paper"). We use *u* and *v* for
variables drawn along the *x* and *y* axes.

*t* is used as parameter for Bezier segments, for each segment
we have 0≤*t*≤1.

For parametric plots we use a variable ϑ varying in a given range,
used to calculate *u*=*f*_{u}(ϑ) and
*v*=*f*_{v}(ϑ).

In the drawing ("on paper") we use coordinates in the range
*x*_{min}≤*x*≤*x*_{max} and
*y*_{min}≤*y*≤*y*_{max}.

The axes settings assign values
*u*_{min}≤*u*≤*u*_{max} and
*v*_{min}≤*v*≤*v*_{max} to the
coordinates.

For a linearly scaled *x* axis we can calculate *x*
and d*x*/d*u* for a given *u* and vice versa using
the formulas:

For a linearly scaled *y* axis we can calculate *y*
and d*y*/d*v* for a given *v* and vice versa using
the formulas:

For a logarithmically scaled *x* axis we can calculate
*x* and d*x*/d*u* for a given *u* and vice
versa using the formulas:

For a logarithmically scaled *y* axis we can calculate
*y* and d*y*/d*v* for a given *v* and vice
versa using the formulas:

The *u* values are converted to *x* values using the
*x* axis settings. The *v* values are converted to
*y* values using the *y* axis settings.

For each interval between points *i* and *i*+1 we have
*t*: 0≤*t*≤1. We do the following calculations for each
interval:

For a linear *x* axis we increase *x* linearly and
find the value of d*x*/d*t* at the start and end of the
interval:

For a logarithmic *x* axis we increase *x*
exponentially and find the value of d*x*/d*t* at the
start and end of the interval:

Finally we calculate d*y*/d*t* for start and end
point:

We do a cubic spline interpolation using the *pgfplot_cs()*
function considering the first derivative values already known. Now
we can express *v* using a piecewise polynomial over
*u*.

For all points except the last one we can obtain the first derivative value:

For the last point *n* we use:

For the given *u* range we calculate the corresponding
*x* range. For the *x* range we calculate a linearly
spaced *x* vector and a corresponding *u* vector. The
function is used to calculate the *v* vector. Optionally we
also calculate a vector containing d*v*/d*u* for the
*u* vector. With the *u*, *v* and optionally
d*v*/d*u* values we continue as described above.

For a parametric points plot with given first derivative values
we have *u*, *v*, d*u*/dϑ, and d*v*/dϑ for each
point. The points are monothonic spaced, Δϑ=1, so
dϑ/d*t*=1.

Using the known values above and the axis settings, we can
calculate *x*, *y*, d*x*/d*t* and
d*y*/d*t* for each point.

For a parametric points plot we have *u* and *v* for
each point. Optionally d*u*/dϑ and d*v*/dϑ are known for
some (but not all) points. The points are monothonic spaced, Δϑ=1,
so dϑ/d*t*=1.

We do two cubic spline interpolations using the
*pgfplot_cs()* function considering the first derivative
values already known to express both *u* and *v* as
polynomials over ϑ. We can find the first derivative d*u*/dϑ
and d*v*/dϑ values not yet known from the piecewise
polynomials.

Dirk Krause

Schmalkalden, 2016-11-15