# Creative Communities of the World Forums

The peer to peer support community for media production professionals.

• # Link shapes with expressions

5 Members · 9 Posts
• ### Livio Maraniello

September 14, 2020 at 5:34 am

Hi everyone! I was wondering if anyone can help me with this. As you can see in the image, I have a circle that moves within two shapes and I was wondering if there is an expression that allows me to automatically scale the circle up and down as the space between the 2 shapes increase or decrease.

Hope this makes sense.

• ### Andrei Popa

September 14, 2020 at 6:17 am

You increase the space by moving the shapes up and down? Because if you do this, things are not very complicated.

But if you move them left and right and the circle must stay in center and grow as the space gets bigger, thing get a lot more complicated.

• ### Livio Maraniello

September 14, 2020 at 10:02 am

Yeah, basically I was thinking of the complicated way. I wanted to link the circle to both top and bottom shapes and moving it on the x axis, so that as the space between the shapes increases the circles size up too

• ### Filip Vandueren

September 14, 2020 at 11:38 am

How are shape A and B created ? Is it a wiggle Paths, or a deliberate design that we need to conform to ?

• ### Matt Volp

September 14, 2020 at 11:56 am

You could draw the wavy lines as paths, trace them using ‘Create Nulls From Paths’ and then drive the size of the circle by the position of the resulting nulls?

• ### Livio Maraniello

September 14, 2020 at 11:28 pm

Hi Filip,

The shapes A and B are deliberately designed like that, no effects have been applied to them.

• ### Brendon Murphy

September 15, 2020 at 5:54 am

This works:

On a new solid, draw a path along the ceiling (just the surface where the ball will touch). Do the same for the floor on another solid.

Add a circle using the ellipse tool (this assumes you will have a uniform circle). Be sure to zero out the shape’s anchor point and position under “Contents” so it matches the layer anchor point.

Add three null objects. One will be the “Leader” that you animate on the x axis. The other two, “Top Tracer” and Bottom Tracer” will follow along the top and bottom paths when you paste this into the “position” parameter (change pathLayer so you have the correct paths selected):

pathLayer = thisComp.layer(“Bottom Path”)

startPos = pathLayer.toComp(pathToTrace.pointOnPath(0));

endPos = pathLayer.toComp(pathToTrace.pointOnPath(1));

pathWidth = endPos[0]-startPos[0];

followOffset = 0-startPos[0];

pathUnits = 1/pathWidth;

pathLayer.toComp(pathToTrace.pointOnPath(progress));

On your ball, use this for position:

topTracer = thisComp.layer(“Top Tracer”).transform.position;

bottomTracer = thisComp.layer(“Bottom Tracer”).transform.position;

vertPos = (topTracer[1]+bottomTracer[1])/2;

[horizPos,vertPos];

And for the ball’s scale:

topTracer = thisComp.layer(“Top Tracer”).transform.position;

bottomTracer = thisComp.layer(“Bottom Tracer”).transform.position;

neededHeight = topTracer[1]-bottomTracer[1];

origHeight = content(“Ellipse 1”).content(“Ellipse Path 1”).size[1];

newHeight = (neededHeight/origHeight)*100;

[newHeight,newHeight];

Hope that helps!

• ### Filip Vandueren

September 15, 2020 at 6:42 pm

Put some time in this today.

I got it not perfect, but pretty damn close 🙂

The thing is that there is no method to find the point on a Path that is nearest to another point, and that’s what we need for precision.

Ì wrote a function that recursively approximates/guesses the nearest point on the paths for the current Ball-position (a Null Object actually).

Then the best position for the Y value of the Null is approximated, one where the nearest point on the ceiling and the nearest point on the floor are equally far apart.

It works best if you try to place the null on a spot that is already kind of equidistant between floor and ceiling. So, that can take some tweaking, just a few keyframes though.

To get it perfect, more recursions of the recursion were necessary and that just calculated way to slow (about a second per frame, just for the expression), and I thought that wasn’t worth it.

Here is the project: https://we.tl/t-nQsRsPrTev

• ### Matt Volp

September 23, 2020 at 8:07 pm

This is super impressive.

Viewing 1 - 9 of 9 posts