www.pudn.com > AdaBoost_weaklearner_1.rar > vector.cpp
#include "vector.h" #include#include #include // set x, y and z values of the current vector // void Vector::set(double _x, double _y, double _z) { x=_x; y=_y; z=_z; } // normalize the current vector to unit length // void Vector::normalize(void) { double d=sqrt(x*x+y*y+z*z); if(d == 0) { cout << "zero length vector\n"; exit(1); } x /= d; y /= d; z /= d; } // scale the current vector with a constant // Vector& Vector::scale(double coeff) { x *= coeff; y *= coeff; z *= coeff; return *this; } // calculate the dot product of the current vector with vector v // double Vector::dotProd(const Vector& v) { return x*v.x+y*v.y+z*v.z; } // calculate the cross product of the current vector with // vector v, the resulting vector is stored in "res" // void Vector :: crossProd(Vector& res, const Vector& v) { double i=y*v.z-z*v.y; double j=z*v.x-x*v.z; double k=x*v.y-y*v.x; res.set(i, j, k); } // add the current vetor to vector v // Vector Vector::operator+ (const Vector& v) { Vector vec; double i=x+v.x; double j=y+v.y; double k=z+v.z; vec.set(i, j, k); return vec; } // subtract vector v from the current vector // Vector Vector::operator- (const Vector& v) { Vector vec; double i=x-v.x; double j=y-v.y; double k=z-v.z; vec.set(i, j, k); return vec; } Vector& Vector::operator= (const Vector& v) { if(this==&v) return *this; x=v.x; y=v.y; z=v.z; return *this; }