ScriptC.mw
Parametric Curve Fitting for a Script Letter
Initial Data
The "curve" being used for this example is a script letter C. This illustration is presented using Maple.
In handwriting, a script C was written on graph paper and then a reasonably small set of data points was read off from the graph paper. The chosen data points are spaced closer together in regions of high curvature and spaced farther apart in regions of smaller curvature, to achieve the goal of keeping the data set small. See the LinePlot below which shows how the data points are spaced.
In this example, the number of data points is 15.
> |
|
> |
|
|
(1) |
> |
|
|
(2) |
> |
|
|
(3) |
> |
|
|
(4) |
> |
|
|
(5) |
The following plot of the data points is not very informative by itself, but when superimposed on future plots it becomes informative.
See the LinePlot below for a better idea of the order of the data points.
> |
|
Piecewise-linear Interpolation
Piecewise-linear (straight-line) interpolation of the data gives an indication of the shape of the letter being represented. For a smooth interpolating curve see the following sections which employ cubic spline interpolation.
> |
|
> |
|
Cubic Spline Interpolation using Dumb Parameterization
We proceed to do cubic spline interpolation as follows. We parameterize the curve by a parameter and then compute two cubic spline fits, fitting data and fitting data . The desired curve is then represented by as varies over its range of values.
As discussed in class and in the CS 370 Course Notes, the simplest parameterization is achieved by setting for all . However, this leads to a distortion of the curve (illustrated below) due to the fact that in some parts of the curve, successive data points are farther apart than in other parts of the curve. Equally-spaced parameter values fail to reflect this property of the given data.
> |
|
Change from a Maple table construct to a Maple list construct.
> |
|
|
(6) |
Do cubic spline interpolation to define and .
> |
|
> |
|
> |
|
The representation used in Maple for the cubic splines computed by the above commands is a piecewise construct. Below we display the cubic spline and we round the coefficients to just four significant digits so as to use less space for this display.
> |
|
|
(7) |
The unapply command appearing below is a Maple construct to transform the given expression into functional form which is useful for subsequent evaluations. For example, if then the result of the command is a function such that invoking evaluates the expression at the value .
> |
|
The refine Procedure
Corresponding to the Matlab procedure refine presented in the CS 370 Course Notes, we define a Maple procedure to refine the list of evaluation points, , for the purpose of plotting. In other words, we define a denser set of evaluation points corresponding to the parameter so that a plot based on evaluations at the dense set of -values will more accurately reflect the cubic spline functions which have been computed.
This procedure will be invoked in the form refine(tlist, refFactor) and the result returned will be a new list of points generated by refining the original list tlist by a factor refFactor.
Plots based on the Dumb Parameterization
First we use a refinement factor of 3 and we display the resulting curve based on evaluating at 43 points.
> |
|
|
(8) |
> |
|
> |
|
|
(10) |
> |
|
> |
|
> |
|
The above plot shows a fairly smooth curve but with some strange kinks.
Let us try a refinement factor of 25 for evaluating the same curve to see whether the kinks in the above plot are an artifact of not evaluating at a sufficiently dense set of -values.
> |
|
> |
|
> |
|
|
(11) |
> |
|
> |
|
> |
|
Although this has achieved some smoothing in parts of the script C, the main kink appearing in the lower part of the curve has not disappeared. This kink is inherent in the particular cubic spline fitting we have done based on the dumb parameterization used above.
Cubic Spline Interpolation using Smart Parameterization
Repeating what was stated above, we parameterize the curve by a parameter and then compute two cubic spline fits, fitting data and fitting data , where are the original 15 data points. The desired curve is then represented by as varies over its range of values.
This time we define the parameter values using a formula based on the distance between successive data points, as discussed in the CS 370 Course Notes.
Recall the original data points.
> |
|
|
(12) |
> |
|
|
(13) |
> |
|
|
(14) |
Define a parameterization based on the distance between successive points.
> |
|
Change from a Maple table construct to a Maple list construct.
> |
|
Do cubic spline interpolation to define and .
> |
|
> |
|
> |
|
First we use a refinement factor of 3 and we display the resulting curve based on evaluating at 43 points.
> |
|
> |
|
> |
|
|
(16) |
> |
|
> |
|
> |
|
This time we have a somewhat smooth curve and the most significant kink appearing in the previous attempt has disappeared.
Let us try a refinement factor of 25 for evaluating the curve in order to produce a plot which more accurately reflects the cubic spline fit.
> |
|
> |
|
> |
|
|
(17) |
> |
|
> |
|
> |
|
We now have a smooth curve through the given data points. The smart parameterization based on the distance between successive data points avoids the distortion caused by a simple-minded parameterization.