[cairo] Rendering B-Splines with Cairo

Bill Spitzak spitzak at thefoundry.co.uk
Mon Apr 6 20:30:16 PDT 2009

```Aren't the end points as though there are 2 b-spline control points at
that location? Ie pretend there is one more point before and after the
ends of your curve but equal to those points, then do your algorithm.

Gerald Hansford wrote:
> Hi - thanks as always to the tremendous team responsible for Cairo -
> it's an excellent library.
>
> Does anyone have any experience rendering open, cubic uniform B-Splines
> using Cairo? I know that it does not have explicit support for
> B-Splines, but my understanding is that one can derive the series of
> Bézier splines represented implicity in a B-Spline. In fact I have code
> that does this for the open & periodic cases for quadratic b-splines, as
> well as the periodic case for cubic B-Splines. For that, my code looks
>
> Vec2f q0, q1, q2, q3;
> q0 = ( spline.getControlPoint( 0 ) + spline.getControlPoint( 1 ) * 4.0f
> + spline.getControlPoint( 2 ) ) / 6.0f;
> moveTo( q0 );
> int lastPt = ( spline.isLoop() ) ? numPoints : numPoints - 3;
> for( int i = 0; i < lastPt; ++i ) {
>     Vec2f p1 = spline.getControlPoint( ( i + 1 ) % numPoints );
>     Vec2f p2 = spline.getControlPoint( ( i + 2 ) % numPoints );
>     Vec2f p3 = spline.getControlPoint( ( i + 3 ) % numPoints );
>
>     q1 = p1 * ( 4.0f / 6.0f ) + p2 * ( 2.0f / 6.0f );
>     q2 = p1 * ( 2.0f / 6.0f ) + p2 * ( 4.0f / 6.0f );
>     q3 = p1 * ( 1.0f / 6.0f ) + p2 * ( 4.0f / 6.0f ) + p3 * ( 1.0f / 6.0f );
>     curveTo( q1, q2, q3 );
> }
>
> The trouble comes when I try to address the open cubic case (where the
> curve passes through the endpoints of the b-spline). All of the
> literature on the topic which I can actually understand seems to be
>
> I know that in the open case, a b-spline with 4 control points exactly
> maps to the bezier curve with the same control points. Also through
> experimentation I can tell that the non-end segments of an open b-spline
> with >= 6 points correspond to the periodic case. However I am still at
> a loss as to how one would glue all of this information together, and I
> haven't managed to get deep enough in the relevant math to follow
> discussions of how knot insertion or blossoming helps me solve this problem.
>
> Any help from someone experienced in all of this would be *very* much
> appreciated.
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> cairo mailing list
> cairo at cairographics.org
> http://lists.cairographics.org/mailman/listinfo/cairo

--
Bill Spitzak, Senior Software Engineer
The Foundry, 618 Hampton Drive, Venice, CA, 90291, USA
Tel: +1 310 399-4555 * Fax: +1 310 450-4516 * Web: www.thefoundry.co.uk
The Foundry Visionmongers Ltd * Registered in England and Wales No: 4642027
```