libalmath  2.5.11.14a
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
alrotation.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_ALROTATION_H_
10 #define _LIBALMATH_ALMATH_TYPES_ALROTATION_H_
11 
12 #include <vector>
13 
14 namespace AL {
15  namespace Math {
16 
19 
27  struct Rotation
31  {
35  float r1_c1;
39  float r1_c2;
43  float r1_c3;
47  float r2_c1;
51  float r2_c2;
55  float r2_c3;
59  float r3_c1;
63  float r3_c2;
67  float r3_c3;
68 
71 
84  Rotation();
86 
95 
109 
125  Rotation (const std::vector<float>& pFloats);
127 
132  Rotation& operator*= (const Rotation& pRot2);
133 
138  Rotation operator* (const Rotation& pRot2) const;
139 
144  bool operator==(const Rotation& pRot2) const;
145 
150  bool operator!=(const Rotation& pRot2) const;
151 
162  bool isNear(
163  const Rotation& pRot2,
164  const float& pEpsilon=0.0001f) const;
165 
170  void normalizeRotation(void);
171 
184  bool isRotation(const float& pEpsilon=0.0001f) const;
185 
192  Rotation transpose() const;
193 
197 
204  float determinant() const;
209 
217  static Rotation fromQuaternion(
218  const float pA,
219  const float pB,
220  const float pC,
221  const float pD);
222 
223 
232  const float pAngle,
233  const float pX,
234  const float pY,
235  const float pZ);
236 
240 
246  static Rotation fromRotX(const float pRotX);
249 
250  static Rotation fromRotXPi() {
251  Rotation r; // identity
252  r.r2_c2 = -1.f;
253  r.r3_c3 = -1.f;
254  return r;
255  }
256 
260 
266  static Rotation fromRotY(const float pRotY);
269 
270  static Rotation fromRotYPi() {
271  Rotation r; // identity
272  r.r1_c1 = -1.f;
273  r.r3_c3 = -1.f;
274  return r;
275  }
276 
280 
286  static Rotation fromRotZ(const float pRotZ);
289 
293  static Rotation fromRotZPi() {
294  Rotation r; // identity
295  r.r1_c1 = -1.f;
296  r.r2_c2 = -1.f;
297  return r;
298  }
299 
304  Rotation r; // identity
305  r.r1_c1 = 0.f;
306  r.r1_c2 = -1.f;
307  r.r2_c1 = 1.f;
308  r.r2_c2 = 0.f;
309  return r;
310  }
311 
321  static Rotation from3DRotation(
322  const float& pWX,
323  const float& pWY,
324  const float& pWZ);
325 
329 
335  void toVector(std::vector<float>& pReturnValue) const;
337  std::vector<float> toVector(void) const;
338 
339  }; // end struct
340 
350  Rotation transpose(const Rotation& pRot);
351 
352 
356 
363  float determinant(const Rotation& pRot);
370 
377  void normalizeRotation(Rotation& pRot);
378 
390  Rotation rotationFromQuaternion(
391  const float pA,
392  const float pB,
393  const float pC,
394  const float pD);
395 
408  const float pAngle,
409  const float pX,
410  const float pY,
411  const float pZ);
412 
421  void applyRotation(
422  const AL::Math::Rotation& pRot,
423  float& pX,
424  float& pY,
425  float& pZ);
426 
430 
436  Rotation rotationFromRotX(const float pRotX);
443 
447 
453  Rotation rotationFromRotY(const float pRotY);
460 
464 
469  Rotation rotationFromRotZ(const float pRotZ);
476 
489  Rotation rotationFrom3DRotation(
490  const float& pWX,
491  const float& pWY,
492  const float& pWZ);
493 
494  }
495 }
496 #endif // _LIBALMATH_ALMATH_TYPES_ALROTATION_H_
Rotation & operator*=(const Rotation &pRot2)
Overloading of operator *= for Rotation.
void normalizeRotation(void)
Normalize data, if needed, to have Rotation properties.
float r2_c1
row 2 column 1.
Definition: alrotation.h:47
Rotation rotationFromRotX(const float pRotX)
Create a Rotation initialized with explicit rotation around x axis.
bool operator!=(const Rotation &pRot2) const
Overloading of operator != for Rotation.
Rotation operator*(const Rotation &pRot2) const
Overloading of operator * for Rotation.
bool operator==(const Rotation &pRot2) const
Overloading of operator == for Rotation.
static Rotation fromRotX(const float pRotX)
Create a Rotation initialized with explicit rotation around x axis.
float r3_c1
row 3 column 1.
Definition: alrotation.h:59
float r3_c2
row 3 column 2.
Definition: alrotation.h:63
static Rotation fromRotXPi()
Definition: alrotation.h:250
Rotation()
Create a Rotation initialized to identity.
Rotation rotationFrom3DRotation(const float &pWX, const float &pWY, const float &pWZ)
Create a Rotation initialized with euler angle. Rot = fromRotZ(pWZ)*fromRotY(pWY)*fromRotX(pWX) ...
static Rotation fromRotZHalfPi()
Create a Rotation initialized with rotation of pi/2 around z axis.
Definition: alrotation.h:303
A 3*3 rotation matrix.
Definition: alrotation.h:30
Rotation transpose(const Rotation &pRot)
Compute the transpose rotation of the one given in argument:
float r1_c2
row 1 column 2.
Definition: alrotation.h:39
std::vector< float > toVector(void) const
Rotation rotationFromRotY(const float pRotY)
Create a Rotation initialized with explicit rotation around y axis.
bool isRotation(const float &pEpsilon=0.0001f) const
Check if the rotation is correct. The condition checks are: and determinant(R) = 1...
static Rotation fromQuaternion(const float pA, const float pB, const float pC, const float pD)
Creates a 3*3 Rotation Matrix from a normalized quaternion ( |a + bi + cj + dk| = 1)...
Rotation transpose() const
Compute the rotation transpose (inverse) of the actual Rotation:
Rotation rotationFromAngleDirection(const float &pTheta, const Position3D &pPos)
Creates a 3*3 Rotation Matrix from a an angle and a normalized Position3D.
float r2_c2
row 2 column 2.
Definition: alrotation.h:51
Rotation rotationFromRotZ(const float pRotZ)
Create a Rotation initialized with explicit rotation around z axis.
static Rotation from3DRotation(const float &pWX, const float &pWY, const float &pWZ)
Create a Rotation initialized with euler angle.
static Rotation fromRotZPi()
Create a Rotation initialized with rotation of pi around z axis.
Definition: alrotation.h:293
static Rotation fromAngleDirection(const float pAngle, const float pX, const float pY, const float pZ)
Creates a 3*3 Rotation Matrix from a an angle and a normalized direction( |pX, pY, pZ| = 1).
float r2_c3
row 2 column 3.
Definition: alrotation.h:55
float r3_c3
row 3 column 3.
Definition: alrotation.h:67
static Rotation fromRotZ(const float pRotZ)
Create a Rotation initialized with explicit rotation around z axis.
static Rotation fromRotYPi()
Definition: alrotation.h:270
float determinant(const Rotation &pRot)
Compute the determinant of the given Rotation:
float r1_c1
row 1 column 1.
Definition: alrotation.h:35
static Rotation fromRotY(const float pRotY)
Create a Rotation initialized with explicit rotation around y axis.
void applyRotation(const AL::Math::Rotation &pRot, float &pX, float &pY, float &pZ)
Apply Rotation to a 3D point.
bool isNear(const Rotation &pRot2, const float &pEpsilon=0.0001f) const
Check if the actual Rotation is near the one give in argument.
void rotationFromQuaternion(const Quaternion &pQua, Rotation &pRot)
Create a Rotation Matrix from a Quaternion
float determinant() const
Compute the determinant of the Rotation:
float r1_c3
row 1 column 3.
Definition: alrotation.h:43
void normalizeRotation(Rotation &pRot)
Normalize data, if needed, to have Rotation properties.