libalmath  2.1.4.13
 All Classes Namespaces Functions Variables Typedefs Groups Pages
alposition2d.h
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 
289 
295  float getAngle() const;
296  };
297 
298  // TODO : Need this ?
299  Position2D operator* (
300  const float pM,
301  const Position2D& pPos1);
302 
314  float distanceSquared(
315  const Position2D& pPos1,
316  const Position2D& pPos2);
317 
329  float distance(
330  const Position2D& pPos1,
331  const Position2D& pPos2);
332 
343  float norm(const Position2D& pPos);
344 
355  Position2D normalize(const Position2D& pPos);
356 
367  float dotProduct(
368  const Position2D& pPos1,
369  const Position2D& pPos2);
370 
382  float crossProduct(
383  const Position2D& pPos1,
384  const Position2D& pPos2);
385 
396  void crossProduct(
397  const Position2D& pPos1,
398  const Position2D& pPos2,
399  float& pRes);
400 
401  } // end namespace math
402 } // end namespace al
403 #endif // _LIBALMATH_ALMATH_TYPES_ALPOSITION2D_H_
static Position2D fromPolarCoordinates(const float pRadius, const float pAngle)
Build a Position2D from polar coordinates.
Position2D normalize() const
Normalize the actual Position2D.
float distanceSquared(const Position2D &pPos1, const Position2D &pPos2)
Compute the squared distance between two Position2D.
void crossProduct(const Position2D &pPos1, const Position2D &pPos2, float &pRes)
Compute the cross Product of two Position2D.
Position2D operator+(void) const
Overloading of operator + for Position2D.
Definition: alposition2d.h:132
float distance(const Position2D &pPos2) const
Compute the distance between the actual Position2D and the one give in argument.
float dotProduct(const Position2D &pPos2) const
Compute the dot Product between the actual Position2D and the one give in argument.
float norm(const Position2D &pPos)
Compute the norm of a Position2D.
bool operator==(const Position2D &pPos2) const
Overloading of operator == for Position2D.
Position2D & operator/=(float pVal)
Overloading of operator /= for Position2D.
bool isNear(const Position2D &pPos2, const float &pEpsilon=0.0001f) const
Check if the actual Position2D is near the one give in argument.
Position2D operator*(float pVal) const
Overloading of operator * for Position2D.
Definition: alposition2d.h:179
Position2D()
Create a Position2D initialized with 0.0f.
float norm() const
Compute the norm of the actual Position2D.
Position2D normalize(const Position2D &pPos)
Normalize a Position2D.
Position2D & operator+=(const Position2D &pPos2)
Overloading of operator += for Position2D.
Position3D operator*(const Rotation &pRot, const Position3D &pPos)
Overloading of operator * between Rotation and Position3D:
float distance(const Position2D &pPos1, const Position2D &pPos2)
Compute the distance between two Position2D :
Position2D operator/(float pVal) const
Overloading of operator / for Position2D.
Position2D operator-() const
Overloading of operator - for Position2D.
Definition: alposition2d.h:140
Position2D & operator*=(float pVal)
Overloading of operator *= for Position2D.
Position2D & operator-=(const Position2D &pPos2)
Overloading of operator -= for Position2D.
float getAngle() const
Return the angular direction of a Position2D.
bool operator!=(const Position2D &pPos2) const
Overloading of operator != for Position2D.
float crossProduct(const Position2D &pPos2) const
Compute the cross Product between the actual Position2D and the one give in argument.
Create and play with a Position2D.
Definition: alposition2d.h:23
float distanceSquared(const Position2D &pPos2) const
Compute the squared distance between the actual Position2D and the one give in argument.