Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Need some expressions help

  • Need some expressions help

    Posted by Barend Onneweer on August 31, 2007 at 1:36 pm

    Hi all,

    I need a bit of rather basic math in an expression, but much to my embarassment my math skills are rusty, and my scripting skills are mediocre.

    Basically I’ve got two points in 2D space – and I need the angle between those.

    I’ve got the positions of Point 1 and 2 – and I can calculate the lengths of the sides of the triangle.

    I know that tanB=y/x

    But how do I get the actual angle of B?

    Thanks in advance for any wisdom 🙂

    Bar3nd

    Raamw3rk – digital storytelling and visual effects

    Barend Onneweer replied 18 years, 12 months ago 4 Members · 6 Replies
  • 6 Replies
  • Steve Roberts

    August 31, 2007 at 2:14 pm
  • Kevin Camp

    August 31, 2007 at 2:45 pm

    i think it is this:

    radiansToDegrees(Math.atan(y/x))

    but there may be issues with which quadrant it is in… i seem to remember something about since tangent (or arctangent) can’t be calculated for an angle 90 degrees or greater then that created some issues getting angles that might be in any quadrant other than 1… steve’s link talked a bit about it too.

    Kevin Camp
    Designer – KCPQ, KMYQ & KRCW

  • Jerzy Drozda jr

    August 31, 2007 at 3:29 pm

    Take a look at this tutorial.
    https://library.creativecow.net/articles/drozda_jerzy/Radar.php

    I’m not 100% sure, but I think I had the same situation when calculating collision detection. Download the project files and take a close look at the expressions used.

    I’m sorry I can’t give you the straight answer, but I’ll be traveling all weekend and I’m getting ready for that. I won’t be able to respond for next two days.

    I hope you’ll get the problem solved.
    Good luck!

    Maltaannon


    maltaannon.com – Free After Effects Video Tutorials and more

  • Kevin Camp

    August 31, 2007 at 4:57 pm

    ok, atan2 fixes the quadrant issue… so this should work nicely.

    radiansToDegrees(Math.atan2(y,x))

    where x and y are your calculated values between the 2 points.

    Kevin Camp
    Designer – KCPQ, KMYQ & KRCW

  • Kevin Camp

    August 31, 2007 at 5:45 pm

    playing around with this a little more… if you want it to return a value based 0-360 degrees, this seems to work…

    180 – radiansToDegrees(Math.atan2(y,x))

    Kevin Camp
    Designer – KCPQ, KMYQ & KRCW

  • Barend Onneweer

    August 31, 2007 at 5:58 pm

    Hi Moldyboot,

    Interestingly, I got as far as “Math.atan2(y,x” before I started the thread, but adding “radiansToDegrees” got me where I need to be.

    Basically what I’m trying to do is combine two trackers to track rotation without having to bake the result into keyframes as I would when using AE’s rotation tracker and applying the result to a layer…

    Thanks,

    Barend

    Raamw3rk – digital storytelling and visual effects

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