Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Bezier Interpolation, Arrays, Searching Arrays ;)!

  • Bezier Interpolation, Arrays, Searching Arrays ;)!

    Posted by Lu Nelson on February 21, 2010 at 2:14 pm

    Hi,

    So this is an attempt at using a bezier curve as an interpolation curve. And it’s a long post.

    I figured out how to generate a bezier after looking at the math on Dan Ebberts’ bezier curve tutorial, and then looking at some reference pages that were linked in other discussions of beziers. Then I ran in to a wall on the question of how you could make use of such a curve for interpolation, because in a bezier curve, y is not expressed in terms of x.

    Anyway, digressing: I did get as far as generating a curve from 0 to 1, applying the general math for these curves and using the Mac OS utility “Grapher” (screenshots included below); but as I say, because it’s parametric (x and y are not expressed in terms of one another, but in terms of a third variable) I was stumped for a while on how I could map it as an interpolation curve. Finally, the only way I could think of to get useful data from it was to generate a given number of samples from this curve, as an array, and then search/sample this array for the x value closest to my reference point (my current time for example) and then take the y value which corresponds to it. Thus y in terms of a given x.

    The formula I used is somewhat simplified from its generic form, because I’m taking only a curve with a startpoint at [0,0], endpoint at [1,1], and control points which move only horizontally, toward the middle (I put them in terms of an “influence” value or “inf” which is between 0 and 1). Their coordinates are therefore going to be [inf,0] and [1-inf,1]. Take a look at the screeenshots from Grapher, to visualize what this variable “inf” does to the curvature:

    influence_00.png
    influence_05.png
    influence_10.png

    If you’re familiar with the math on this, you’ll notice also that the expressions for x and y are simplified. This is due to the specifics of this case, where we’re looking at [0,0] to [1,1], as I’ve noted. Also the variable “t” is not necessarily “time”. That can throw you off. You could also see it as “z” in a way, because a bezier is in a sense a 2D projection of a 3D curve.

    OK, so now where I’m stuck is (1.) with the syntax and logic of using arrays (assuming this is the way to go): I’m sure I’m missing something here, in the expression I’ve written. Probably initiating the “curve” array the wrong way? I don’t know.

    Also, (2.) I’m not sure where to place this expression because the array itself doesn’t really need to be regenerated on each frame. Could it be placed in a text.source property or something?

    Finally, (3.) I have no idea how to search the array (or rather, the sub-arrays of the array). I read a bit about “binary search”, but I’m just a bit too out of touch with this stuff to see how to implement it. The basic idea would be to find the x value closest to my current time, in seconds, and return the corresponding y value. In that case the curve’s value range from y=0 to y=1, would map to the time span from 0 to 1 seconds.

    Note: the “samples” value is probably going to be passed in from somewhere else, if I get this thing working — but what it represents is simply how many frames I’m going to need this interpolation curve for, so in this example since I’m assuming it’s 1 seconds and I have a comp frame rate of 30, I took 30. It’d be a function of the duration and frame rate that I wanted to map the interpolation to.

    Anyway, this is as far as I got:

    inf = 0.5;
    samples = 30;
    curve = [[]];

    for ( i = 0; i < samples; i++ ) { t = i/samples; curve[i][0] = (1-3*(1-2*inf))*t*t*t + (3(1-2*inf)-3*inf)*t*t + 3*inf*t; curve[i][1] = -2*t*t*t + 3*t*t; } This bit of code is already wrong, somehow; but the bigger problem as I've said, is how to search and retrieve the right values from it. Any takers? Thanks in advance..... LMN Lu Nelson Berlin, Germany -- [MacProQ2.66, 8GB, Sys10.5.6, FCP 6.0.5, AE 9.0.2]

    Lu Nelson replied 16 years, 2 months ago 1 Member · 0 Replies
  • 0 Replies

Sorry, there were no replies found.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy