Calculating vector length and angle

What type of scripts do you need?

Moderator: byronnash

Post Reply
Posts: 7
Joined: March 17th, 2008, 3:25 pm

December 12th, 2009, 12:58 pm

Hi I need some help to finish my line measurement tool.

Edit: Sorry ! - this should have been posted under Expression Discussion - please move

Sometimes I need to calculate the distance and angle between two points on the screen, so I'm working on an animation preset.
I use the beam effect to select the two points and an expression to calculate the length and angle of the line.

Calculating the length work fine, but the angle are giving me problems.
I use the expression found here : ... tions.html

At the moment it returns values between -180 and 180 and have 0 at "9 o'clock"

I want it to return values between 0 and 360 and have 0 at "12 o'clock" 90.dg at "3 o'clock" 180dg. at "6 o'clock" and 270dg. at "9 o'clock"

Can anyone help me ?

AfterEffects CS4 project attached
red value = length
yellow value = angle

(6.41 KiB) Downloaded 517 times
Posts: 128
Joined: December 7th, 2007, 10:11 am

December 12th, 2009, 3:57 pm

Try this transformation at the end of your angle expression:

Code: Select all

where "ang" is your previous calculated value.

meaning your expression should be changed to this:

Code: Select all

this_point=effect("line")("Starting Point");
that_point=effect("line")("Ending Point");
delta=sub(this_point, that_point);
angle=Math.atan2(delta[1], delta[0]);
ang = radians_to_degrees(angle);
Posts: 7
Joined: March 17th, 2008, 3:25 pm

December 13th, 2009, 3:05 am

Thanks koby

Perfect !

Post Reply