LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: jam007 on January 23, 2005, 21:33:19

Title: Vector2f angle, alternate method
Post by: jam007 on January 23, 2005, 21:33:19
I found that the angle method in Vector2f returns the unsigned angle between the vectors. For me that was a problem so I made a modified method:

   public static float angle2f(Vector2f a, Vector2f b) {
           float dls = Vector2f.dot(a, b) / (a.length() * b.length());
           if (dls < -1f) dls = -1f;
               else if (dls > 1.0f) dls = 1.0f;
           float ang=(float)Math.acos(dls);
           if (a.x*b.y-b.x*a.y<0) ang=-ang;
           return ang;
   }


Maybe useful for others also.