Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Controlling an offset position with an angle slider.

  • Controlling an offset position with an angle slider.

    Posted by Christopher Rutherford on May 24, 2016 at 8:45 pm

    Hey smart people,

    I’m wondering if there’s an elegant way to controlling a layers position using angles & magnitudes as opposed to cartesian coordinates.

    And if not, is there a breakdown somewhere of how turn angle inputs into x/y outputs. From my floundering research thus far noticed there’s a lot of radian conversions & if/then statements for the 4 quadrants but I haven’t been able to parse it beyond that.

    For reference, Dan Ebberts code here almost does what I’m trying to figure out, but I can’t quite deconstruct it in order to control the distance of the offset.

    Thanks,

    EDIT: After a bit more searching I came across GrayMachine’s polar coordinate code. It took a bit of tinkering but I got it to work for myself. However, set the resting position of the layer (that is, the position when the Distance1 slider was 0) at 971,971. Subtracted 11 from 2 lines of code & that managed to work, but I don’t really know /why/.

    d = thisComp.layer(“Master”).effect(“Distance1”)(“Slider”)
    a = thisComp.layer(“Master”).effect(“Angle Control”)(“Angle”)

    angle = a;
    length = d;
    aRad =degreesToRadians( angle – 90);
    x=d*Math.cos(aRad)-11;
    y=d*Math.sin(aRad)-11;
    add(position, [x, y]);

    Christopher Rutherford replied 10 years, 3 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    May 24, 2016 at 9:19 pm

    It should be as straightforward as this:

    a = effect(“Angle Control”)(“Angle”);
    d = effect(“Slider Control”)(“Slider”);
    r = degreesToRadians(a-90);
    x = d*Math.cos(r);
    y = d*Math.sin(r);
    value + [x,y]

    which I think is the same as Harry’s solution. I’m not sure why you’d need any adjustments unless you’ve got parenting w/ rotation or non-uniform scaling involved.

    Dan

  • Christopher Rutherford

    May 24, 2016 at 9:31 pm

    Yeah I’d only found it it after posting my question. I still don’t quite understand why an input of 0 gives me an offset position of +11, but I haven’t yet worked out that math.

    But thanks for your time.

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