libalmath  2.5.7.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
alposition2d.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012 Aldebaran Robotics. All rights reserved.
3  * Use of this source code is governed by a BSD-style license that can be
4  * found in the COPYING file.
5  */
6 
7 
8 #pragma once
9 #ifndef _LIBALMATH_ALMATH_TYPES_ALPOSITION2D_H_
10 #define _LIBALMATH_ALMATH_TYPES_ALPOSITION2D_H_
11 
12 #include <vector>
13 
14 namespace AL {
15  namespace Math {
16 
23  struct Position2D
24  {
26  float x;
28  float y;
29 
32 
43  Position2D();
45 
48 
59  explicit Position2D(float pInit);
63 
66 
77  Position2D(float pX, float pY);
81 
84 
95  Position2D(const std::vector<float>& pFloats);
101 
108  static Position2D fromPolarCoordinates(const float pRadius,
109  const float pAngle);
110 
115  inline Position2D operator+ (const Position2D& pPos2) const
116  {
117  return Position2D(x + pPos2.x, y + pPos2.y);
118  }
119 
124  inline Position2D operator- (const Position2D& pPos2) const
125  {
126  return Position2D(x - pPos2.x, y - pPos2.y);
127  }
128 
132  inline Position2D operator+ (void) const
133  {
134  return *this;
135  }
136 
140  inline Position2D operator- () const
141  {
142  return Position2D(-x, -y);
143  }
144 
149  Position2D& operator+= (const Position2D& pPos2);
150 
155  Position2D& operator-= (const Position2D& pPos2);
156 
164  bool operator==(const Position2D& pPos2) const;
165 
173  bool operator!=(const Position2D& pPos2) const;
174 
179  inline Position2D operator* (float pVal) const
180  {
181  return Position2D(x*pVal, y*pVal);
182  }
183 
188  Position2D operator/ (float pVal) const;
189 
194  Position2D& operator*= (float pVal);
195 
200  Position2D& operator/= (float pVal);
201 
212  float distanceSquared(const Position2D& pPos2) const;
213 
224  float distance(const Position2D& pPos2) const;
225 
235  bool isNear(
236  const Position2D& pPos2,
237  const float& pEpsilon=0.0001f) const;
238 
247  float norm() const;
248 
257  Position2D normalize() const;
258 
269  float dotProduct(const Position2D& pPos2) const;
270 
281  float crossProduct(const Position2D& pPos2) const;
282 
286  void toVector(std::vector<float>& pReturnVector) const;
287  std::vector<float> toVector(void) const;
288 
293  void writeToVector(std::vector<float>::iterator& pIt) const;
294 
300  float getAngle() const;
301  };
302 
303  // TODO : Need this ?
304  Position2D operator* (
305  const float pM,
306  const Position2D& pPos1);
307 
319  float distanceSquared(
320  const Position2D& pPos1,
321  const Position2D& pPos2);
322 
334  float distance(
335  const Position2D& pPos1,
336  const Position2D& pPos2);
337 
348  float norm(const Position2D& pPos);
349 
360  Position2D normalize(const Position2D& pPos);
361 
372  float dotProduct(
373  const Position2D& pPos1,
374  const Position2D& pPos2);
375 
387  float crossProduct(
388  const Position2D& pPos1,
389  const Position2D& pPos2);
390 
401  void crossProduct(
402  const Position2D& pPos1,
403  const Position2D& pPos2,
404  float& pRes);
405 
406  } // end namespace math
407 } // end namespace al
408 #endif // _LIBALMATH_ALMATH_TYPES_ALPOSITION2D_H_
Position2D operator-() const
Overloading of operator - for Position2D.
Definition: alposition2d.h:140
bool isNear(const Position2D &pPos2, const float &pEpsilon=0.0001f) const
Check if the actual Position2D is near the one give in argument.
float getAngle() const
Return the angular direction of a Position2D.
float crossProduct(const Position2D &pPos1, const Position2D &pPos2)
Compute the cross Product of two Position2D.
float distanceSquared(const Position2D &pPos2) const
Compute the squared distance between the actual Position2D and the one give in argument.
Position2D & operator/=(float pVal)
Overloading of operator /= for Position2D.
float norm(const Position2D &pPos)
Compute the norm of a Position2D.
std::vector< float > toVector(void) const
Position2D normalize() const
Normalize the actual Position2D.
bool operator!=(const Position2D &pPos2) const
Overloading of operator != for Position2D.
Create and play with a Position2D.
Definition: alposition2d.h:23
bool operator==(const Position2D &pPos2) const
Overloading of operator == for Position2D.
Position2D & operator*=(float pVal)
Overloading of operator *= for Position2D.
Position2D & operator-=(const Position2D &pPos2)
Overloading of operator -= for Position2D.
float distanceSquared(const Pose2D &pPos1, const Pose2D &pPos2)
Compute the squared distance between two Pose2D.
float dotProduct(const Position2D &pPos1, const Position2D &pPos2)
Compute the dot Product between two Position2D:
void writeToVector(std::vector< float >::iterator &pIt) const
Write [x, y] in the vector and update the iterator. It is assumed the vector has enough space...
float distance(const Position2D &pPos2) const
Compute the distance between the actual Position2D and the one give in argument.
float norm() const
Compute the norm of the actual Position2D.
float distance(const Pose2D &pPos1, const Pose2D &pPos2)
Compute the distance between two Pose2D.
Position2D normalize(const Position2D &pPos)
Normalize a Position2D.
float dotProduct(const Position2D &pPos2) const
Compute the dot Product between the actual Position2D and the one give in argument.
static Position2D fromPolarCoordinates(const float pRadius, const float pAngle)
Build a Position2D from polar coordinates.
Position2D operator/(float pVal) const
Overloading of operator / for Position2D.
Position2D & operator+=(const Position2D &pPos2)
Overloading of operator += for Position2D.
Position2D operator+(void) const
Overloading of operator + for Position2D.
Definition: alposition2d.h:132
Position3D operator*(const Rotation &pRot, const Position3D &pPos)
Overloading of operator * between Rotation and Position3D:
Position2D()
Create a Position2D initialized with 0.0f.
Position2D operator*(float pVal) const
Overloading of operator * for Position2D.
Definition: alposition2d.h:179
float crossProduct(const Position2D &pPos2) const
Compute the cross Product between the actual Position2D and the one give in argument.