Smoothing a curve: bezier curves, b-splines and Alejandro's PenTool Script

François Chaplais francois.chaplais at mines-paristech.fr
Thu Oct 1 12:02:07 EDT 2009


Le 1 oct. 09 à 11:56, David Bovill a écrit :

> I'm looking for a handler to smooth out rev graphic curves - you  
> fetch the
> points and you interpolate a vaiable number of in between values.  
> I've lost
> the script I had to do that, and worse I've forgotten how :) The  
> aim is to
> create a general handler like"
>

I cannot answer  this problem with a script, but here are the maths  
behind it

1) you select a vector space of function (polynomials, for instance:  
polynomials are linear combinations of monomials t^k).
These functions are expressed as a linear combination of elementary  
functions,
whose value you can easily compute *at any point*
2) you use a family of *linear* operators which are well defined over  
this functional space.
For instance, instant value, instant differentiations are linear  
operators which are well defined for polynomials.
[average value also, I have used this for some algorithms]
3) you set the generalized *interpolation* problem:
for a given set of points, you wish that your linear operators  
(instant value, derivative, etc...)
take some desired values.

It turns out that the solution to problem (3) is the solution of  
*finite dimensional* linear system.
Let us consider bezier curves.

To simplify, we assume that the vertical coordinate is a function of
the horizontal coordinate. The vector space for Bezier curves is the  
space of polynomials of degree
smaller or equal to 3: they are described by 4 parameters.

Now, what you specify to the bezier curve is:
a) the value and derivative at the left end point
b) the value and derivative at the right end point

This is a set of 4 linear equations with 4 unknowns. It has the form
Ax = b
where b is the vector of specifications, x the unknown value of your  
function  parameters (the coefficients of the monomials)
and A is a matrix which only depends of the end points.
If the distance between the endpoints is constant, A does not depend  
on the endpoints.
A is" easily"  computable.

The drawing of the Bezier curves boils down to this:
1) you compute the matrix A
2) you invert it
3) the parameters x of the unknown cubic polynomials are given by x  
=A^(-1)b
4) once your know the cubic polynomial, you can compute its value at  
any point [the operation is referred as interpolation]

HTH

François

P.S I have de Boor's book, it is unreadable.


More information about the use-livecode mailing list