Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions having a hard time understanding this expression.

  • having a hard time understanding this expression.

    Posted by Assaf Goldlust on July 9, 2018 at 6:19 pm

    the idear of this expressions
    is to make a layer Y position bounce from 100 to 0 to -100
    and make that bounce in a frequency of 5 times per second

    but im having a hard time understanding the math behind that? is any around here can help me out?

    var frequency=5;
    var amplitude=100;
    var x=transform.position[0];
    var y=transform.position[1]+(amplitude*Math.sin(frequency*time*2*Math.PI));
    [x,y]

    Assaf Goldlust replied 7 years, 10 months ago 3 Members · 15 Replies
  • 15 Replies
  • Kalleheikki Kannisto

    July 10, 2018 at 7:05 am

    The main part is obviously this:

    (amplitude*Math.sin(frequency*time*2*Math.PI))

    The main thing to understand is the sine function (Math.sin), which gives you the y value from a point rotating on a unit circle (circle with the radius of one) at a given angle in relation to the positive x axis drawn from the center of the circle. Time is used to change the angle. Math.PI is pi, i.e. the relationship of the circumference of a circle to its diameter. Since pi means one full rotation, you are getting the y value of the rotating point based on time. When frequency is one, that’s one rotation per second. Multiplied by frequency you get that many rotations. The multiplication by 2 in that formula is an unnecessary addition, it just doubles the frequency.

    transform.position[0] retrieves the x position of the layer, [1] the y position. The [0] and [1] are array indices.

    For a visual of the unit circle, see https://en.wikipedia.org/wiki/Sine

    Kalleheikki Kannisto
    Senior Graphic Designer

  • Assaf Goldlust

    July 11, 2018 at 8:16 am

    im a little confused? according to the book im working and also inside after it tell me that PI is half a circle…

  • Kalleheikki Kannisto

    July 11, 2018 at 9:31 am

    Pi is half a circle if you multiply the radius with it, full circle if you multiply the diameter. Diameter = 2 * radius.

    Kalleheikki Kannisto
    Senior Graphic Designer

  • Assaf Goldlust

    July 11, 2018 at 9:46 am

    now its make sense. the Math.PI in this case is radius and not the diameter.

    this the “*2” opertation is included

  • Kalleheikki Kannisto

    July 11, 2018 at 9:50 am

    Yes, sorry, I forgot that Javascript, which Expressions are based on, uses radians as units for this calculation, so you’re right in that a full circle is indeed 2*PI when measured in radians.

    Kalleheikki Kannisto
    Senior Graphic Designer

  • Assaf Goldlust

    July 11, 2018 at 10:30 am

    dont worry about it, you were still a great help. thank you!

  • Assaf Goldlust

    July 11, 2018 at 9:32 pm

    here is something that gave me a bit of a head screather. im assiming time is changing the angle of the expression by rotating the point in at the center of the unit circle, but then im ising 2*Math.PI to tell him how many rotation to do per 1 second.
    but if time is changing the angle by making the point rotate and the frequency make it go faster, dosn’t have any kind of effect of how many complete rotation he does in a second?

  • Dan Ebberts

    July 11, 2018 at 10:13 pm

    The 2*Math.PI just converts the number of rotations to radians. The current number of rotations is determined by frequency*time. So for example, when frequency is 5, and time is 2, that’s 10 complete rotations, so the total angle is 20*Math.PI radians.

    Dan

  • Assaf Goldlust

    July 11, 2018 at 10:26 pm

    i tought that Math.SIn treat already treat any number you feed him as a radian.

  • Dan Ebberts

    July 12, 2018 at 12:03 am

    That’s correct.

Page 1 of 2

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