atan2 - calculating angles

Hi

I have been searching on the net and within the forum and i just cant work out how to calculate the angle between two points.

In flash i would do this:
var angle : Number = Math.atan2(a.y - b.y, a.x - b.x) * 180 / Math.PI;

In openframeworks im doing this:
float angle = atan2(_particles[i]._y - _y, _particles[i]._x-_x) * 180 / PI;

But it just not working. How can i get the angle between two points?

Thanks for any help.

1 Like

Hello,

Usually do something like:

  
Vec2f lineBetween  = positionA - positionB;  
float theta = atan2(lineBetween.x,lineBetween.y)-(PI/2);   

For the “Vec2f” and the “PI” i´m using Memo Akten addon: MSACore

Remember that atan2 gives the information on radiants and not in degrees.

I hope this could help

1 Like