<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">&lt;<a href="mailto:ranma42@gmail.com">ranma42@gmail.com</a>&gt;</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 &lt;<a href="mailto:ranma42@gmail.com">ranma42@gmail.com</a>&gt;<br>
Date: Tue, Nov 15, 2011 at 10:42 AM<br>
Subject: Re: [cairo] Bezier curve<br>
To: Inderjit Singh &lt;<a href="mailto:inderjit.singh@spaceapplications.com">inderjit.singh@spaceapplications.com</a>&gt;<br>
<div class="im"><br>
<br>
On Mon, Nov 7, 2011 at 3:42 PM, Inderjit Singh<br>
&lt;<a href="mailto:inderjit.singh@spaceapplications.com">inderjit.singh@spaceapplications.com</a>&gt; wrote:<br>
&gt; Hi,<br>
&gt;<br>
&gt; I&#39;m new to cairo and I&#39;m trying to draw a smooth curve between using an<br>
&gt; array of points.<br>
&gt;<br>
&gt; Say I have an array with (x,y) coordinates as: POS_T pos = {{0.0, 0.0},<br>
&gt; {1.0,1.0}, {1.5, 2.0}, {0.5, 3.0}, {0.0, 4.0}};<br>
&gt;<br>
&gt; So basically, a half round &#39;circle&#39;. I&#39;ve been looking in cairo docs but the<br>
&gt; closest thing I get to is the cairo_curve_to but for that it requires<br>
&gt; control points. How is it determined? I want a simple smooth line but using<br>
&gt; Bezier algorithm requires additional data to make it happen. Is that<br>
&gt; 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&#39;t test it).<br>
<div class="im"><br>
<br>
&gt;<br>
&gt; Or can I simply use curve_line_to and then interpolate this? currently the<br>
&gt; 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>
&gt;<br>
&gt; ...<br>
&gt;     for(uint32_t i = 0; i &lt; boundary; i=i++)<br>
&gt;     {<br>
&gt;         cairo_move_to(cr, station-&gt;coverage[i].x, station-&gt;coverage[i].y);<br>
&gt;<br>
&gt; //        cairo_line_to(cr,<br>
&gt; //                      station-&gt;coverage[(i+1) % boundary].x,<br>
&gt; //                      station-&gt;coverage[(i+1) % boundary].y);<br>
&gt;<br>
&gt;         cairo_curve_to(cr,<br>
&gt;                      station-&gt;coverage[i].x,<br>
&gt;                      station-&gt;coverage[(i].y,<br>
&gt;                      station-&gt;coverage[i+1].x,<br>
&gt;                      station-&gt;coverage[i+1].y,<br>
&gt;                      station-&gt;coverage[i+2].x,<br>
&gt;                      station-&gt;coverage[i+2].y);<br>
&gt;     }<br>
&gt;<br>
&gt;     cairo_set_line_width (cr, 1.5);<br>
&gt;     cairo_stroke(cr);<br>
&gt;<br>
&gt;     cairo_destroy(cr);<br>
&gt;<br>
&gt;<br>
&gt; Any help would be appreciated. Thanks.<br>
&gt; Indy<br>
<br>
</div>If you need further information, just write ;)<br>
<br>
Andrea<br>
<br>
&gt;<br>
<span class="HOEnZb"><font color="#888888">&gt;<br>
&gt; --<br>
&gt; cairo mailing list<br>
&gt; <a href="mailto:cairo@cairographics.org">cairo@cairographics.org</a><br>
&gt; <a href="http://lists.cairographics.org/mailman/listinfo/cairo" target="_blank">http://lists.cairographics.org/mailman/listinfo/cairo</a><br>
&gt;<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>