// myvec.cxx // // methods for class myvec // #include "myvec.h" #include using namespace std; // constructor My3Vector::My3Vector( double xv, double yv, double zv ) { x = xv; y = yv; z = zv; } // get length of 3-vector double My3Vector::Length() const { return( sqrt( x*x + y*y +z*z ) ); } double My3Vector::Dot(const My3Vector & v) const { return( x*v.x + y*v.y + z*v.z ); } double My3Vector::Angle(const My3Vector & v) const { double ltot = Length()*v.Length(); if( ltot <= 0) { return 0.0; } else{ double arg = Dot(v)/ltot; if(arg > 1.0) arg = 1.0; if(arg < -1.0) arg = -1.0; return acos(arg)*180./M_PI; } } My3Vector My3Vector::operator + (const My3Vector & xv ) const { My3Vector tv; tv.x = x + xv.x; tv.y = y + xv.y; tv.z = z + xv.z; return tv; } // multplikation von rechts My3Vector My3Vector::operator * (const double & c ) const { My3Vector tv; tv.x = x * c; tv.y = y * c; tv.z = z * c; return tv; } // multplikation von links My3Vector operator * (const double & c, const My3Vector & v ) { return( v * c ); } ostream & operator << ( ostream &s, const My3Vector &v) { s << "(" << v.x <<","<< v.y <<","<< v.z <<")"; return s; }