Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Author
Message
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 4th Jan 2012 00:46 Edited at: 4th Jan 2012 05:06
I'm having difficulty with implementing the more advanced splines for animation curves. Not really the splines themselves since theres hundreds of articles out there. But it's the returning of the single valve that I'm having difficulty with. For instance Bezier interpolation, I'd imagine that you'd have to calculate the x line (time scale) and run that through the y line to return a resulting value. But I can't find a single example of how to do this. Every example separates the calculation for 2d point drawing.

Linear is simple and can be done in a single line:
out = (((time-key0.x)*(key1.y-key0.y))/(key1.x-key0.x))+key0.y

'key' the control point, 'x' being time and 'y' being value. 'out' would be the resulting value based on the time.

But for something like Bezier where you have 'x' and 'y' plus a direction vector defined by say 'x2' and 'y2' it would look like:

(pseudo code, just off the top of my head)
t0 = (time-key0.x)/(key1.x-key0.x)
t1 = 1-t0
p0 = t1*t1*t1 // faster than doing t1^3 multiple times
p1 = t1*t1
p2 = t0*t0
p3 = t0*t0*t0

outx = key0.x*p0 +3*key0.x2*p1*t0 +3*key1.x2*t1*p2 + key1.x*p3
outy = key0.y*p0 +3*key0.y2*p1*t0 +3*key1.y2*t1*p2 + key1.y*p3

That's fine for drawing, well sort of if you wanted to draw a point every single frame (you'd create divisions for drawing 2D and 3D). But returning one value not so good. I also don't have a clue how you'd combine them, can't find an article for that, unless it has a different name maybe.

So my question is how do you covert these different interpolation methods for use of animation curves with a single resulting value?
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 4th Jan 2012 01:35
@Sasuke
Hi mate. Have a look to this piece of code from phaelax...pehaps it can help.




Cheers.



I'm not a grumpy grandpa
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 4th Jan 2012 03:05
Cheers chafari, but same problem, good for drawing not for returning values.
BatVink
Moderator
23
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 4th Jan 2012 09:12
I have always used the same code for drawing and getting a position, as it is the same thing. In the code I use (taken from an article on the internet) you represent the curve as a line from 0.0 to 1.0. then you supply a point on the line (e.g 0.5) to get the x,y values for that point. Then, you either draw with it or use it for any other purpose you have.

My purpose was to draw a track. I got points 0.0 to 1.0 in increments of 0.01, saved them in an array and used them to draw the track from quads. I then used the same points to place the car (point p) and point it in the direction of the next track section (point p + 1)

Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 4th Jan 2012 20:48
Cheers BatVink, I give it a go. Out of interest, can anyone see the problem with this bit of code for 2d drawing of a Bezier curve. For some reason it just won't work correctly. But it works completely fine for 3d Bezier curves, all I did was take away the z component.



Even if the direction vectors are set to nothing the first point is bugged for some reason.

I'm also making a program to display/alter curves, linear at the mo.
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 7th Jan 2012 18:37 Edited at: 7th Jan 2012 18:40
Ok, got it, just my math was off the first time. Now it's just a case of learning how to combine two different interpolation. Hmm...



Anyone have any clue how you combine interpolations?
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 7th Jan 2012 20:00
what do you mean combine them?

Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 7th Jan 2012 20:20
So a key point would leave with a cubic interpolation (it's output) and the next key point would receive with linear interpolation (it's input). So it would start with a curve which would turn into a straight line somewhere in the middle. Basically I want to be able to combine different types of curves between key points. I've look at quite a few articles on tangents, not going to lie, there slight confusing.
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 7th Jan 2012 23:36 Edited at: 7th Jan 2012 23:36
I would just linear interpolate the two interpolants xD

So you have two interpolating functions, X1[t] and X2[t] As t goes from 0 to 1, the line goes from the previous point to the next point. So, we can linear interpolate these two functions!
X[t]=(X2[t]-X1[t])*t+X1[t]
So when t is small, X[t]~=X1[t], and when t is 1ish, X[t]~=X2[t].

Login to post a reply

Server time is: 2026-07-09 22:48:55
Your offset time is: 2026-07-09 22:48:55