ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Parented layer spaces - expression formulas for an offset piston

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
George Umanov
Parented layer spaces - expression formulas for an offset piston
on Apr 14, 2018 at 4:02:04 am

Hi all,

I've been attempting to animate a piston attached to a "wheel".
The odd thing about my setup is that the piston is not centered in-line with the wheel - rather it's offset by a distance from the wheels center.

I found a great resource on this website on a piston animation setup, where the piston is centered.
See here:
https://library.creativecow.net/articles/ebberts_dan/expressions.php

I was able to duplicate this in After Effects without issues.
But my several days worth of attempts at animating an offset piston setup have failed.

Here is my attempt at the math:
https://i.imgur.com/OHsY3RF.png
Similar to the above website, just adjusted for the offset.

I'm pretty sure I keep failing because I have a terrible understanding of layer spaces for "child" layers.

According to my math, I need the length of "h" - but I don't know how to write the after effects formula for "h".
It's the piston offset distance on the y-axis. And since my piston if the child of the crank rod, which is the child of the wheel, my attempts don't work correctly.

Any help with how to write the expression for "h" will be greatly appreciated.

Crank rotation:

rad2deg=180/Math.PI;
deg2rad=Math.PI/180;
r=length(this_comp.layer("wheel").anchor_point,position);
l=length(anchor_point,this_comp.layer("piston").position);
pistonoffset=sub(this_comp.layer("wheel").anchor_point,this_comp.layer("piston").anchor_point);
h=pistonoffset[1];
adjust=Math.asin((r*Math.sin(this_comp.layer("wheel").rotation*deg2rad)-h)/l)*rad2deg;
-this_comp.layer("wheel").rotation+adjust;


Piston rotation:

-1*(this_comp.layer("wheel").rotation+this_comp.layer("crank").rotation)


Return to posts index

Kalleheikki Kannisto
Re: Parented layer spaces - expression formulas for an offset piston
on Apr 14, 2018 at 7:43:32 am

Why do you need a formula for h if h is a constant?

Kalleheikki Kannisto
Senior Graphic Designer


Return to posts index

George Umanov
Re: Parented layer spaces - expression formulas for an offset piston
on Apr 14, 2018 at 2:38:31 pm

I just figured it would be more accurate to calculate it rather than try to figure out the pixel distance myself, but I suppose I could just throw in a null at the anchors and subtract the y-values myself. I’ll see where that gets me.

Does each piece need to be in a specific position when I apply the parenting and the expressions? I’m assuming everything need to be position to a “starting point”?

So wheel at 0 deg, anchor center. Crank rod at specific angle toward the piston, anchored on outside of wheel. And piston at its offset position with 0 displacement, anchored where it meets the crank rod.
This is where I would apply the parenting, followed by the expressions?


All my attempts result in a ridiculous “wobble” of the piston, caused by a crank rod end that draws a circle not a line.


Return to posts index


Steve Bentley
Re: Parented layer spaces - expression formulas for an offset piston
on Apr 14, 2018 at 3:22:33 pm

If the piston and wheel are graphics in the comp you can simplify the whole thing by just parenting one object to the other (with an offset anchor point) and having the animation of one drive the other. Depending on your set up you may have to do an expression that uses only one of the pistons position's attributes (x or y) so that the rotational motion of the wheel doesn't make the piston angle.

You could also use an IK chain. You can do a simple script to make this (hint the child is always "looking" back at the parent) or you could use a free resource like DUIK to set that up for you.



Return to posts index

Kalleheikki Kannisto
Re: Parented layer spaces - expression formulas for an offset piston
on Apr 15, 2018 at 7:25:49 am

If you use parented nulls, like Steve suggests, the only thing you need to calculate is the x position of the piston connection point, which can be derived with the pythagorean triangle from the distance to the point that is tracing a circle (c).

The main issue is that parented nulls live in their own coordinate system. The global position of a parented null, courtesy of Dan Ebberts, is:

L = thisComp.layer("Null 1");
L.toWorld(L.anchorPoint)

Kalleheikki Kannisto
Senior Graphic Designer


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]