<div dir="ltr"><font face="courier new,monospace"><font face="arial,helvetica,sans-serif">If you really want to get into the mathematics of how to choose the control point in order to get an optimal approximation of a quarter of a circle, then you should have a look at the MetaFont source code by Donal Knuth. See: <a href="http://www.tex.ac.uk/ctan/systems/knuth/dist/mf/mf.web">http://www.tex.ac.uk/ctan/systems/knuth/dist/mf/mf.web</a> . <br>
<br>But if you want simply want to do calculations like this it might be easier to use Asymptote <a href="http://asymptote.sourceforge.net/">http://asymptote.sourceforge.net/</a> , which is an evolution of MetaFont (via MetaPost). With Asymptote you can create paths by specifying with directions and tension, and it will calculate the control points for you. <br>
<br>Hope this helps.<br><br>Regards,<br>Dov<br></font></font><br><div class="gmail_quote">On Tue, Nov 15, 2011 at 11:43, Andrea Canciani <span dir="ltr"><<a href="mailto:ranma42@gmail.com">ranma42@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">(I forgot to write to the list... sorry for the double mail)<br>
<br>
<br>
---------- Forwarded message ----------<br>
From: Andrea Canciani <<a href="mailto:ranma42@gmail.com">ranma42@gmail.com</a>><br>
Date: Tue, Nov 15, 2011 at 10:42 AM<br>
Subject: Re: [cairo] Bezier curve<br>
To: Inderjit Singh <<a href="mailto:inderjit.singh@spaceapplications.com">inderjit.singh@spaceapplications.com</a>><br>
<div class="im"><br>
<br>
On Mon, Nov 7, 2011 at 3:42 PM, Inderjit Singh<br>
<<a href="mailto:inderjit.singh@spaceapplications.com">inderjit.singh@spaceapplications.com</a>> wrote:<br>
> Hi,<br>
><br>
> I'm new to cairo and I'm trying to draw a smooth curve between using an<br>
> array of points.<br>
><br>
> Say I have an array with (x,y) coordinates as: POS_T pos = {{0.0, 0.0},<br>
> {1.0,1.0}, {1.5, 2.0}, {0.5, 3.0}, {0.0, 4.0}};<br>
><br>
> So basically, a half round 'circle'. I've been looking in cairo docs but the<br>
> closest thing I get to is the cairo_curve_to but for that it requires<br>
> control points. How is it determined? I want a simple smooth line but using<br>
> Bezier algorithm requires additional data to make it happen. Is that<br>
> correct?<br>
<br>
</div>Yes, the additional data determines how the smoothing between the<br>
points is performed.<br>
You can choose the control points and get different smoothing types<br>
between your points.<br>
You might want to read something about splines (cairo supports cubic<br>
Bezier curves, which in turn can represent any parametric cubic<br>
curve).<br>
You can find an algorithm for cubic spline interpolation here<br>
<a href="http://en.wikipedia.org/wiki/Spline_interpolation" target="_blank">http://en.wikipedia.org/wiki/Spline_interpolation</a><br>
(I didn't test it).<br>
<div class="im"><br>
<br>
><br>
> Or can I simply use curve_line_to and then interpolate this? currently the<br>
> code looks like this for line:<br>
<br>
</div>cairo_line_to() would connect the points with straight line segments.<br>
<div class="im"><br>
><br>
> ...<br>
> for(uint32_t i = 0; i < boundary; i=i++)<br>
> {<br>
> cairo_move_to(cr, station->coverage[i].x, station->coverage[i].y);<br>
><br>
> // cairo_line_to(cr,<br>
> // station->coverage[(i+1) % boundary].x,<br>
> // station->coverage[(i+1) % boundary].y);<br>
><br>
> cairo_curve_to(cr,<br>
> station->coverage[i].x,<br>
> station->coverage[(i].y,<br>
> station->coverage[i+1].x,<br>
> station->coverage[i+1].y,<br>
> station->coverage[i+2].x,<br>
> station->coverage[i+2].y);<br>
> }<br>
><br>
> cairo_set_line_width (cr, 1.5);<br>
> cairo_stroke(cr);<br>
><br>
> cairo_destroy(cr);<br>
><br>
><br>
> Any help would be appreciated. Thanks.<br>
> Indy<br>
<br>
</div>If you need further information, just write ;)<br>
<br>
Andrea<br>
<br>
><br>
<span class="HOEnZb"><font color="#888888">><br>
> --<br>
> cairo mailing list<br>
> <a href="mailto:cairo@cairographics.org">cairo@cairographics.org</a><br>
> <a href="http://lists.cairographics.org/mailman/listinfo/cairo" target="_blank">http://lists.cairographics.org/mailman/listinfo/cairo</a><br>
><br>
--<br>
cairo mailing list<br>
<a href="mailto:cairo@cairographics.org">cairo@cairographics.org</a><br>
<a href="http://lists.cairographics.org/mailman/listinfo/cairo" target="_blank">http://lists.cairographics.org/mailman/listinfo/cairo</a><br>
</font></span></blockquote></div><br></div>