[cairo] a quadratic Bézier curve

Simon Budig simon at budig.de
Tue Apr 13 09:35:58 PDT 2010


Nicola Fontana (ntd at entidi.it) wrote:
> Il giorno Tue, 13 Apr 2010 17:28:32 +0300
> Roman Beslik <beroal at ukr.net> ha scritto:
> 
> > Hello. Can I draw it with Cairo?
> 
> Cairo uses only cubic Bézier curves. This is not a real issue
> though, because elevating the degree of a Bézier curve is quite
> easy:
> 
> http://www.cs.mtu.edu/~shene/COURSES/cs3621/NOTES/spline/Bezier/bezier-elev.html

Since this might be a bit hard to digest for people without previous
experience in bezier math here is an untested helper function
that shows how it should work for your case:

void
helper_quadratic_to (cairo_t *cr,
                     double x1, double y1,
                     double x2, double y2)
{
  double x0, y0;
  cairo_get_current_point (cr, &x0, &y0);
  cairo_curve_to (cr,
                  2.0 / 3.0 * x1 + 1.0 / 3.0 * x0,
                  2.0 / 3.0 * y1 + 1.0 / 3.0 * y0,
                  2.0 / 3.0 * x1 + 1.0 / 3.0 * x2,
                  2.0 / 3.0 * y1 + 1.0 / 3.0 * y2,
                  y1, y2);
}

Hope this helps,
        Simon
-- 
              simon at budig.de              http://simon.budig.de/


More information about the cairo mailing list