Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Calculating angle from camera to object – expression

  • Calculating angle from camera to object – expression

    Posted by Joemason on November 8, 2006 at 8:16 pm

    I’ve been trying to figure out a way to calculate the angle between an 3D layer and a camera… specifically, a perpendicular line from the center of any given 3D object and a camera.

    The first idea I had was parenting a Null to the “object”, having it auto-orient to the camera, then calculating the absolute rotation of the Null. But in 3D space, this seems to be a tall order.

    Mainly this is to adapt Angle property controls based on camera/object angle.

    Anyone have any great ideas?

    Colin Braley replied 19 years, 6 months ago 3 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    November 8, 2006 at 9:47 pm

    It’ll probably be some variation of something like this:

    C = thisComp.layer(“Camera 1”);
    v1 = normalize(position – C.position)
    v2 = C.toWorldVec([0,0,1]);
    radiansToDegrees(Math.acos(dot(v1,v2)))

    Dan

  • Colin Braley

    November 8, 2006 at 11:32 pm

    Dan,
    I was reading through this expression trying to figure out how it works and ive got a few questions. I typed out what I think each line does but im not sure about line 3…

    C = thisComp.layer(“Camera 1”);
    //var C = the camera

    v1 = normalize(position – C.position)
    //v1 is the direction vector from the camera to the layer (it has length 1)

    v2 = C.toWorldVec([0,0,1]);
    //what is this line doing?

    radiansToDegrees(Math.acos(dot(v1,v2)))

    //so here you are finding the angle between v1 and v2 and outputting it in
    //degrees because v1 dot( v1 , v2 ) = length(v1) * length(v2) * cos( theta )
    //where theta is the angle between the two vectors…but since v1 and v2 are //normalized you are just using the arccos to get the angle between the two //vectors

    Thanks in advance Dan.

    ~Colin

  • Dan Ebberts

    November 9, 2006 at 2:00 am

    Colin,

    Your analysis is dead on.

    v2 = C.toWorldVec([0,0,1]);

    This just creates a unit vector in the direction of the camera’s z axis and translates it to world coordintes. Then you have the two unit vectors you need to find the angle.

    Dan

  • Colin Braley

    November 9, 2006 at 2:17 am

    That makes sense now…thanks a lot Dan. I’m taking a class in vector geometry and 3d calc so a lot of the expressions you have up here finally make sense to me… 🙂
    ~Colin

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