00001 00007 #ifndef P_VECTOR2_HH 00008 #define P_VECTOR2_HH 00009 00010 #include <iostream> 00011 #include <string> 00012 #include <blort/Recognizer3D/PNamespace.hh> 00013 #include <blort/Recognizer3D/Except.hh> 00014 00015 namespace P 00016 { 00017 00021 class Vector2 00022 { 00023 public: 00024 double x; 00025 double y; 00026 00027 Vector2(); 00028 Vector2(double xx, double yy); 00029 void Set(double xi, double yi) {x = xi; y = yi;} 00030 Vector2& operator+=(const Vector2 &v); 00031 Vector2& operator-=(const Vector2 &v); 00032 Vector2& operator*=(double s); 00033 Vector2& operator/=(double s) throw(Except); 00034 double NormSquare() const; 00035 double LengthSquare() const; 00036 double Norm() const; 00037 double Length() const; 00038 void Normalise(); 00039 Vector2 Normal(); 00040 Vector2 NormalClockwise(); 00041 Vector2 NormalAntiClockwise(); 00042 }; 00043 00044 Vector2 operator-(const Vector2 &v); 00045 bool operator==(const Vector2 &a, const Vector2 &b); 00046 bool operator!=(const Vector2 &a, const Vector2 &b); 00047 Vector2 operator+(const Vector2 &a, const Vector2 &b); 00048 Vector2 operator-(const Vector2 &a, const Vector2 &b); 00049 Vector2 operator*(const double s, const Vector2 &v); 00050 Vector2 operator*(const Vector2 &v, const double s); 00051 Vector2 operator/(const Vector2 &v, const double s) throw(Except); 00052 double PolarAngle(const Vector2 &v); 00053 double Length(const Vector2 &v); 00054 Vector2 Normalise(const Vector2 &v); 00055 double Dot(const Vector2 &a, const Vector2 &b); 00056 double Cross(const Vector2 &a, const Vector2 &b); 00057 bool LeftOf(const Vector2 &a, const Vector2 &b); 00058 bool CounterClockwiseTo(const Vector2 &a, const Vector2 &b); 00059 bool RightOf(const Vector2 &a, const Vector2 &b); 00060 bool ClockwiseTo(const Vector2 &a, const Vector2 &b); 00061 double DistanceSquare(const Vector2 &a, const Vector2 &b); 00062 double Distance(const Vector2 &a, const Vector2 &b); 00063 Vector2 LineIntersection(const Vector2 &p1, const Vector2 &d1, 00064 const Vector2 &p2, const Vector2 &d2) throw(Except); 00065 Vector2 LineIntersection(const Vector2 &p1, const Vector2 &d1, 00066 const Vector2 &p2, const Vector2 &d2, double *l1, double *l2) throw(Except); 00067 bool LinesIntersecting(const Vector2 &a1, const Vector2 &a2, 00068 const Vector2 &b1, const Vector2 &b2); 00069 bool LinesIntersecting(const Vector2 &a1, const Vector2 &a2, 00070 const Vector2 &b1, const Vector2 &b2, Vector2 &isct); 00071 double DistPointToLine(const Vector2 &q, const Vector2 &p, const Vector2 &d); 00072 double AbsDistPointToLine(const Vector2 &q, const Vector2 &p, const Vector2 &d); 00073 Vector2 Rotate(const Vector2 &a, double phi); 00074 Vector2 CircleCenter(const Vector2 &pi, const Vector2 &pj, 00075 const Vector2 &pk); 00076 Vector2 MidPoint(const Vector2 &a, const Vector2 &b); 00077 00078 ostream& operator<<(ostream &os, const Vector2 &v); 00079 istream& operator>>(istream &is, Vector2 &v) throw(Except); 00080 string& operator<<(string &s, const Vector2 &v); 00081 const string& operator>>(const string &s, Vector2 &v); 00082 00083 } 00084 00085 #include <blort/Recognizer3D/Vector2.ic> 00086 #endif 00087