CCL Home Page
Up Directory CCL vec_angle
#include "utility.h"

double vec_angle(vector1,vector2)
/*============================================================================*/
/* PURPOSE: CALCULATE THE ANGLE BEWTEEN TWO VECTORS.  IF EITHER VECTOR HAS
/*	ZERO LENGTH, THE RETURNED ANGLE IS -1.
/* INPUTS:
/*	VECTOR1		(X,Y,Z) TRIPLET.
/*	VECTOR2		(X,Y,Z) TRIPLET.
/* OUTPUTS:
/*	FUNCTION VALUE	ANGLE IN DEGREES (0-180) BETWEEN VECTOR1 AND VECTOR2.
/* WRITTEN: M.V.GRIESHABER
/* LAST MODIFICATION: 11 JUNE 1991 MVG
*/
   double vector1[3];
   double vector2[3];
   {
   double length1;
   double length2;
   double cos_theta;

   /* COMPUTE THE LENGTH OF EACH VECTOR. */
   length1=vec_length(vector1);
   length2=vec_length(vector2);
   if (length1==0.0 || length2==0.0) return(-1.0);

   /* COMPUTE THE COSINE OF THE INCLUDED ANGLE. */
   cos_theta=vec_dotprod(vector1,vector2) / (length1*length2);

   /* GUARD AGAINST THRESHHOLD INACCURACY. */
   if (cos_theta > 1.0) cos_theta=1.0;
   else if (cos_theta < -1.0) cos_theta= -1.0;

   return(acos(cos_theta)*DEGREES_PER_RADIAN);
   }
Modified: Fri Feb 11 17:00:00 1994 GMT
Page accessed 5019 times since Sat Apr 17 21:59:03 1999 GMT