MeshKit  1.0
VecUtil.hpp
Go to the documentation of this file.
00001 #ifndef MESHKIT_VECUTIL_HPP
00002 #define MESHKIT_VECUTIL_HPP
00003 
00004 #include <math.h>
00005 
00006 namespace MeshKit {
00007 
00008 class ModelEnt;
00009 class MKCore;
00010 
00015 class VecUtil 
00016 {
00017 public:
00024   static double dot(double *a, double *b);
00025 
00030   static double length_sq(double *a);
00031 
00037   static double dist2(double *a, double *b);
00038 
00042   static void normalize(double *a);
00043 
00049   static void cross(double *a, double *b, double *c);
00050 
00052   static double PI;
00053 
00055   static double TWO_PI;
00056 };
00057     
00058 inline double VecUtil::dot(double *a, double *b) {return a[0]*b[0] + a[1]*b[1] + a[2]*b[2];}
00059 
00060 inline double VecUtil::length_sq(double *a) {return a[0]*a[0] + a[1]*a[1] + a[2]*a[2];}
00061     
00062 inline double VecUtil::dist2(double *a, double *b) 
00063 {
00064   return sqrt((b[0]-a[0])*(b[0]-a[0]) + (b[1]-a[1])*(b[1]-a[1])
00065               + (b[2]-a[2])*(b[2]-a[2]));
00066 }
00067 
00068 inline void VecUtil::normalize(double *a) 
00069 {
00070   double lsq = length_sq(a);
00071   if (lsq == 0.0) return;
00072   lsq = 1.0 / sqrt(lsq);
00073   for (int i = 0; i < 3; i++) a[i] *= lsq;
00074 }
00075 
00076 inline void VecUtil::cross(double *a, double *b, double *c) 
00077 {
00078   c[0] = a[1]*b[2] - a[2]*b[1];
00079   c[1] = a[2]*b[0] - a[0]*b[2];
00080   c[2] = a[0]*b[1] - a[1]*b[0];
00081 }
00082 
00083 } // namespace MeshKit
00084 
00085 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines