INET Framework for OMNeT++/OMNEST
inet::RotationMatrix Class Reference

#include <RotationMatrix.h>

Public Member Functions

 RotationMatrix ()
 
 RotationMatrix (const double matrix[3][3])
 
 RotationMatrix (const EulerAngles &eulerAngles)
 
Coord rotateVector (const Coord &vector) const
 
Coord rotateVectorInverse (const Coord &vector) const
 
EulerAngles toEulerAngles () const
 
Quaternion toQuaternion () const
 

Protected Member Functions

void computeRotationMatrix (const double &q0, const double &q1, const double &q2, const double &q3)
 
double computeDeterminant () const
 

Protected Attributes

double matrix [3][3]
 

Constructor & Destructor Documentation

◆ RotationMatrix() [1/3]

inet::RotationMatrix::RotationMatrix ( )
16 {
17  // identity matrix
18  matrix[0][0] = 1;
19  matrix[0][1] = matrix[0][2] = 0;
20  matrix[1][1] = 1;
21  matrix[1][0] = matrix[1][2] = 0;
22  matrix[2][2] = 1;
23  matrix[2][1] = matrix[2][0] = 0;
24 }

◆ RotationMatrix() [2/3]

inet::RotationMatrix::RotationMatrix ( const double  matrix[3][3])
27 {
28  for (int i = 0; i < 3; i++)
29  for (int j = 0; j < 3; j++)
30  this->matrix[i][j] = matrix[i][j];
32 }

◆ RotationMatrix() [3/3]

inet::RotationMatrix::RotationMatrix ( const EulerAngles eulerAngles)
35 {
36  Quaternion q(eulerAngles);
37  computeRotationMatrix(q.s, q.v.x, q.v.y, q.v.z);
38 }

Member Function Documentation

◆ computeDeterminant()

double inet::RotationMatrix::computeDeterminant ( ) const
protected
55 {
56  return matrix[0][0] * ((matrix[1][1] * matrix[2][2]) - (matrix[2][1] * matrix[1][2])) - matrix[0][1] * (matrix[1][0] * matrix[2][2] - matrix[2][0] * matrix[1][2]) + matrix[0][2] * (matrix[1][0] * matrix[2][1] - matrix[2][0] * matrix[1][1]);
57 }

Referenced by RotationMatrix().

◆ computeRotationMatrix()

void inet::RotationMatrix::computeRotationMatrix ( const double &  q0,
const double &  q1,
const double &  q2,
const double &  q3 
)
protected
41 {
42  // Ref: http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles
43  matrix[0][0] = 1 - 2 * (q2 * q2 + q3 * q3);
44  matrix[0][1] = 2 * (q1 * q2 - q0 * q3);
45  matrix[0][2] = 2 * (q0 * q2 + q1 * q3);
46  matrix[1][0] = 2 * (q1 * q2 + q0 * q3);
47  matrix[1][1] = 1 - 2 * (q1 * q1 + q3 * q3);
48  matrix[1][2] = 2 * (q2 * q3 - q0 * q1);
49  matrix[2][0] = 2 * (q1 * q3 - q0 * q2);
50  matrix[2][1] = 2 * (q0 * q1 + q2 * q3);
51  matrix[2][2] = 1 - 2 * (q1 * q1 + q2 * q2);
52 }

Referenced by RotationMatrix().

◆ rotateVector()

◆ rotateVectorInverse()

Coord inet::RotationMatrix::rotateVectorInverse ( const Coord vector) const
67 {
68  return Coord(vector.x * matrix[0][0] + vector.y * matrix[1][0] + vector.z * matrix[2][0],
69  vector.x * matrix[0][1] + vector.y * matrix[1][1] + vector.z * matrix[2][1],
70  vector.x * matrix[0][2] + vector.y * matrix[1][2] + vector.z * matrix[2][2]);
71 }

Referenced by inet::CanvasProjection::computeCanvasPointInverse(), inet::physicallayer::DielectricObstacleLoss::computeObjectLoss(), and inet::physicallayer::IdealObstacleLoss::isObstacle().

◆ toEulerAngles()

EulerAngles inet::RotationMatrix::toEulerAngles ( ) const
74 {
75  // Ref: http://planning.cs.uiuc.edu/node103.html
76  // NOTE: this algorithm works only if matrix[0][0] != 0 and matrix[2][2] != 0
77  double tx = atan2(matrix[2][1], matrix[2][2]);
78  double ty = atan2(-matrix[2][0], sqrt(matrix[2][1] * matrix[2][1] + matrix[2][2] * matrix[2][2]));
79  double tz = atan2(matrix[1][0], matrix[0][0]);
80  return EulerAngles(rad(tz), rad(ty), rad(tx));
81 }

◆ toQuaternion()

Quaternion inet::RotationMatrix::toQuaternion ( ) const
84 {
85  // Ref: http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/
86  double w, x, y, z;
87  double trace = matrix[0][0] + matrix[1][1] + matrix[2][2];
88  if (trace > 0) {
89  double s = 0.5 / sqrt(trace + 1.0);
90  w = 0.25 / s;
91  x = (matrix[2][1] - matrix[1][2]) * s;
92  y = (matrix[0][2] - matrix[2][0]) * s;
93  z = (matrix[1][0] - matrix[0][1]) * s;
94  }
95  else {
96  if (matrix[0][0] > matrix[1][1] && matrix[0][0] > matrix[2][2]) {
97  double s = 2.0 * sqrt(1.0 + matrix[0][0] - matrix[1][1] - matrix[2][2]);
98  w = (matrix[2][1] - matrix[1][2]) / s;
99  x = 0.25 * s;
100  y = (matrix[0][1] + matrix[1][0]) / s;
101  z = (matrix[0][2] + matrix[2][0]) / s;
102  }
103  else if (matrix[1][1] > matrix[2][2]) {
104  double s = 2.0 * sqrt(1.0 + matrix[1][1] - matrix[0][0] - matrix[2][2]);
105  w = (matrix[0][2] - matrix[2][0]) / s;
106  x = (matrix[0][1] + matrix[1][0]) / s;
107  y = 0.25 * s;
108  z = (matrix[1][2] + matrix[2][1]) / s;
109  }
110  else {
111  double s = 2.0 * sqrt(1.0 + matrix[2][2] - matrix[0][0] - matrix[1][1]);
112  w = (matrix[1][0] - matrix[0][1]) / s;
113  x = (matrix[0][2] + matrix[2][0]) / s;
114  y = (matrix[1][2] + matrix[2][1]) / s;
115  z = 0.25 * s;
116  }
117  }
118  return Quaternion(w, x, y, z);
119 }

Referenced by inet::SuperpositioningMobility::getCurrentAngularPosition().

Member Data Documentation

◆ matrix

double inet::RotationMatrix::matrix[3][3]
protected

The documentation for this class was generated from the following files:
inet::RotationMatrix::matrix
double matrix[3][3]
Definition: RotationMatrix.h:23
inet::RotationMatrix::computeDeterminant
double computeDeterminant() const
Definition: RotationMatrix.cc:54
inet::RotationMatrix::computeRotationMatrix
void computeRotationMatrix(const double &q0, const double &q1, const double &q2, const double &q3)
Definition: RotationMatrix.cc:40
inet::units::sqrt
value< Value, pow< Unit, 1, 2 > > sqrt(const value< Value, Unit > &a)
Definition: Units.h:272
inet::units::values::s
value< double, units::s > s
Definition: Units.h:1235
inet::math::close
bool close(double one, double two)
Tests whether two doubles are close enough to be declared equal.
Definition: INETMath.h:123
inet::units::values::rad
value< double, units::rad > rad
Definition: Units.h:1245