Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Studying angles of a traingle

  • Studying angles of a traingle

    Posted by Tyler Paul on February 28, 2009 at 5:34 pm

    I’ve built a triangle in AE. Each leg’s height scale is equal to it’s length. By adjusting the height scale of either leg (a and b) the hypotenuse line (c)is then calculated and adjusted.

    --------------
    B
    |\
    | \c
    |a \
    |___\A
    C b
    --------------

    The code works but the formula didn’t work as I expected.

    I’m solving for A (the anchor point of the hypotenuse)

    a=thisComp.layer("leg2").transform.scale[1]; 'a is opposite
    b=thisComp.layer("leg1").transform.scale[1]; 'b is adjacent
    c=transform.scale[1]; 'c is the hypotenuse
    ang=Math.asin(b/c);
    angfin=radiansToDegrees(ang);
    [-angfin]

    I used ‘asin’ but the formula was ‘b/c’ = adjacent/hypotenuse = cos.

    Am I correct in that it should be Math.acos? Why does acos fail?

    Tyler Paul replied 17 years, 2 months ago 2 Members · 4 Replies
  • 4 Replies
  • Filip Vandueren

    March 1, 2009 at 4:59 pm

    This worked for me:

    a, b, and c are solids of 2px * 100 px;

    They should all be created and place at the same position.

    a and b can be freely scaled (in Y).

    c has these expressions:

    position:

    a=thisComp.layer(“a”);
    b=thisComp.layer(“b”);

    a.position+[b.scale[1],0]

    Scale:

    a=thisComp.layer(“a”).scale[1];
    b=thisComp.layer(“b”).scale[1];

    c=Math.sqrt(a*a + b*b);

    [100,c];

    Rotation:

    a=thisComp.layer(“a”).scale[1];
    b=thisComp.layer(“b”).scale[1];
    c=scale[1];

    if (c) {
    angle=Math.asin(b/c);

    if (a>0) {
    -radiansToDegrees(angle);
    } else {
    radiansToDegrees(angle)-180;
    }
    } else {
    0
    }

    The main things to keep in mind are that the angle needs to be reversed, because the After Effects pixel coördinate system for Y is opposite of what you would expect in Math.
    Also, No parenting should be applied.

    If added some if/thens to corrct for negative lengths of a & b (would also not happen in pure Math) when the scale is negative, and a check to see if c is not 0 (when a and b are 0) to prevent a division by zero error.

  • Tyler Paul

    March 2, 2009 at 1:03 am

    That’s more or less what I had (less being all those fancy if statements) but I see the same problem in your code.

    ---------------------
    X
    |\
    |
    |
    |
    |
    |
    b
    |
    |
    |____a_____\
    ------------------------

    Since you pushed ‘c’ in the direction of ‘b’ then we’re solving for angle X.

    sin = opposite/hypotenuse = a/c

    cos = adjacent/hypotenuse = b/c

    I don’t understand why the code shouldn’t read acos(b/c)

    * * *
    “Life Should Come With Backround Music”

    -Brown Sugar Studios-

  • Filip Vandueren

    March 2, 2009 at 1:10 am

    I think it has to do with two things:

    As stated the Y-coördinates of pixels are reverse of what they are in Math.
    In effect, the coördinates make more sense if you look at the after effects screen turned 90° to the left: coördinates rise from left to right, and from down to up, just as they do on a trig circle.

    Also in a trig Math situation, 0° is East, while in our case 0° is North. So that’s a difference of 90°

    Combine these two with the fact that sin(90-a)=cos(a) and you see how the two get interchanged.

  • Tyler Paul

    March 2, 2009 at 1:27 am

    Heh. I get that. Good to know.

    It reminds me of when I first used blender and the Z and Y axis seemed to switch place.

    STANDARDIZE PEOPLE!!! C’mon!

    * * *
    “Life Should Come With Backround Music”

    -Brown Sugar Studios-

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