libalmath  2.8.7.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
alpose2d.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_ALPOSE2D_H_
10 #define _LIBALMATH_ALMATH_TYPES_ALPOSE2D_H_
11 
12 #include <vector>
13 #include <cmath>
14 #include <almath/api.h>
15 
16 namespace AL {
17  namespace Math {
18 
26  struct ALMATH_API Pose2D {
28  float x;
30  float y;
32  float theta;
33 
36 
49  Pose2D();
51 
54 
67  explicit Pose2D(float pInit);
70 
73 
86  explicit Pose2D(
91  float pX,
92  float pY,
93  float pTheta);
94 
97 
110  Pose2D(const std::vector<float>& pFloats);
117 
125  static Pose2D fromPolarCoordinates(const float pRadius, const float pAngle);
126 
131  inline Pose2D operator+ (const Pose2D& pPos2) const
132  {
133  return Pose2D(x + pPos2.x, y + pPos2.y, theta + pPos2.theta);
134  }
135 
140  inline Pose2D operator- (const Pose2D& pPos2) const
141  {
142  return Pose2D(x - pPos2.x, y - pPos2.y, theta - pPos2.theta);
143  }
144 
148  inline Pose2D operator+ (void) const
149  {
150  return *this;
151  }
152 
156  inline Pose2D operator- () const
157  {
158  return Pose2D(-x, -y, -theta);
159  }
160 
165  Pose2D& operator+= (const Pose2D& pPos2);
166 
171  Pose2D& operator-= (const Pose2D& pPos2);
172 
177  Pose2D& operator*= (const Pose2D& pPos2);
178 
183  inline Pose2D operator* (const Pose2D& pPos2) const
184  {
185  return Pose2D(
186  x + std::cos(theta) * pPos2.x - std::sin(theta) * pPos2.y,
187  y + std::sin(theta) * pPos2.x + std::cos(theta) * pPos2.y,
188  theta + pPos2.theta);
189  }
190 
195  bool operator==(const Pose2D& pPos2) const;
196 
201  bool operator!=(const Pose2D& pPos2) const;
202 
207  inline Pose2D operator* (float pVal) const
208  {
209  return Pose2D(x*pVal, y*pVal, theta*pVal);
210  }
211 
216  Pose2D operator/ (float pVal) const;
217 
222  Pose2D& operator*= (float pVal);
223 
228  Pose2D& operator/= (float pVal);
229 
242  float distanceSquared(const Pose2D& pPos2) const;
243 
254  float distance(const Pose2D& pPos2) const;
255 
259  Pose2D inverse() const;
260 
269  Pose2D diff(const Pose2D& pPos2) const;
270 
281  bool isNear(const Pose2D& pPos2,
282  const float& pEpsilon=0.0001f) const;
283 
287  void toVector(std::vector<float>& pReturnVector) const;
288  std::vector<float> toVector(void) const;
289 
294  void writeToVector(std::vector<float>::iterator& pIt) const;
295 
302  inline float norm() const
303  {
304  return std::sqrt(x * x + y * y);
305  }
306 
315  Pose2D normalize() const;
316 
323  inline float getAngle(void) const
324  {
325  return std::atan2(y, x);
326  }
327  }; // end struct
328 
329 
341  ALMATH_API float distanceSquared(
342  const Pose2D& pPos1,
343  const Pose2D& pPos2);
344 
356  ALMATH_API float distance(
357  const Pose2D& pPos1,
358  const Pose2D& pPos2);
359 
366  ALMATH_API void pose2dInvertInPlace(Pose2D& pPos);
367 
374  ALMATH_API Pose2D pinv(const Pose2D& pPos);
375 
376 
389  ALMATH_API Pose2D pose2dDiff(
390  const Pose2D& pPos1,
391  const Pose2D& pPos2);
392 
399  ALMATH_API Pose2D pose2DInverse(const Pose2D& pPos);
400 
407  ALMATH_API void pose2DInverse(
408  const Pose2D& pPos,
409  Pose2D& pRes);
410 
411 
412  } // end namespace math
413 } // end namespace AL
414 #endif // _LIBALMATH_ALMATH_TYPES_ALPOSE2D_H_
ALMATH_API Pose2D pinv(const Pose2D &pPos)
Alternative name for inverse: return the pose2d inverse of the given Pose2D.
ALMATH_API float distance(const Pose2D &pPos1, const Pose2D &pPos2)
Compute the distance between two Pose2D.
BodyMass< T > operator+(const BodyMass< T > &lhs, const BodyMass< T > &rhs)
Definition: bodymass.h:111
float norm() const
Compute the norm of the current Pose2D.
Definition: alpose2d.h:302
bool isNear(const Transform &lhs, const Transform &rhs, double epsilon)
Definition: qigeometry.h:111
ALMATH_API float distanceSquared(const Pose2D &pPos1, const Pose2D &pPos2)
Compute the squared distance between two Pose2D.
bool operator!=(const Pose &lhs, const Pose &rhs)
Definition: urdf.h:340
Transform inverse(const Transform &tf)
Definition: qigeometry.h:120
float getAngle(void) const
Returns the angle of the current Pose2D.
Definition: alpose2d.h:323
ALMATH_API Position2D normalize(const Position2D &pPos)
Normalize a Position2D.
ALMATH_API void pose2dInvertInPlace(Pose2D &pPos)
Inverse the given Pose2D in place:
ALMATH_API Pose2D pose2DInverse(const Pose2D &pPos)
Compute the inverse of a Pose2D.
A pose in a 2-dimentional space.
Definition: alpose2d.h:26
ALMATH_API Pose2D pose2dDiff(const Pose2D &pPos1, const Pose2D &pPos2)
Compute the Pose2D between the actual Pose2D and the one give in argument result: ...
bool operator==(const BodyMass< T > &lhs, const BodyMass< T > &rhs)
Definition: bodymass.h:79
ALMATH_API Position3D operator*(const Rotation &pRot, const Position3D &pPos)
Overloading of operator * between Rotation and Position3D: