Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Clamping the result of a radiansToDegrees expression…

  • Clamping the result of a radiansToDegrees expression…

    Posted by Danny Parsons on February 20, 2009 at 10:11 pm

    Hi there,

    I have a null with a simple radiansToDegrees expression applied to its rotation property, calculating the angle based on the layer’s own position relative to a specified anchor point within the comp…

    delta = [250,700] – transform.position;
    -radiansToDegrees(Math.atan2(delta[0], delta[1]))

    I now want to link another layer’s rotation to that result, but clamp its range between, let’s say, 0 – 270 degrees. At the moment, the value is snapping back to zero when I reach beyond 180 degrees, since it’s being told that its value is -179, rather than +181 degrees.

    r2dResult = thisComp.layer(“Null 1”).transform.rotation;
    clamp(0,270, r2dResult)

    I’m sure there’s a simple way to correct this, but I haven’t yet been able to figure it out. Any ideas?

    Thanks in advance,

    DP

    Dan Ebberts replied 17 years, 2 months ago 2 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    February 20, 2009 at 11:12 pm

    Try adding 360 if the value is negative. Then clamp it.

    Dan

  • Danny Parsons

    February 21, 2009 at 12:25 am

    Thanks Dan,

    I had a feeling it was going to be something a lot simpler than some of the things I was trying!

    I do have a quick follow-up question, however…

    Now, when I drag the null any ‘earlier’ than ‘twelve o’clock’, the rotation value snaps straight to the upper clamp-limit. Is there any I could get it to stick at zero until I reach the 270 degrees mark again (going backwards), and only THEN have the layer resume its movement (in much the same way that it currently behaves when I’m moving in the opposite – clockwise – direction)?

    Thanks again,

    DP

  • Dan Ebberts

    February 21, 2009 at 1:02 am

    I can’t thing of a good way to do that, because there’s no way for the expression to know how the null got into the upper left quadrent. I’m talking about just being able to drag the null around and get the behavior you describe.

    However, if you’re talking about animating the value of the null, then you could do it by having the expression go backwards in time, frame-by-frame, to figure out where it was before it got into that quadrant and then clamp to 0 or 270 based on that.

    Dan

  • Danny Parsons

    February 21, 2009 at 2:35 am

    Oh, well – thanks for trying!

    It’s really just the dragging behaviour I was after – it doesn’t need to be animated, as it is part of a kind of comp-panel based UI to drive other stuff.

    Regarding which…

    Sorry to do this again, but I have yet another follow-up question! Admittedly, I haven’t spent much time trying to figure this one out for myself yet, but I figure that whilst I have you ‘on the line’, you can probably save me a few hours of head-bashing…

    The rotation property we were just discussing will be a “value +” kind of deal, since I would like the user to be able to tweak the value of a rotary control using the pad “+” and “-“ keys, as an alternative to dragging with his/her mouse.

    But for those who are neither exclusively ‘tappers’ or ‘draggers’, and would occasionally like to use both methods, it would be nice if the null’s position could also ‘catch up’ with its rotation, if the rotation is tweaked independently.

    I don’t think I have ever used radiansToDegrees before, and from looking at other threads, its potential applications seem pretty varied, so any suggestions as to how to go about this would be much appreciated.

    Thanks again,

    DP

  • Dan Ebberts

    February 21, 2009 at 4:54 pm

    I doubt that it will work, because you’ll end up with a position expression that depends on rotation tied to a rotation expression that depends on position.

    Dan

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