AE ENHANCERS

Expressions/Scripts/Presets
It is currently Wed May 22, 2013 4:32 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Calculating vector length and angle
PostPosted: Sat Dec 12, 2009 12:58 pm 
Offline

Joined: Mon Mar 17, 2008 3:25 pm
Posts: 8
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


Attachments:
line_measurement.aep.zip [6.41 KiB]
Downloaded 107 times
Top
 Profile  
 
 Post subject: Re: Calculating vector length and angle
PostPosted: Sat Dec 12, 2009 3:57 pm 
Offline

Joined: Fri Dec 07, 2007 10:11 am
Posts: 128
Try this transformation at the end of your angle expression:

Code:
(ang+270)%360

where "ang" is your previous calculated value.

meaning your expression should be changed to this:
Code:
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.


Top
 Profile  
 
 Post subject: Re: Calculating vector length and angle
PostPosted: Sun Dec 13, 2009 3:05 am 
Offline

Joined: Mon Mar 17, 2008 3:25 pm
Posts: 8
Thanks koby

Perfect !

>kenneth


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group