Need a method to generate cubic spline control points

R

Richard Price

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.
 
A

Andrew Wagner

[Note: parts of this message were removed to make it a legal post.]

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, secondControlPoints 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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,731
Latest member
MarcyGipso

Latest Threads

Top