From: Andrew Wagner Date: 2011-02-04T08:44:52+09:00 Subject: Re: Need a method to generate cubic spline control points --00032555ae2aa65e64049b695704 Content-Type: text/plain; charset=UTF-8 Hi Rich, So this math is a little over my head, but I can read the ruby and c# pretty well. If you want to draw a smooth curve through a set of lines, this is my best guess at what you need to do, from looking at that page and the attached code: 1.) make an array/list of points for your curve 2.) run them through the code that's on the page. you can read the code with the out parameters this way: def getCurveControlPoints(knots) firstControlPoints = [] secondControlPoints = [] # ... body of the method return [firstControlpoints,secondControlPoints] end Otherwise, translating that c# code is pretty straightforward. 3.) It gets a little fuzzy for me from here, since his code (in Window1.xaml.cs) uses a class, BezierSegment, which he doesn't provide the source for. However, it looks like he's saying that if you draw a line through firstControlPoints[i], secondControlPoints[i] and knots[i+1], for each i in the the indices of firstControlPoints, you will wind up with a Bezier curve. I'm not sure how to mentally parse that rmagick string you provided. It might be worth doing the above and just plotting the resulting points first, to see what you get. Hope this somehow helps! On Thu, Feb 3, 2011 at 4:17 PM, Richard Price wrote: > Hello: > > My name is Rich Price and I am looking for some help from a > person who is both a Ruby programmer and is mathematically > literate. Or at least more so than I am. > > Here is my problem. I wish to generate open and closed cubic > splines that pass through an array of "knot" points such as: > > [[x1, y1], [x2, y2], [x3, y3], [x4, y4]] > > But cubic splines require control points as well as "knot" > points. I need to generate the control points that will > result in a smooth curve. > > I found an article that explains how to do this and even > provides example code. But the code is written in C# > [a language that I do not know]. And I think it draws > lines whereas I want a method which would input the array > above and output a string which could then be input into a > rmagick path command. For example, taking the above array to > be an open curve and using cxn and cyn to be the generated > control points it should produce the following string: > > "Mx1,y1 Ccx1,cy1 cx2,cy2 x2,y2 Scx3,cy3 x3,y3 Scx4,cy4 x4,y4" > > A similar method would be needed to handle closed curves. > > The article with the equations needed for the generation of > these control points can be found at: > > > http://www.codeproject.com/script/Articles/ArticleVersion.aspx?aid=31859&av=56252 > > Please let me know if you would be interested in helping me > with this problem. > > -- > Posted via http://www.ruby-forum.com/. > > --00032555ae2aa65e64049b695704--