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 2012 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 
29 namespace gazebo
30 {
31  namespace math
32  {
35 
38  class Vector2d
39  {
41  public: Vector2d();
42 
46  public: Vector2d(const double &_x, const double &_y);
47 
50  public: Vector2d(const Vector2d &_v);
51 
53  public: virtual ~Vector2d();
54 
58  public: double Distance(const Vector2d &_pt) const;
59 
61  public: void Normalize();
62 
66  public: void Set(double _x, double _y);
67 
71  public: Vector2d Cross(const Vector2d &_v) const;
72 
76  public: Vector2d &operator =(const Vector2d &_v);
77 
81  public: const Vector2d &operator =(double _v);
82 
86  public: Vector2d operator+(const Vector2d &_v) const;
87 
90  // \return this
91  public: const Vector2d &operator+=(const Vector2d &_v);
92 
96  public: Vector2d operator-(const Vector2d &_v) const;
97 
101  public: const Vector2d &operator-=(const Vector2d &_v);
102 
107  public: const Vector2d operator/(const Vector2d &_v) const;
108 
113  public: const Vector2d &operator/=(const Vector2d &_v);
114 
118  public: const Vector2d operator/(double _v) const;
119 
123  public: const Vector2d &operator/=(double _v);
124 
128  public: const Vector2d operator*(const Vector2d &_v) const;
129 
134  public: const Vector2d &operator*=(const Vector2d &_v);
135 
139  public: const Vector2d operator*(double _v) const;
140 
144  public: const Vector2d &operator*=(double _v);
145 
150  public: bool operator ==(const Vector2d &_v) const;
151 
154  public: bool operator!=(const Vector2d &_v) const;
155 
158  public: bool IsFinite() const;
159 
163  public: double operator[](unsigned int _index) const;
164 
166  public: double x;
167 
169  public: double y;
170 
175  public: friend std::ostream &operator<<(std::ostream &_out,
176  const gazebo::math::Vector2d &_pt)
177  {
178  _out << _pt.x << " " << _pt.y;
179  return _out;
180  }
181 
186  public: friend std::istream &operator>>(std::istream &_in,
188  {
189  // Skip white spaces
190  _in.setf(std::ios_base::skipws);
191  _in >> _pt.x >> _pt.y;
192  return _in;
193  }
194  };
195 
197  }
198 }
199 #endif
200 
201 
202