All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Vector2d.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2011 Nate Koenig
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUdouble WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 /* Desc: Two dimensional vector
18  * Author: Nate Koenig
19  * Date: 3 Apr 2007
20  */
21 
22 #ifndef VECTOR2D_HH
23 #define VECTOR2D_HH
24 
25 #include <math.h>
26 #include <iostream>
27 #include <fstream>
28 
29 namespace gazebo
30 {
31  namespace math
32  {
35 
37  class Vector2d
38  {
40  public: Vector2d();
41 
45  public: Vector2d(const double &_x, const double &_y);
46 
49  public: Vector2d(const Vector2d &_v);
50 
52  public: virtual ~Vector2d();
53 
56  public: double Distance(const Vector2d &_pt) const;
57 
59  public: void Normalize();
60 
64  public: void Set(double _x, double _y);
65 
69  public: Vector2d Cross(const Vector2d &_v) const;
70 
74  public: Vector2d &operator =(const Vector2d &_v);
75 
79  public: const Vector2d &operator =(double _v);
80 
84  public: Vector2d operator+(const Vector2d &_v) const;
85 
88  // \return this
89  public: const Vector2d &operator+=(const Vector2d &_v);
90 
94  public: Vector2d operator-(const Vector2d &_v) const;
95 
99  public: const Vector2d &operator-=(const Vector2d &_v);
100 
105  public: const Vector2d operator/(const Vector2d &_v) const;
106 
111  public: const Vector2d &operator/=(const Vector2d &_v);
112 
116  public: const Vector2d operator/(double _v) const;
117 
121  public: const Vector2d &operator/=(double _v);
122 
126  public: const Vector2d operator*(const Vector2d &_v) const;
127 
132  public: const Vector2d &operator*=(const Vector2d &_v);
133 
137  public: const Vector2d operator*(double _v) const;
138 
142  public: const Vector2d &operator*=(double _v);
143 
148  public: bool operator ==(const Vector2d &_v) const;
149 
152  public: bool operator!=(const Vector2d &_v) const;
153 
156  public: bool IsFinite() const;
157 
161  public: double operator[](unsigned int _index) const;
162 
164  public: double x;
165 
167  public: double y;
168 
173  public: friend std::ostream &operator<<(std::ostream &_out,
174  const gazebo::math::Vector2d &_pt)
175  {
176  _out << _pt.x << " " << _pt.y;
177  return _out;
178  }
179 
184  public: friend std::istream &operator>>(std::istream &_in,
186  {
187  // Skip white spaces
188  _in.setf(std::ios_base::skipws);
189  _in >> _pt.x >> _pt.y;
190  return _in;
191  }
192  };
193 
195  }
196 }
197 #endif
198 
199 
200