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

David Bovill david.bovill at gmail.com
Thu Oct 1 14:19:10 EDT 2009


Thanks for response - did make me smile!

2009/10/1 François Chaplais <francois.chaplais at mines-paristech.fr>

>
> 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
>

Maybe someone can suggest a hack :) I'm thinking something along the lines
of calculating the bezier curves for each pair of points along the curve:
this is the function I have courtesy Alejandro:

function graph_BezierLine listOfPoints, zdt
>    put item 1 of  listOfPoints into x1
>    put item 2 of  listOfPoints into y1
>    put item 3 of  listOfPoints into xa
>    put item 4 of  listOfPoints into ya
>    put item 5 of  listOfPoints into xb
>    put item 6 of  listOfPoints into yb
>    put item 7 of  listOfPoints into x2
>    put item 8 of  listOfPoints into y2
>    put 0 into v1
>
>    if zdt is empty then put 32 into zdt
>    repeat with i = 1 TO zdt -- zdt is a integer number like 32
>       put i * 1/zdt into v1
>       put 1 - v1 into v2
>       put (x1 * (v2 * v2 * v2) + (3 * xa * v1 * v2 * v2) + (3 * xb * v1 *
> v1 * v2) + (x2 * (v1 ^ 3))) into x
>       put (y1 * (v2 * v2 * v2) + (3 * ya * v1 * v2 * v2) + (3 * yb * v1 *
> v1 * v2) + (y2 * (v1 ^ 3))) into y
>       if (x div 1 & "," & y div 1) <> last line of variablezxc then put (x
> div 1 & "," & y div 1) & CR after variablezxc
>    end repeat
>
>    --  if x1,y1 <> first line of variablezxc then put x1,y1 & return before
> variablezxc
>    if x2,y2 <> last line of variablezxc then put x2,y2 & CR after
> variablezxc
>    put x1,y1 & CR before variablezxc
>    -- put x2,y2 & CR after variablezxc
>    return variablezxc
> end graph_BezierLine
>

Then doing something like working out the perpendicular to the curve at each
point.... hmmmm think it would be a nice little utility handler to have?



More information about the use-livecode mailing list