[cairo] Spline with more than 4points

James Cloos cloos at jhcloos.com
Thu May 1 14:06:14 PDT 2008


>>>>> "jaya" == jaya  <jayakarthi at yahoo.com> writes:

jaya> I use wxWidgets for the GUI. Before cairo, i used the DrawSpline
jaya> function of the wxWidgets to draw a spline where i can specify any
jaya> number of points. But in cairo i am not able to find a replacement
jaya> function. I found only cairo_curve_to function which will accept
jaya> only four [points].

Cairo follows the Postscript model; you have to build up the splines one
Beziér segment at a time using the line_to and curve_to functions.

The wx docs weren’t sufficiently explicit, but I see no way there to
specify a degree or knot vector; they, like cairo, seem to use fixed-
degree splines.  I took a quick look at their src.  They have functions
for both cubic and quadratic Beziérs.  You should note that cairo only
does cubic.

So, if you points are in structs that look like:

    struct point { int x, int y }

and you have points p0, p1, ..., p15 then you move to the first point
and then call curve_to with the next three points at a time until you
reach the last point:

      cairo_move_to(cr, p0.x, p0.y);
      cairo_curve_to(cr,  p1.x,  p1,y,  p2.x,  p2.y,  p3.x,  p3.y);
      cairo_curve_to(cr,  p4.x,  p4,y,  p5.x,  p5.y,  p6.x,  p6.y);
      cairo_curve_to(cr,  p7.x,  p7,y,  p8.x,  p8.y,  p9.x,  p9.y);
      cairo_curve_to(cr, p10.x, p10,y, p11.x, p11.y, p12.x, p12.y);
      cairo_curve_to(cr, p13.x, p13,y, p14.x, p14.y, p15.x, p15.y);

-JimC
-- 
James Cloos <cloos at jhcloos.com>         OpenPGP: 1024D/ED7DAEA6


More information about the cairo mailing list