Calculate the angle from velocity?

This topic is 4386 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Is it possible to calculate the angle from the velocity? I already know how to get the speed from the velocity by calculating the magnitude sqr(x * x + y * y), so all I need to know know is how to get the angle.

Share on other sites
And in actual code or in english?

Share on other sites
Angle between vectors formula:

u · v = |u||v| cos θ

where u and v are the vectors, and θ is the angle between them.

|u| means magnitude of vector u
and u · v is a dot product, not a multiplication

Share on other sites
What hmmz said. In code:
atan2( y, x );
Or if your language does not specify atan2:
if( x != 0 )   angle = atan( y / x );else   angle = ( y < 0 ? -M_PI : M_PI );
EDIT: Oops, too late to see hmmz second post! [smile]

Share on other sites
Thanks everyone,

actually my language doesn't specify atan2 (using VB6).

The whole 'angle = ( y < 0 ? -M_PI : M_PI );' doesn't work currectly when x is zero.

What actually works is this: angle = ( y < 0 ? PI * 1.5 : 0 );

1. 1
2. 2
frob
16
3. 3
4. 4
5. 5
Rutin
10

• 18
• 13
• 14
• 76
• 22
• Forum Statistics

• Total Topics
632149
• Total Posts
3004363

×