Vector2d.hh
00001 /* 00002 * Copyright 2011 Nate Koenig & Andrew Howard 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUdouble WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 * 00016 */ 00017 /* Desc: Two dimensional vector 00018 * Author: Nate Koenig 00019 * Date: 3 Apr 2007 00020 */ 00021 00022 #ifndef VECTOR2D_HH 00023 #define VECTOR2D_HH 00024 00025 #include <iostream> 00026 #include <math.h> 00027 #include <fstream> 00028 00029 namespace gazebo 00030 { 00031 namespace math 00032 { 00035 00037 class Vector2d 00038 { 00040 public: Vector2d(); 00041 00043 public: Vector2d( const double &x, const double &y ); 00044 00046 public: Vector2d( const Vector2d &pt ); 00047 00049 public: virtual ~Vector2d(); 00050 00052 public: double Distance( const Vector2d &pt ) const; 00053 00055 public: void Normalize(); 00056 00058 public: void Set(double x, double y); 00059 00061 public: Vector2d GetCrossProd(const Vector2d &pt) const; 00062 00064 public: const Vector2d &operator=( const Vector2d &pt ); 00065 00067 public: const Vector2d &operator=( double value ); 00068 00070 public: Vector2d operator+( const Vector2d &pt ) const; 00071 00073 public: const Vector2d &operator+=( const Vector2d &pt ); 00074 00076 public: Vector2d operator-( const Vector2d &pt ) const; 00077 00079 public: const Vector2d &operator-=( const Vector2d &pt ); 00080 00082 public: const Vector2d operator/( const Vector2d &pt ) const; 00083 00085 public: const Vector2d &operator/=( const Vector2d &pt ); 00086 00088 public: const Vector2d operator/( double v ) const; 00089 00091 public: const Vector2d &operator/=( double v ); 00092 00094 public: const Vector2d operator*( const Vector2d &pt ) const; 00095 00097 public: const Vector2d &operator*=( const Vector2d &pt ); 00098 00100 public: const Vector2d operator*( double v ) const; 00101 00103 public: const Vector2d &operator*=( double v ); 00104 00106 public: bool operator==( const Vector2d &pt ) const; 00107 00109 public: bool operator!=( const Vector2d &pt ) const; 00110 00112 public: bool IsFinite() const; 00113 00115 public: double operator[](unsigned int index) const; 00116 00118 public: double x; 00119 00121 public: double y; 00122 00127 public: friend std::ostream &operator<<( std::ostream &out, const gazebo::math::Vector2d &pt ) 00128 { 00129 out << pt.x << " " << pt.y; 00130 return out; 00131 } 00132 00137 public: friend std::istream &operator>>( std::istream &in, gazebo::math::Vector2d &pt ) 00138 { 00139 // Skip white spaces 00140 in.setf( std::ios_base::skipws ); 00141 in >> pt.x >> pt.y; 00142 return in; 00143 } 00144 }; 00145 00147 } 00148 } 00149 #endif

1.7.5.1