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 (C) 2012-2014 Open Source Robotics Foundation
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 #include "gazebo/util/system.hh"
29 
30 namespace gazebo
31 {
32  namespace math
33  {
36 
40  {
42  public: Vector2d();
43 
47  public: Vector2d(const double &_x, const double &_y);
48 
51  public: Vector2d(const Vector2d &_v);
52 
54  public: virtual ~Vector2d();
55 
59  public: double Distance(const Vector2d &_pt) const;
60 
62  public: void Normalize();
63 
67  public: void Set(double _x, double _y);
68 
72  public: Vector2d Cross(const Vector2d &_v) const;
73 
77  public: Vector2d &operator =(const Vector2d &_v);
78 
82  public: const Vector2d &operator =(double _v);
83 
87  public: Vector2d operator+(const Vector2d &_v) const;
88 
91  // \return this
92  public: const Vector2d &operator+=(const Vector2d &_v);
93 
97  public: Vector2d operator-(const Vector2d &_v) const;
98 
102  public: const Vector2d &operator-=(const Vector2d &_v);
103 
108  public: const Vector2d operator/(const Vector2d &_v) const;
109 
114  public: const Vector2d &operator/=(const Vector2d &_v);
115 
119  public: const Vector2d operator/(double _v) const;
120 
124  public: const Vector2d &operator/=(double _v);
125 
129  public: const Vector2d operator*(const Vector2d &_v) const;
130 
135  public: const Vector2d &operator*=(const Vector2d &_v);
136 
140  public: const Vector2d operator*(double _v) const;
141 
145  public: const Vector2d &operator*=(double _v);
146 
151  public: bool operator ==(const Vector2d &_v) const;
152 
155  public: bool operator!=(const Vector2d &_v) const;
156 
159  public: bool IsFinite() const;
160 
164  public: double operator[](unsigned int _index) const;
165 
167  public: double x;
168 
170  public: double y;
171 
176  public: friend std::ostream &operator<<(std::ostream &_out,
177  const gazebo::math::Vector2d &_pt)
178  {
179  _out << _pt.x << " " << _pt.y;
180  return _out;
181  }
182 
187  public: friend std::istream &operator>>(std::istream &_in,
189  {
190  // Skip white spaces
191  _in.setf(std::ios_base::skipws);
192  _in >> _pt.x >> _pt.y;
193  return _in;
194  }
195  };
196 
198  }
199 }
200 #endif
201 
202 
203