Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Graph Animation Problem

  • Graph Animation Problem

    Posted by Dan Darling on November 18, 2020 at 7:47 pm

    Hello!

    I do not have a ton of experience with AE expressions. This may be a simple fix..

    I am trying to animate a vertical line across a graph and have an object track the intersection between the two lines. Im having trouble figuring out how to control the x axis independently so that wherever it moves, the y axis tracks the graph line. Maybe there is a way to track the intersection of the two lines? Or another way of approaching the problem?

    In my example the blue dot is tracking the graph line, but not tracking the x position of the vertical line. Ideally I would have a rig where I could freely move the vertical line and the dot will follow the intersection.

    I searched around and could not find any other threads like this. Would love any input!

    Thanks!

    Dan Darling replied 5 years, 6 months ago 2 Members · 3 Replies
  • 3 Replies
  • Dan Darling

    November 18, 2020 at 7:48 pm
  • Dan Ebberts

    November 18, 2020 at 8:47 pm

    It’s not particularly simple, but if your graph is a function of x (never loops back so there are multiple values of y for the same x), a binary search like this should work:

    x = thisComp.layer("Vertical Line").transform.position[0];

    L = thisComp.layer("Graph");

    p = L.content("Shape 1").content("Path 1").path;

    iterations = 12;

    p0 = L.toComp(p.pointOnPath(0));

    p1 = L.toComp(p.pointOnPath(1));

    if (x < p0[0]){

    p0;

    }else if (x > p1[0]){

    p1;

    }else{

    lower = 0;

    mid = .5;

    upper = 1.0;

    for ( i = 0; i < iterations; i++){

    pCur = L.toComp(p.pointOnPath(mid));

    if (pCur[0] == x) break;

    if (pCur[0] > x){

    upper = mid;

    }else{

    lower = mid

    }

    mid = (upper+lower)/2;

    }

    pCur

    }

  • Dan Darling

    November 19, 2020 at 3:09 am

    Woah, Dan you are a genius. Works like a dream!

    Cheers

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