[cairo] Curve drawing question (from GUADEC)

Carl Worth cworth at cworth.org
Thu Jun 29 12:17:13 PDT 2006


On Thu, 29 Jun 2006 18:42:44 +0100, Liam Girdwood wrote:
> I had the good fortune to bump into Carl and Keith at GUADEC recently
> and asked them a cairo curve drawing question.

It was nice to meet you as well.

> I asked what was the best sequence of cairo function calls to draw a
> scaled curve in cairo (e.g. lines of longitude/latitude on a spherical
> projection of the Earth). Iirc, Carl mentioned that getting the ordering
> of cairo function calls wrong in this case could cause the line
> thickness to vary slightly from one end of the curve to the other.

So here's some untested code that you might find useful. This goes
perhaps one step more than you asked for by allowing arbitrary
translation and rotation of the ellipse in addition to the scaling you
need.

	cairo_save (cr);
	{
	    cairo_translate (cr, x, y);
	    cairo_rotate (cr, angle_in_radians);
	    cairo_scale (cr, sx, sy);
	    cairo_arc (cr, 0.0, 0.0, 1.0,
		       0.0, 2 * M_PI);
	}
	cairo_restore (cr);

	cairo_set_line_width (cr, line_width);
	cairo_stroke (cr);

We use a save/restore pair here to allow the path to be affected by
the scaling, but not the stroke itself, (so that you will get a
uniform line width as desired).

-Carl
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/cairo/attachments/20060629/cebaf76d/attachment.pgp


More information about the cairo mailing list