|
![](/i/fill.gif) |
> Given an array of {t, Point} where t is a floating point number, between
> 0 to 1, and Point is a point in the 2D plane. (The array can be sorted
> by ascending t.)
>
> Now I want a formula f(t) that returns a "smooth path" going through all
> these points.
Unfortunately there is no simple formula/algorithm and you'll need to do
a bit of maths and geometry if you're coding it all yourself.
Start by splitting the curve up into segments between each point and
have a separate f(t) for each segment. A cubic bezier will likely be
your best bet and it is guaranteed to actually go through all points and
you can control the gradient (in space and time) at the start and end of
each segment to match with the neighbours.
Here is a good demo to get the feel of what the control points do:
http://blogs.sitepointstatic.com/examples/tech/canvas-curves/bezier-curve.html
Wikipedia has the formulas you need, use the 2nd one from this section:
http://en.wikipedia.org/wiki/B%C3%A9zier_curve#Cubic_B.C3.A9zier_curves
P0 and P3 are your start and end points in each section, P1 and P2 are
"control points" that control the shape of the curve. Looking at the
equation further down for B'(t) you can figure out that for the adjacent
segments to match in gradient you need P1-P0 of one segment to equal
P3-P2 of the next section.
Post a reply to this message
|
![](/i/fill.gif) |