VIDEO COPILOT FORUM
Free After Effects Tutorials & More Hosted By: Andrew Kramer

Calculating target angles

Scripting for After Effects

Calculating target angles

Postby Rob Neal on 11/6/2009, 3:32 pm

Hi,
I've got a bit of a maths problem here and I suspect it's pretty simple, but I can't quite get my head around it. (Probably mathematically dyslexic!)

This is an entirely 2D calculation. (No Z space required) - Working on the principle I have a 2D point in space, such as a null that I want as my "light", and a small solid as my "object", if I apply a drop shadow effect to the object, I need to calculate the angle of the shadow based on wherever the "light"'s position is, whether I move the "light" or the "object", it should be able to determine what angle they are relative to each other.

If you can add the cherry on the cake and work out the distance between the "light" and "object" to control the drop shadow opacity/blur, then that would be even cooler!

I'm sure I can't be the first to want an expression like this, someone MUST have done it before, but I can't seem to find a solution.
HAYYALLP!! :cry:

Many thanks,
Rob
Rob Neal
 
Posts: 347
Joined: 09/30/2008, 4:29 am
Location: London, England

Re: Calculating target angles

Postby ngambles on 11/6/2009, 5:12 pm

This is real similar.

Write back if you need more help than that.
ngambles
 
Posts: 556
Joined: 09/20/2008, 12:47 pm
Location: Denver, CO USA

Re: Calculating target angles

Postby Rob Neal on 11/6/2009, 6:57 pm

Thanks mate. I must have been off sick from school the day we did arctangents. ;)

Rob
Rob Neal
 
Posts: 347
Joined: 09/30/2008, 4:29 am
Location: London, England

Re: Calculating target angles

Postby ngambles on 11/7/2009, 1:48 pm

The way we did it in the other post was like this:
Our setup was that the blur center acted as a light source.
We then applied the layer style 'Bevel and Emboss' to the graphic layer.
Then we put the expression in the angle value for the Bevel and Emboss.

That's it. The expression calculates the angle for the layer style so the shadows and highlights of the Bevel and Emboss matched the angle of our radial blur shadows.

In your case instead of using the Bevel and Emboss layer style you'd want to use the drop shadow layer style, and after that it all works the same.

From what I gathered it sounded like you were using the null layer as your light source so you want to find the proper angle between your graphic layer and the null object. In that case you'd use the code below and put it in the angle for your dropshadow.
Code: Select all
pos = (pickwhip the position of your null object) ;
vec = thisLayer.position - pos;

ang = radiansToDegrees(Math.atan2( vec[0] , vec[1] )) + 90


That will get your angles working correctly.

And if you want it to get closer/farther as it gets closer/farther from the null object you could put this code in the distance of the dropshadow.
Code: Select all
posN = thisComp.layer("Null 1").position;
vec = thisLayer.position - posN;

length( vec ) / 5


After that you can probably put some expression into the spread of the dropshadow so it gets harder when the distance is closer and softer when they're farther away. That shouldn't be too hard so I'll let you figure that one out.

Hope it helps.

Cheers
ngambles
 
Posts: 556
Joined: 09/20/2008, 12:47 pm
Location: Denver, CO USA

Re: Calculating target angles

Postby Rob Neal on 11/8/2009, 5:06 am

Yay!
Many thanks for that Nathan. Got it working.
I used the example of drop shadow as an example, but I am actually using a pseudo-embossing effect called Shade/Shape, which needs a lighting angle. All worked out anyway.

Incidentally, I discovered there is a standard Ae effect called "Radial Shadow" which does all this for you.
Never noticed it before. :idea:

regards,
Rob
Rob Neal
 
Posts: 347
Joined: 09/30/2008, 4:29 am
Location: London, England


Return to After Effects Expressions