Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

Vector.cpp

Go to the documentation of this file.
00001 
00037 #define WANT_STREAM                  // include.h will get stream fns
00038 #define WANT_MATH                    // include.h will get math fns
00039                                      // newmatap.h will get include.h
00040 #include <newmatap.h>                // need matrix applications
00041 #include <newmatio.h>                // need matrix output routines
00042 
00043 #ifdef use_namespace
00044 using namespace NEWMAT;              // access NEWMAT namespace
00045 #endif
00046 
00047 #include "Vector.h"
00048 #include "Debug.h"
00049 #include <math.h>
00050 
00051 
00052 double Vector::DotProduct(const BaseClass& a, const BaseClass& b)
00053 {
00054         ASSERT(a.Ncols() == b.Ncols());
00055 
00056         int nCols = a.Ncols();
00057         double r = 0;
00058         
00059         for (int i = 1; i <= nCols; i++)
00060                 r += a(i) * b(i);
00061 
00062         return r;
00063 }
00064 
00065 double Vector::CrossProductMag(const BaseClass& a, const BaseClass& b)
00066 {
00067         double dAngleAB = 0;
00068         return DotProduct(a, b) * sin(dAngleAB);
00069 }
00070 
00071 /* static */
00072 double Vector::DistFromPtToLine(const BaseClass& x, const BaseClass& a, const BaseClass& b)
00073 {
00074         double m, t, n = 0, d = 0;
00075         int i, k = x.Ncols();
00076 
00077         ASSERT(k == a.Ncols() && k == b.Ncols());
00078 
00079         for (i = 1; i <= k; i++)
00080         {
00081                 m = b(i) - a(i);
00082                 n += m * (x(i) - a(i));
00083                 d += m * m;
00084         }
00085 
00086         t = n / d;
00087 
00088         if (t >= 0 && t <= 1)
00089                 return Norm2((a - x) + (b - a) * t);
00090         else
00091                 return ((n = Norm2(a - x)) < (d = Norm2(b - x))) ? n:d;
00092 }

Generated on Sat Nov 13 11:21:26 2004 for Noisy DAG Matcher by doxygen1.2.18