View all expressions
Interpolation

Constrain Shape Layer Inside Circle Bounds

Keeps a smaller shape layer constrained inside a larger circle by calculating and limiting its position, ensuring it stays within the boundaries.

Contributed by:


largeCircle = thisComp.layer("LargeCircle");
largePosition = largeCircle.position;
largeRadius = largeCircle.content("Ellipse 1").content("Ellipse Path 1").size[0] / 2;
smallRadius = content("Ellipse 1").content("Ellipse Path 1").size[0] / 2;
delta = position - largePosition;
distance = length(delta);
if (distance > (largeRadius - smallRadius)) {
constrainedDelta = normalize(delta) * (largeRadius - smallRadius);
constrainedPosition = largePosition + constrainedDelta;}
else {
constrainedPosition = position;}
constrainedPosition;

Constrain Shape Layer Inside Circle Bounds

Practical use case

Ideal for creating animations where smaller objects, like buttons or icons, need to move freely but stay within a circular frame.

Check out similar expressions

Data-driven video workflows for After Effects are easier with Plainly.

a mesh of elegant lines transparent image