00001 //---------------------------------------------------------------------- 00002 // The Motion Strategy Library (MSL) 00003 //---------------------------------------------------------------------- 00004 // 00005 // Copyright (c) University of Illinois and Steven M. LaValle. 00006 // All Rights Reserved. 00007 // 00008 // Permission to use, copy, and distribute this software and its 00009 // documentation is hereby granted free of charge, provided that 00010 // (1) it is not a component of a commercial product, and 00011 // (2) this notice appears in all copies of the software and 00012 // related documentation. 00013 // 00014 // The University of Illinois and the author make no representations 00015 // about the suitability or fitness of this software for any purpose. 00016 // It is provided "as is" without express or implied warranty. 00017 //---------------------------------------------------------------------- 00018 00019 #ifndef MSL_VECTOR_H 00020 #define MSL_VECTOR_H 00021 00022 00023 #include <fstream> 00024 #include <iostream> 00025 #include <list> 00026 #include <vector> 00027 using namespace std; 00028 00029 00030 #include "mslio.h" 00031 00032 void error_handler(int i, const char* s); 00033 00034 class MSLVector 00035 { 00036 friend class MSLMatrix; 00037 00038 double* v; 00039 int d; 00040 00041 void check_dimensions(const MSLVector&) const; 00042 00043 public: 00044 00045 MSLVector(); 00046 MSLVector(int d); 00047 MSLVector(double a, double b); 00048 MSLVector(double a, double b, double c); 00049 MSLVector(const MSLVector& w, int prec); 00050 MSLVector(const MSLVector&); 00051 ~MSLVector(); 00052 MSLVector& operator=(const MSLVector&); 00053 00054 int dim() const { return d; } 00055 double& operator[](int i); 00056 double operator[](int) const; 00057 double hcoord(int i) const { return (i<d) ? (*this)[i] : 1; } 00058 double coord(int i) const { return (*this)[i]; } 00059 double sqr_length() const; 00060 double length() const; 00061 MSLVector norm() const { return *this/length(); } 00062 double angle(const MSLVector& w) const; 00063 MSLVector rotate90() const; 00064 MSLVector rotate(double a) const; 00065 MSLVector& operator+=(const MSLVector&); 00066 MSLVector& operator-=(const MSLVector&); 00067 MSLVector operator+(const MSLVector& v1) const; 00068 MSLVector operator-(const MSLVector& v1) const; 00069 double operator*(const MSLVector& v1) const; 00070 MSLVector operator*(double r) const; 00071 MSLVector operator-() const; 00072 MSLVector operator/(double) const; 00073 bool operator==(const MSLVector& w) const; 00074 bool operator!=(const MSLVector& w) const { return !(*this == w); } 00075 friend MSLVector operator*(double f, const MSLVector& v) { return v *f; } 00076 void print(ostream& O); 00077 void print() { print(cout); } 00078 void read(istream& I); 00079 void read() { read(cin); } 00080 friend ostream& operator<<(ostream& O, const MSLVector& v); 00081 friend istream& operator>>(istream& I, MSLVector& v); 00082 }; 00083 00084 ostream& operator<<(ostream& O, const MSLVector& v); 00085 istream& operator>>(istream& I, MSLVector& v); 00086 00087 #endif