I'm trying to create a spline path as seen in the link below but trying to find the fomular to use has been the most difficult aspect since I don't know how to interpolate the points. The spline will be used to create a path for a game I'm making were I need objects to follow such a path (is sonething a bit similar to zuma deluxe: http://www.terragame.com/screens/zuma_deluxe.jpg ).
@ne555 thanks, but after scouring through Google for the algorithms I was met with maths I haven't learnt yet (currently doing A-level maths whilst on degree). Its just taking ages plus it usually filled with jargon that leads to jargon on most sites.
But now I've realised that I'm looking for the Hermite Spline algorithm instead, is yours it? I dont quite understand it yet since I don't understand what
a, b and c are points. \alpha is a number
a_j, or a[j] represents one cartesian coordinate of the point
a[0] = x
a[1] = y
a[2] = z
...
That formula is showing how to calculate the coordinates of the interpolation point.
Taking different values for alpha (factor of interpolation) we get different interpolated points.
It could be writted as c[j] = w1 a[j] + w2 b[j] where w1 + w2 = 1
As you can see, when we interpolate, we assign a weigth to every point. Larger the weigth, the result will be near to that point.
(like an atraction force, if it is negative it will repel it)
So if we take \alpha = 0, we get c = a
\alpha = 1, then c = b
\alpha = 0.5, c is the midpoint.
If you take 0 <= \alpha <= 1 the result will land between the control points (a, b).
else it will land outside.
But always on the straight line that connects 'a' with 'b'
Now, Bézier. Let's just take order 3, that uses 4 control points.
First and last points are the endpoints of the curve.
The other mark the derivatives of the curve at those endpoints. (the arrows)
So p0, endpoint
vector (p1-p0), start direction. Larger its modulo faster will go.
Now you 'interpolate' the 4 points, with De Casteljau algorithm.
And here is something interesting. \alpha is now time.
At time=0 you are at the start (p0), at time=1 you are at the goal (p3)
Intermediate times will give you intermediate positions that are not equally spaced, but that take into account your 'particle' velocity.
You want Hermite. That one ask for continuity of endpoints and its velocities.
So you need to make sure that p3 = q0
and vector(p2-p3) = - vector(q1-q0)
p'(0) = p1-p0 - ok (derivative at first end is pointing towards first control point)
p'(1) = p2-p3 - ok (derivate at other end is pointing towards second control point)
so the formula look right to me after all
are you sure you have programmed it right?
p0, p1, p2, and p3 are vectors. to multiple a vector by a scalar you just multiply each element by the scaler
p0 is the start point of the spline and p3 the end point