Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions scaling linked to rotation isn’t working.

  • scaling linked to rotation isn’t working.

    Posted by Richie Tovell on December 3, 2009 at 3:02 am

    I’ve asked for help on this little project quite a few times now and not really managed to figure out the correct way to achieve the right result’s, sorry about that, especially to you Dan, though I’ve learned a lot.

    So I figured I’d upload a test project to help you to see where I’m going wrong, I’ll outline it again here now though. In the project there are three layers (these layers will be replaced by footage eventually) The layers are arranged side by side and their anchor points adjoined using parenting, here the two outside layers are parented to the centre layer.

    The centre layer rotates by 90 + degrees and the outer layers swing around to follow.

    Here is my problem, I want the outer layers to sale so that this shape occupies the same width in the composition at all times, I have the “scale transform values” of these outer layers linked to the yrotation of the centre layer to achieve this but what ever amount of scale I use, ie 2x yrotation or 1.5 times yrotation etc the scale is always wrong, this is because they are “attached to a layer that is rotating and pulling the layers away from the edge of the comp along an exponential path, it’s this exponential amount the I can’t figure out an expression for.

    Can you guys help me figure this out?

    I’ve laid out the test project (pictured above) as clearly as I can, the actual comp is very different there are many more layers of varying size but I’m sure, if you can help me figure out the scale and correct expressions I can transfer them in to my main comp easily enough.

    409_yrotationscaleproject.aep.zip

    Dan will you attempt this for me? or can any of you chaps who hang out on this forum help?

    Coda – musical selections; in film, the ending or last section of a film (often wordless).

    Richie Tovell replied 16 years, 5 months ago 2 Members · 10 Replies
  • 10 Replies
  • Dan Ebberts

    December 3, 2009 at 6:50 am

    It’s a moderately complicated trig problem and there are some critical pieces of information missing. First, you need to know the exact width of the center piece. You have a mask on it and the mask isn’t centered around the anchor point, which makes the calculation more difficult. You also don’t have a camera in the comp, but you need to know the distance from the camera to the center layer’s anchor point. You can figure out the distance to the “implied” camera that AE uses in a 3D scene if you don’t provide one, but it might be easier to just add a camera.

    Once your middle layer is centered in the comp, and you know the width of each of the layers and the distance from the camera you can set up the calculations. It’s hard to explain, but if you draw a top view that includes the camera, the angled center piece and the counter-rotated edge pieces you can see what needs to be done. You’re really dealing with 3 overlaping triangles that all have the camera at their apex. One triange is the width of the comp and passes through the center layer’s anchor point. The second, larger triangle intersects the edge of the center layer that’s farthest away from the camera and extends to the edge of the camera view at that distance (which makes it wider than the comp). The third triangle is smaller than the other two, with its rear edge lining up with the point on the center layer that’s closest to the camera and is just wide enough to fill the camera view at that point, which makes it not as wide as the comp.

    The widths of these triangles are all related by the ratio of the distance of side farthest from the camera to the distance of the center layer’s anchor point from the camera. Half the width of the center piece times the cosine of the y rotation detrmines how much of the horizontal distance is occupied by center piece at any given rotation. Half the width of the center piece times the sine of the y rotation determines how far away each edge piece is from the camera. Then you need to scale each edge layer to fill up the rest of the comp view.

    It’s just math, but it’s not trivial.

    Dan

  • Richie Tovell

    December 3, 2009 at 8:24 am

    Sounds very complicated, thanks for taking the time to explain but that’s way beyond me, I could probably get some help with the maths possibly, but can AF handle these kinds of equations as expressions?

    In all honesty, I’d be happy if the shape even stayed roughly the same width as the comp window, at the moment my comp doesn’t, it expands way out of bounds and then shrinks to a great deal smaller then comp width, what I’m wondering is if you had an ideal project to work on and you knew the missing values that you needed to know to work out this expression could you put together something that roughly worked?

    I feel I’m asking to much of you here actually, though it perhaps doesn’t need to be as precise as your thinking, if you can find the time to put something rough my way at some stage I’d be very grateful and happy to experiment with it till it worked well enough.

    There is a camera in the comp, it’s a shy layer, the width of the layers I think I can re adjust and provide you with in an updated project this evening (including) an exact pixel count of the width of each layer if that would help?

    Let me know what you think, I realise it’s maybe going to be too time consuming for you which is perfectly understandable.

    Richie.

    Coda – musical selections; in film, the ending or last section of a film (often wordless).

  • Dan Ebberts

    December 3, 2009 at 2:54 pm

    The scale expression for the piece on the left is going to look roughly like this:

    mw = 470; // width of middle layer
    w = 430; // width of this layer
    p1 = thisComp.layer(“Medium Gray-Royal Blue Solid 2”).transform.position;
    p2 = thisComp.layer(“Camera 1”).transform.position;
    d = p1[2] – p2[2];

    angle = degreesToRadians(thisComp.layer(“Medium Gray-Royal Blue Solid 2”).transform.yRotation);
    dy = (mw/2)*Math.sin(angle);
    dx = (mw/2)*Math.cos(angle);
    oldW = mw/2 + w;
    newW = oldW*(d + dy)/d;
    myNewW = newW – dx;
    s = (myNewW/w)*100;
    [s,value[1],value[2]]

    The one on the right will be the same, except for this line:

    angle = -degreesToRadians(thisComp.layer(“Medium Gray-Royal Blue Solid 2”).transform.yRotation);

    This all assumes the center layer never rotates past 90 degrees.

    Dan

  • Richie Tovell

    December 3, 2009 at 4:27 pm

    Dan, that works beautifully!! absolutely amazing!! I’m so grateful, every time I’ve come up against a problem you’ve absolutely demolished it!! lol, I’m completely in awe of you 🙂

    I tested it in the example project and it’s easly precise enough for what I need to do, I’ll perhaps have to ask you a few questions after I’ve dropped it in to the main comp, which I’m doing now.

    I did also wan’t to know what are the variables in this expression that I will need to tweak, obviously there are the layer names, that’s no problem, but the layer widths also?

    mw = 470; // width of middle layer
    w = 430; // width of this layer

    Anything other than these?

    By the way, in the test comp the expression works fine when yrotations pass 90 and even – 90, marvellous work!!

    Thanks again.

    Coda – musical selections; in film, the ending or last section of a film (often wordless).

  • Dan Ebberts

    December 3, 2009 at 4:31 pm

    Those should be it, and you wouldn’t need to define them that way if your layers didn’t have masks on them (you could use the actual width of the layers).

    Dan

  • Richie Tovell

    December 4, 2009 at 8:11 pm

    Thanks Dan.

    Your expression is in the main comp, placed on the central layer and has completely stabilised the adjoining two layers, it’s worked really well, better for some reason than it has in the test project, I’m now tackling the outer layers.

    What I’d planned on doing was disabling the scale of the next adjoining layer using your previous “Disable scale from parent” expression.

    L = thisLayer;
    s = transform.scale.value;
    while (L.hasParent){
    L = L.parent;
    for (i = 0; i < s.length; i++) s[i] *= 100/L.transform.scale.value[i] } s This has worked fine, this layer now acts the same as the original centre layer in the first test project, so I was hoping to be able to repeat your "yrotation scaling" expression again on the next layer (left most layer, layer 1) but it's not working the same as it it did for the centre layers, I can't figure out why this is, I know the camera position has effected the perspective a little, the outer layer may also still be scaling through it's parenting possibly but only very slightly if at all, for some reason it's rotation is very slightly out and the expression isn't stabilizing the shape width as before. I've updated the project and entered the expressions (to layer 1 and 2) as I think they should be, would you have a look over them for me perhaps? 412_yrotationscaleproject2.aep.zip

    The only thing I’ve changed in the expression is that now the centre layer is twice it’s width this is so as to plaice the anchor point back to centre from the point of view of the expression.

    Could you have a look?

    Regards

    Richie.

    Coda – musical selections; in film, the ending or last section of a film (often wordless).

  • Dan Ebberts

    December 4, 2009 at 11:39 pm

    Sorry – I’m lost. All the math is going to be different for the way you have things set up now. You’ve changed the configuration of the triangles that the expression was based on.

    Dan

  • Richie Tovell

    December 5, 2009 at 1:55 am

    It’s ok I understand, there’s to many variations now in these outer layers to work out.

    I wonder if one expression could cover all of the layers and somehow take in to account all the rotations and all the widths at once. . . .

    Sorry I realise that’s a ridiculous amount of calculations. . I’ll try and hack something out of what I have already.

    Thanks

    Richie.

    Coda – musical selections; in film, the ending or last section of a film (often wordless).

  • Dan Ebberts

    December 5, 2009 at 2:57 am

    >I wonder if one expression could cover all of the layers and somehow take in to account all the rotations and all the widths at once. . . .

    I’d say that’s very likely.

    Dan

  • Richie Tovell

    December 5, 2009 at 4:41 am

    I think I should let you have a look at the whole comp, I probably should have done that in the first place and asked you the best way to tackle it, sorry.

    I’ll strip out all the unnecessary stuff, the plugins and footage etc just leaving all the layers in their place, perhaps it wont need as complex an expression as I thought, but I’d appreciate your thoughts. It will take me a day or so.

    I’ve been working towards building a comp based around this shape for months and I have to admit it’s been a real struggle, so your help is much appreciated.

    Thanks Dan.

    Richie.

    Coda – musical selections; in film, the ending or last section of a film (often wordless).

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