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