Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Calculating angle from two points

  • Calculating angle from two points

    Posted by Navarro Parker on June 4, 2017 at 8:19 pm

    As everyone knows, using the ol’ Gradient Ramp effect gives you two point controls for the start and end of your ramp.

    I need to use a different gradient effect that only has one point control and an angle control.

    What would be an expression to derive an angle value based on the two point controls?

    Kevin Camp replied 7 years, 6 months ago 2 Members · 1 Reply
  • 1 Reply
  • Kevin Camp

    June 5, 2017 at 4:19 pm

    Math.atan2(y,x) is the function that you are looking for.

    to get an angle from the ramp effect’s start and end points, try this:
    L = thisComp.layer("Layer with Ramp Effect");
    p1 = L.effect("Gradient Ramp")("Start of Ramp");
    p2 = L.effect("Gradient Ramp")("End of Ramp");
    p = p2 - p1;
    radiansToDegrees( Math.atan2( p[1], p[0] ) );

    depending on where you want zero degrees to start, you may need to add or subtract 90 degrees (currently zero is pointing right)

    Kevin Camp
    Art Director
    KCPQ, KZJO & KRCW

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