Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Math.sin going out of sync

  • Math.sin going out of sync

    Posted by John Winthrop on October 18, 2016 at 4:56 pm

    I am trying to synchronize a pendulum rotated with the tempo of a song.

    the tempo is 123 BPM which is 1.025 per second.

    I have a slider set to time*1.025 and when I link the rotation of the pendulum directly to the slider (*360) it makes one full revolution exactly on beat for the duration of the song, so I know that 1.025 is the right beats per second.

    However when I plug that same number into a typical swing equation:
    \\\\\\\\\\\
    tempo=(time*1.025)
    amp=40;
    freq=4;

    amp*Math.sin(tempo*freq);
    \\\\\\\\\\\\\\

    It becomes un-synchronized. Is there something I am missing about the math behind Math.sin? I feel like it should be making one or two swings per beat depending on the value of “freq”.

    John Winthrop replied 9 years, 7 months ago 2 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    October 18, 2016 at 5:12 pm

    Try it this way:

    freq = 1.025;
    swingsPerBeat = 2;
    amp=40;
    amp*Math.sin(time*freq*swingsPerBeat*Math.PI*2);

    Dan

  • John Winthrop

    October 18, 2016 at 6:59 pm

    Worked perfectly, thanks again Dan.

    Do you mind me asking what about adding “*Math.PI*2” made that difference? I know Math.PI as a javascript function simply represents the number PI (the general ratio of circumference to diameter) but how does that doubled affect this equation? I have seen you use “*Math.PI*2” in other expressions and never really understood what that was achieving.

    Thank you it has been quite some time since I took geometry.

  • Dan Ebberts

    October 18, 2016 at 7:11 pm

    The JavaScript Math functions expect angles expressed in radians, where one complete revolution is equal to 2 times pi.

    Dan

  • John Winthrop

    October 18, 2016 at 7:15 pm

    Ohhhh ok, thank you!

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