Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions find Y value of path at specific X value

  • find Y value of path at specific X value

  • Whitney Clegg

    November 24, 2021 at 1:32 am

    Hello,

    Here is a simplified version of a composition I’m working on. There is a row of rectangles with a linear gradient on each of them running from top to bottom. Across this row is a path I have drawn. I would like to attach the y value of the middle of each gradient to the path where it crosses the middle of that rectangle.

    I’ve almost achieved the result I want using .pointOnPath calculated at the percentage of the distance of the x position of the rectangle to the width of the composition, but this is actually too imprecise for my actual composition. Due to the curvature of my path that percentage along the path isn’t really lining up with the x position of each rectangle. What I want to do is find the exact y value of the path where it crosses the exact x value of each rectangle. Can you think of a way to do this?

    <br class=”simplyweb-checked”>

    Right now this is how I’m getting the y value for the middle of my gradient:

    thisComp.layer(“Path”).transform.position[1] + thisComp.layer(“Path”).content(“Path 1”).path.pointOnPath((transform.xPosition / thisComp.width))[1]

    <br class=”simplyweb-checked”>

    Thank you!

  • Andrei Popa

    November 24, 2021 at 9:22 am

    Hi Whitney. I think this should work better. It’s not 100% accurate, but more accurate than before. Basically, it checks for every percent if it passed the center of the current rectangle. When it passed, it returns the value. It will work bad if you have loops in your shape, but if it is similar to the example, it should work

    myPathLayer = thisComp.layer("Path");

    myPath = thisComp.layer("Path").content("Path 1").path;

    startPosition = myPath.pointOnPath(0);

    arbitraryX = xPosition + startPosition[0];

    i = 1;

    while (startPosition[0] < arbitraryX) {

    startPosition = myPath.pointOnPath(i / 100);

    i++;

    }

    startPosition[1] + myPathLayer.position[1];

Viewing 1 - 2 of 2 posts

Log in to reply.

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