Page 1 of 1

Calculating vector length and angle

Posted: December 12th, 2009, 12:58 pm
by kennethbonde
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 : http://www.jjgifford.com/expressions/ge ... 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


>kenneth

Re: Calculating vector length and angle

Posted: December 12th, 2009, 3:57 pm
by kobyg
Try this transformation at the end of your angle expression:

Code: Select all

(ang+270)%360
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);
(ang+270)%360
Koby.

Re: Calculating vector length and angle

Posted: December 13th, 2009, 3:05 am
by kennethbonde
Thanks koby

Perfect !

>kenneth