Parametric splines
Hi;
Did anyone implemented (or had the formulas) a program to, given a set of N points in 3d space, calculate the N-1 parametric equations for the segments? thanx
depends on how you want to interpolate between those points of yours doesnt it? more information would be nice, like are the point evenly spaced?
Well, its something like this: i have a camera, and i want it to follow a path....so i will choose some points from my world , and then the camera would pass in each point, in a curved path, like splines from MAX...the points are not linearly distributed, they are random....
The most natural algorithm for this would be a natural cubic spline. Searching for that might find something useful. There are probably a lot of libraries, as well, that implement various cubic splines, NURBS, etc. I wrote my own to do various cubic splines about a year ago, but I don''t have it with me right now, and it probably could use some cleaning up, anyway.
int Agony() { return *((int*)0); } Mwahaha... >8)
int Agony() { return *((int*)0); } Mwahaha... >8)
Given 4 points, (p0, p1, p2, p3), and the parameter t, in the range of [0,1] and denoting an arbitrary point between p1 and p2:
It''s called cubic interpolation and requires 4 control points on the curve to calculate.
P = (p3 - p2) - (p0 - p1)Q = (p0 - p1) - PR = p2 - p0S = p1return P*t*t*t + Q*t*t + R*t + S
It''s called cubic interpolation and requires 4 control points on the curve to calculate.
@vertexnomral
i find that method works not very good. although the path is constant, the speed is lower close to the control points or something.
heres my personal favorite:
multiply this matrix:
[0, 1, 0, 0]
[-1/2, 0, 1/2, 0]
[1, -5/2, 2, -1/2]
[-1/2, 3/2, -3/2, 1/2]
with a matrix looking like this:
(cp stands for contol point)
[cp0x, cp0y, cp0z]
[cp1x, cp1y, cp1z]
[cp2x, cp2y, cp2z]
[cp3x, cp3y, cp3z]
the outcome matrix looks like this:
[c0x, c1x, c2x, c3x]
[c0y, c1y, c2y, c3y]
[c0z, c1z, c2z, c3z]
which are the coefficients for a third order curve, the number denoting the power of each term, ie x = c0x + c1x*i + c2x*i^2 + c3x*i^3, etc.
''i'' being in the range 0-1.
by far the best interpolation method ive come across, and all it needs as input are four points, you dont have to worry about setting directions or anything.
i find that method works not very good. although the path is constant, the speed is lower close to the control points or something.
heres my personal favorite:
multiply this matrix:
[0, 1, 0, 0]
[-1/2, 0, 1/2, 0]
[1, -5/2, 2, -1/2]
[-1/2, 3/2, -3/2, 1/2]
with a matrix looking like this:
(cp stands for contol point)
[cp0x, cp0y, cp0z]
[cp1x, cp1y, cp1z]
[cp2x, cp2y, cp2z]
[cp3x, cp3y, cp3z]
the outcome matrix looks like this:
[c0x, c1x, c2x, c3x]
[c0y, c1y, c2y, c3y]
[c0z, c1z, c2z, c3z]
which are the coefficients for a third order curve, the number denoting the power of each term, ie x = c0x + c1x*i + c2x*i^2 + c3x*i^3, etc.
''i'' being in the range 0-1.
by far the best interpolation method ive come across, and all it needs as input are four points, you dont have to worry about setting directions or anything.
quote:Original post by Eelco
@vertexnomral
[0, 1, 0, 0]
[-1/2, 0, 1/2, 0]
[1, -5/2, 2, -1/2]
[-1/2, 3/2, -3/2, 1/2]
by far the best interpolation method ive come across, and all it needs as input are four points, you dont have to worry about setting directions or anything.
Funny ! Can you explain this a bit more ?
What is the matrix for a 5 control points spline ?
quote:
Funny ! Can you explain this a bit more ?
yes, i can.
what do you know about the curve C(i) = c0 + c1*i + c2*i^2 + c3*i^3 we want?
we want C(0) to be cp1
we want C(1) to be cp2
so:
C(0) = cp1
C(1) = cp2
we have four unknown, our coefficients c0 to c3, so we need two more equations. we havnt yet defined anything about the direction, or derivative of our curve.
(cp2-cp0)/2 is the average gradient between these points. cp1 lies in the middle of them, so this would be a nice candidate for the derivative of C at point cp1 aka i=0. so:
C''(0) = (cp2-cp0)/2
and following the same logic:
C''(1) = (cp3-cp1)/2
yay, four equations.
c0*1 + c1*0 + c2*0 + c3*0 = cp1
c0*1 + c1*1 + c2*1 + c3*1 = cp2
c0*0 + c1*1 + c2*0 + c3*0 = (cp2-cp0)/2
c0*0 + c1*1 + c2*2 + c3*3 = (cp3-cp1)/2
omg, a martix!!11
if you rewrite that a bit you have the matrix that transforms your constants into your control points. invert it, and you get the opposite.
quote:
What is the matrix for a 5 control points spline ?
i dont think a 5-control point spline would make much sense, since your control points wouldnt lie symetricly spaced around your interval. 6 control point would though. if you pick 6 convenient relations between your function on the interval 0-1 and these 6 control points, you can apply the same logic to that, and get a 6x6 matrix.
hey thats weird...
my last post didnt increase the number of posts, not did it bump this thread..
?
my last post didnt increase the number of posts, not did it bump this thread..
?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement