angle between vectors in radians

Bj

Addon Developer
Addon Developer
Donator
Joined
Oct 16, 2007
Messages
1,886
Reaction score
11
Points
0
Location
USA-WA
Website
www.orbiter-forum.com
is this a correct statement?

Code:
float get_angle_between_in_radians(long double ax, long double ay, long double az, long double bx, long double by, long double bz)
{
    float pi = 3.14159265358979323846;
       float dotproduct, lengtha, lengthb, result;

   dotproduct = (ax * bx) + (ay * by) + (az * bz);
   lengtha = sqrt(ax * ax + ay * ay + az * az);
   lengthb = sqrt(bx * bx + by * by + bz * bz);

   result = acos( dotproduct / (lengtha * lengthb) );

   if(dotproduct < 0)
   {
      if(result > 0)
         result += pi;
      else
         result -= pi;
   }
   return result;
}


also does this actually turn rad to degrees

Code:
       y =  y * (57.29577951);
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,638
Reaction score
2,353
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
Looks correct, but when you use orbiters API, you can do that simpler by using VECTOR3...

I don't know why you have such a complex if statement for correcting the range of the angle...

Also the other statement is 180.0/PI. So it is correct.
 

simonpro

Beta Tester
Beta Tester
Joined
Feb 10, 2008
Messages
1,042
Reaction score
7
Points
0
Yes, dotproduct is = |a||b|Cos(theta)
 
Top