Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Fix line to the tangent of a circle

  • Fix line to the tangent of a circle

    Posted by Paul Roper on December 7, 2012 at 7:09 pm

    Hello,

    I’ve created an expression the links the radius of a circle to the angle of a line forming a tangent to it. I was originally looking for a way to make the angle of the line dependent upon the radius of the circle, but using my limited trigonometry it seemed easier to drive the radius of the circle by the angle of the line. I’m not bothered which is the driver and which is driven. Anyway, I came up with the following expression, which works with partial success (see end of this post for the expression text).

    It looks like it’s working:

    …but the radius is always dependent on ‘opposite’ side of the right-angled triangle formed by the line (hypoteneuse), and therefore intersects the edge of the circle at larger diameters:

    Any suggestions as to how I can tweak this to make the line always touch the edge of the circle, like a tangent should?

    Thanks,

    Paul

    angleOfLine=degrees_to_radians(thisComp.layer("NewLine").transform.rotation);
    lengthOfLine=1000;
    radius=Math.tan(angleOfLine)*lengthOfLine;
    [radius*2,radius*2]

    Paul Roper replied 13 years, 9 months ago 2 Members · 5 Replies
  • 5 Replies
  • Paul Roper

    December 7, 2012 at 7:45 pm

    To take it even further, what I’m trying to achieve is something like this:

    The green circles are 3D layers parented to the spotlight, so their movement follow the spotlight’s rotation (if I don’t use the ‘point of interest’ but the rotation instead). What I’d like is a pair of lines that also follow the movement (I just added those cyan lines in Photoshop to illustrate what I want) and could ideally move to track the edges of the ‘target’ circle as the spotlight’s cone angle is increased. It’s be great to be able to do this with the Beam effect, so keep the line a consistent width no matter what angle the spotlight is facing.

    Any thoughts, anyone? Or as I suspect, as this is for a fairly short animation, I should just keyframe the thing by eye?

    – Paul

  • Dan Ebberts

    December 7, 2012 at 7:49 pm

    So the line’s anchor point is at its right edge and the distance between the line and the circle is fixed, is that correct? Is the distance between the center of the circle and the rotation point of the line the same as the distance between their anchor points?

    Dan

  • Paul Roper

    December 7, 2012 at 7:56 pm

    So the line’s anchor point is at its right edge and the distance between the line and the circle is fixed, is that correct?

    Yes.

    Is the distance between the center of the circle and the rotation point of the line the same as the distance between their anchor points?

    Yes. The anchor point of the circle is at x=200. The anchor point of the line is at x=1200.

  • Dan Ebberts

    December 7, 2012 at 8:32 pm

    I think all you need to do is change Math.tan to Math.sin

    Dan

  • Paul Roper

    December 7, 2012 at 9:55 pm

    Worked perfectly! Thanks, Dan!

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