Re: Fwd: Bezier curve

Inderjit Singh <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <c033854e-67f9-4fd3-b2be-10b1ff93a56f@is-PC>
Thanks for the answers. 

I simply added more points and used cairo_line_to instead. It was sufficient for me and it made things a lot easier. 

Indy 

----- Original Message -----

From: "Dov Grobgeld" <[email protected]> 
To: "Andrea Canciani" <[email protected]> 
Cc: "cairo list" <[email protected]> 
Sent: Tuesday, 15 November, 2011 11:10:08 AM 
Subject: Re: [cairo] Fwd: Bezier curve 


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: http://www.tex.ac.uk/ctan/systems/knuth/dist/mf/mf.web . 

But if you want simply want to do calculations like this it might be easier to use Asymptote http://asymptote.sourceforge.net/ , 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. 

Hope this helps. 

Regards, 
Dov 


On Tue, Nov 15, 2011 at 11:43, Andrea Canciani < [email protected] > wrote: 


(I forgot to write to the list... sorry for the double mail) 


---------- Forwarded message ---------- 
From: Andrea Canciani < [email protected] > 
Date: Tue, Nov 15, 2011 at 10:42 AM 
Subject: Re: [cairo] Bezier curve 
To: Inderjit Singh < [email protected] > 



On Mon, Nov 7, 2011 at 3:42 PM, Inderjit Singh 
< [email protected] > wrote: 
> Hi, 
> 
> I'm new to cairo and I'm trying to draw a smooth curve between using an 
> array of points. 
> 
> Say I have an array with (x,y) coordinates as: POS_T pos = {{0.0, 0.0}, 
> {1.0,1.0}, {1.5, 2.0}, {0.5, 3.0}, {0.0, 4.0}}; 
> 
> So basically, a half round 'circle'. I've been looking in cairo docs but the 
> closest thing I get to is the cairo_curve_to but for that it requires 
> control points. How is it determined? I want a simple smooth line but using 
> Bezier algorithm requires additional data to make it happen. Is that 
> correct? 

Yes, the additional data determines how the smoothing between the 
points is performed. 
You can choose the control points and get different smoothing types 
between your points. 
You might want to read something about splines (cairo supports cubic 
Bezier curves, which in turn can represent any parametric cubic 
curve). 
You can find an algorithm for cubic spline interpolation here 
http://en.wikipedia.org/wiki/Spline_interpolation 
(I didn't test it). 



> 
> Or can I simply use curve_line_to and then interpolate this? currently the 
> code looks like this for line: 

cairo_line_to() would connect the points with straight line segments. 


> 
> ... 
> for(uint32_t i = 0; i < boundary; i=i++) 
> { 
> cairo_move_to(cr, station->coverage[i].x, station->coverage[i].y); 
> 
> // cairo_line_to(cr, 
> // station->coverage[(i+1) % boundary].x, 
> // station->coverage[(i+1) % boundary].y); 
> 
> cairo_curve_to(cr, 
> station->coverage[i].x, 
> station->coverage[(i].y, 
> station->coverage[i+1].x, 
> station->coverage[i+1].y, 
> station->coverage[i+2].x, 
> station->coverage[i+2].y); 
> } 
> 
> cairo_set_line_width (cr, 1.5); 
> cairo_stroke(cr); 
> 
> cairo_destroy(cr); 
> 
> 
> Any help would be appreciated. Thanks. 
> Indy 

If you need further information, just write ;) 

Andrea 

> 
> 
> -- 
> cairo mailing list 
> [email protected] 
> http://lists.cairographics.org/mailman/listinfo/cairo 
> 
-- 
cairo mailing list 
[email protected] 
http://lists.cairographics.org/mailman/listinfo/cairo 




-- 
cairo mailing list 
[email protected] 
http://lists.cairographics.org/mailman/listinfo/cairo

--
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.