00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef POINT_H_
00024 #define POINT_H_
00025
00026 #include <cmath>
00027 #include <iostream>
00028
00036 struct Point2D {
00038 Point2D();
00040 Point2D(double _x, double _y);
00041
00043 inline Point2D ortho()
00044 {return Point2D(y, -x);}
00045
00046 double x;
00047 double y;
00048 };
00049
00057 struct OrientedPoint2D: public Point2D {
00059 OrientedPoint2D();
00061 OrientedPoint2D(double _x, double _y, double _theta);
00062
00064 OrientedPoint2D ominus() const;
00065
00067 OrientedPoint2D ominus(const OrientedPoint2D& point) const;
00068
00070 Point2D ominus(const Point2D& point) const;
00071
00073 OrientedPoint2D oplus(const OrientedPoint2D& point) const;
00074
00076 Point2D oplus(const Point2D& point) const;
00077
00078 double theta;
00079 };
00080
00082 inline double deg2rad(double _angle)
00083 {return _angle/180.0*M_PI;}
00084
00086 inline double rad2deg(double _angle)
00087 {return _angle/M_PI*180.0;}
00088
00090 double normAngle(double angle, double base);
00091
00093 inline Point2D operator-(const Point2D& first, const Point2D& last)
00094 {return Point2D(first.x - last.x, first.y - last.y);}
00095
00097 inline Point2D operator+(const Point2D& first, const Point2D& last)
00098 {return Point2D(first.x + last.x, first.y + last.y);}
00099
00101 inline OrientedPoint2D operator-(const OrientedPoint2D& first, const OrientedPoint2D& last)
00102 {return OrientedPoint2D(first.x - last.x, first.y - last.y, normAngle(first.theta - last.theta, -M_PI));}
00103
00105 inline OrientedPoint2D operator+(const OrientedPoint2D& first, const OrientedPoint2D& last)
00106 {return OrientedPoint2D(first.x + last.x, first.y + last.y, normAngle(first.theta + last.theta, -M_PI));}
00107
00109 inline Point2D operator*(const Point2D& first, const double last)
00110 {return Point2D(first.x * last, first.y * last);}
00111
00113 inline Point2D operator*(const double last, const Point2D& first)
00114 {return Point2D(first.x * last, first.y * last);}
00115
00117 inline double operator*(const Point2D& first, const Point2D& last)
00118 {return first.x * last.x + first.y * last.y;}
00119
00121 inline std::ostream& operator << (std::ostream& out, const Point2D& point)
00122 {out << "(" << point.x << ", " << point.y << ")"; return out;}
00123
00125 inline std::ostream& operator << (std::ostream& out, const OrientedPoint2D& point)
00126 {out << "(" << point.x << ", " << point.y << ", " << point.theta << ")"; return out;}
00127
00128 #endif
00129