How to calculate shape layer position with scale animation relative to anchor point?
Copy link to clipboard
Copied
Hi, I need to calculate shape layer position, for example top left point A(x, y) for rectangle shape layer scale animation relative to anchor point. Is there any formula which describes point A movement? Base on data I am getting from AE I can get original position, but during animation only scale property changes.
I've attached few examples with different anchor point position.
Copy link to clipboard
Copied
You simply multiply the source sice with the normalized scale and then add it to the position (pseudo code):
position+size*scale/100
Mylenium
Copy link to clipboard
Copied
sourceRectAtTime() has Left, Width, Top, and Height properties that it can read from Text and Shape layers. If all you need is to grab the top left corner of any shape layer or text layer, then all you need is something like this:
ref = thisComp.layer("Shape Layer 1");
s = ref.scale / 100;
box = ref.sourceRectAtTime();
x = box.left;
y = box.top;
p = ref.position + [x * s[0], y * s[1]];
If you want to calculate the center of a shape or text layer, you have to add the width and height divided by 2 like this:
ref = thisComp.layer("Shape Layer 1");
s = ref.scale / 100;
box = ref.sourceRectAtTime();
x = box.width / 2 + box.left;
y = box.height / 2 + box.top;
p = ref.position + [x * s[0], y * s[1]];
If your shape layer has a stroke, you don't need to make any adjustments to return the center, but if you want a corner, you'll need to add the stroke value for the shape layer. If there is more than one shape with a stroke, they all need to have the stroke width to return any corner of the stroked layer.
If you must modify or animate the Shape Layer's anchor point also, you'll need to compensate for the change by multiplying the scale by anchor point, then subtracting the Anchor Point value from the position like this:
ref = thisComp.layer("Shape Layer 1");
s = ref.scale / 100;
box = ref.sourceRectAtTime();
x = box.width / 2 + box.left;
y = box.height / 2 + box.top;
ap = [ref.anchorPoint[0] * s[0], ref.anchorPoint[1] * s[1]];
p = ref.position - ap + [x * s[0], y * s[1]];
That should get you started, but your screenshots make me think that you have applied a mask to a large shape layer and that you are using the Mask to generate a path using Video Copilot's Saber plugin. If you want to attach another layer to a mask position, you'll need to run a different set of expressions to calculate the size of the mask. A starting point for that kind of problem would be to use the Window/Create Nulls from Paths/Nulls Follow Points script tool and then throw a scale multiplier into that calculation.

