00001 #ifndef MSL_VECTOR_H 00002 #define MSL_VECTOR_H 00003 00004 #include <stream.h> 00005 #include <list.h> 00006 #include <vector.h> 00007 00008 void error_handler(int i, const char* s); 00009 00010 class MSLVector 00011 { 00012 friend class MSLMatrix; 00013 00014 double* v; 00015 int d; 00016 00017 void check_dimensions(const MSLVector&) const; 00018 00019 public: 00020 00021 MSLVector(); 00022 MSLVector(int d); 00023 MSLVector(double a, double b); 00024 MSLVector(double a, double b, double c); 00025 MSLVector(const MSLVector& w, int prec); 00026 MSLVector(const MSLVector&); 00027 ~MSLVector(); 00028 MSLVector& operator=(const MSLVector&); 00029 00030 int dim() const { return d; } 00031 double& operator[](int i); 00032 double operator[](int) const; 00033 double hcoord(int i) const { return (i<d) ? (*this)[i] : 1; } 00034 double coord(int i) const { return (*this)[i]; } 00035 double sqr_length() const; 00036 double length() const; 00037 MSLVector norm() const { return *this/length(); } 00038 double angle(const MSLVector& w) const; 00039 MSLVector rotate90() const; 00040 MSLVector rotate(double a) const; 00041 MSLVector& operator+=(const MSLVector&); 00042 MSLVector& operator-=(const MSLVector&); 00043 MSLVector operator+(const MSLVector& v1) const; 00044 MSLVector operator-(const MSLVector& v1) const; 00045 double operator*(const MSLVector& v1) const; 00046 MSLVector operator*(double r) const; 00047 MSLVector operator-() const; 00048 MSLVector operator/(double) const; 00049 bool operator==(const MSLVector& w) const; 00050 bool operator!=(const MSLVector& w) const { return !(*this == w); } 00051 friend MSLVector operator*(double f, const MSLVector& v) { return v *f; } 00052 void print(ostream& O); 00053 void print() { print(cout); } 00054 void read(istream& I); 00055 void read() { read(cin); } 00056 friend ostream& operator<<(ostream& O, const MSLVector& v); 00057 friend istream& operator>>(istream& I, MSLVector& v); 00058 friend istream& operator>>(istream& is, list<MSLVector> & vl); 00059 friend ostream& operator<<(ostream& os, const list<MSLVector> & vl); 00060 friend istream& operator>>(istream& is, vector<MSLVector> & vl); 00061 friend ostream& operator<<(ostream& os, const vector<MSLVector> & vl); 00062 }; 00063 00064 00065 #endif