g2o
dquat2mat.cpp
Go to the documentation of this file.
1 #include "dquat2mat.h"
2 #include <iostream>
3 namespace g2o {
4  namespace internal {
5  using namespace std;
6 
8 
9  int _q2m(double& S, double& qw, const double& r00 , const double& r10 , const double& r20 , const double& r01 , const double& r11 , const double& r21 , const double& r02 , const double& r12 , const double& r22 ){
10  double tr=r00 + r11 + r22;
11  if (tr > 0) {
12  S = sqrt(tr + 1.0) * 2; // S=4*qw
13  qw = 0.25 * S;
14  // qx = (r21 - r12) / S;
15  // qy = (r02 - r20) / S;
16  // qz = (r10 - r01) / S;
17  return 0;
18  } else if ((r00 > r11)&(r00 > r22)) {
19  S = sqrt(1.0 + r00 - r11 - r22) * 2; // S=4*qx
20  qw = (r21 - r12) / S;
21  // qx = 0.25 * S;
22  // qy = (r01 + r10) / S;
23  // qz = (r02 + r20) / S;
24  return 1;
25  } else if (r11 > r22) {
26  S = sqrt(1.0 + r11 - r00 - r22) * 2; // S=4*qy
27  qw = (r02 - r20) / S;
28  // qx = (r01 + r10) / S;
29  // qy = 0.25 * S;
30  // qz = (r12 + r21) / S;
31  return 2;
32  } else {
33  S = sqrt(1.0 + r22 - r00 - r11) * 2; // S=4*qz
34  qw = (r10 - r01) / S;
35  // qx = (r02 + r20) / S;
36  // qy = (r12 + r21) / S;
37  // qz = 0.25 * S;
38  return 3;
39  }
40  }
41 
42  void compute_dq_dR ( Eigen::Matrix<double, 3, 9, Eigen::ColMajor>& dq_dR , const double& r11 , const double& r21 , const double& r31 , const double& r12 , const double& r22 , const double& r32 , const double& r13 , const double& r23 , const double& r33 ){
43  double qw;
44  double S;
45  int whichCase=_q2m( S, qw, r11 , r21 , r31 , r12 , r22 , r32 , r13 , r23 , r33 );
46  S*=.25;
47  switch(whichCase){
48  case 0: compute_dq_dR_w(dq_dR, S, r11 , r21 , r31 , r12 , r22 , r32 , r13 , r23 , r33 );
49  break;
50  case 1: compute_dq_dR_x(dq_dR, S, r11 , r21 , r31 , r12 , r22 , r32 , r13 , r23 , r33 );
51  break;
52  case 2: compute_dq_dR_y(dq_dR, S, r11 , r21 , r31 , r12 , r22 , r32 , r13 , r23 , r33 );
53  break;
54  case 3: compute_dq_dR_z(dq_dR, S, r11 , r21 , r31 , r12 , r22 , r32 , r13 , r23 , r33 );
55  break;
56  }
57  if (qw<=0)
58  dq_dR *= -1;
59  }
60  }
61 }
int _q2m(double &S, double &qw, const double &r00, const double &r10, const double &r20, const double &r01, const double &r11, const double &r21, const double &r02, const double &r12, const double &r22)
Definition: dquat2mat.cpp:9
void compute_dq_dR(Eigen::Matrix< double, 3, 9, Eigen::ColMajor > &dq_dR, const double &r11, const double &r21, const double &r31, const double &r12, const double &r22, const double &r32, const double &r13, const double &r23, const double &r33)
Definition: dquat2mat.cpp:42
void compute_dq_dR_x(Eigen::Matrix< double, 3, 9 > &dq_dR_x, const double &qx, const double &r00, const double &r10, const double &r20, const double &r01, const double &r11, const double &r21, const double &r02, const double &r12, const double &r22)
Definition: dquat2mat.cpp:41
void compute_dq_dR_w(Eigen::Matrix< double, 3, 9 > &dq_dR_w, const double &qw, const double &r00, const double &r10, const double &r20, const double &r01, const double &r11, const double &r21, const double &r02, const double &r12, const double &r22)
Definition: dquat2mat.cpp:2
void compute_dq_dR_z(Eigen::Matrix< double, 3, 9 > &dq_dR_z, const double &qz, const double &r00, const double &r10, const double &r20, const double &r01, const double &r11, const double &r21, const double &r02, const double &r12, const double &r22)
Definition: dquat2mat.cpp:125
void compute_dq_dR_y(Eigen::Matrix< double, 3, 9 > &dq_dR_y, const double &qy, const double &r00, const double &r10, const double &r20, const double &r01, const double &r11, const double &r21, const double &r02, const double &r12, const double &r22)
Definition: dquat2mat.cpp:83