00001 // 00002 // Copyright (C) 2006 Institut fuer Telematik, Universitaet Karlsruhe (TH) 00003 // 00004 // This program is free software; you can redistribute it and/or 00005 // modify it under the terms of the GNU General Public License 00006 // as published by the Free Software Foundation; either version 2 00007 // of the License, or (at your option) any later version. 00008 // 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with this program; if not, write to the Free Software 00016 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 // 00018 00024 #ifndef __VECTOR2D_H_ 00025 #define __VECTOR2D_H_ 00026 00027 #include <math.h> 00028 #include <omnetpp.h> 00029 #include <iostream> 00030 00031 class Vector2D 00032 { 00033 public: 00034 Vector2D(); 00035 Vector2D(double x, double y); 00036 00037 double x, y; 00038 00039 void normalize(); 00040 double distanceSqr(const Vector2D v) const; 00041 double xyMaxDistance(const Vector2D v) const; 00042 double cosAngle(const Vector2D& v) const; 00043 int getQuadrant(const Vector2D& v) const; 00044 00045 Vector2D& operator=(const Vector2D& v); 00046 Vector2D& operator+=(const Vector2D& v); 00047 Vector2D& operator-=(const Vector2D& v); 00048 Vector2D& operator*=(const double s); 00049 Vector2D& operator/=(const double s); 00050 Vector2D operator+(const Vector2D& v) const; 00051 Vector2D operator-(const Vector2D& v) const; 00052 Vector2D operator*(const double s) const; 00053 Vector2D operator/(const double s) const; 00054 bool operator==(const Vector2D& v) const; 00055 bool operator!=(const Vector2D& v) const; 00056 00057 friend bool operator<(const Vector2D& a, const Vector2D& b); 00058 friend std::ostream& operator<<(std::ostream& Stream, const Vector2D& v); 00059 00060 void netPack(cCommBuffer *b); 00061 void netUnpack(cCommBuffer *b); 00062 }; 00063 00070 inline void doPacking(cCommBuffer *b, Vector2D& obj) {obj.netPack(b);} 00071 00078 inline void doUnpacking(cCommBuffer *b, Vector2D& obj) {obj.netUnpack(b);} 00079 00080 #endif