rotation-in-angles.cpp
Go to the documentation of this file.
1 
4 #include "calibration-types.h"
5 #include <cmath>
6 #include <cstdlib>
7 #include <stdexcept>
8 #include <sstream>
9 #include <iomanip>
10 
11 
12 namespace librealsense {
13 namespace algo {
14 namespace depth_to_rgb_calibration {
15 
16 
18  {
20 
21  auto sin_a = sin( rot_angles.alpha );
22  auto sin_b = sin( rot_angles.beta );
23  auto sin_g = sin( rot_angles.gamma );
24 
25  auto cos_a = cos( rot_angles.alpha );
26  auto cos_b = cos( rot_angles.beta );
27  auto cos_g = cos( rot_angles.gamma );
28 
29  //% function [R] = calcRmatRromAngs(xAlpha,yBeta,zGamma)
30  //% R = [cos( yBeta )*cos( zGamma ), -cos( yBeta )*sin( zGamma ), sin( yBeta ); ...
31  //% cos( xAlpha )*sin( zGamma ) + cos( zGamma )*sin( xAlpha )*sin( yBeta ), cos( xAlpha )*cos( zGamma ) - sin( xAlpha )*sin( yBeta )*sin( zGamma ), -cos( yBeta )*sin( xAlpha ); ...
32  //% sin( xAlpha )*sin( zGamma ) - cos( xAlpha )*cos( zGamma )*sin( yBeta ), cos( zGamma )*sin( xAlpha ) + cos( xAlpha )*sin( yBeta )*sin( zGamma ), cos( xAlpha )*cos( yBeta )];
33  //% end
34  // -> note the transposing of the coordinates
35 
36  res.rot[0] = cos_b * cos_g;
37  res.rot[3] = -cos_b * sin_g;
38  res.rot[6] = sin_b;
39  res.rot[1] = cos_a * sin_g + cos_g * sin_a*sin_b;
40  res.rot[4] = cos_a * cos_g - sin_a * sin_b*sin_g;
41  res.rot[7] = -cos_b * sin_a;
42  res.rot[2] = sin_a * sin_g - cos_a * cos_g*sin_b;
43  res.rot[5] = cos_g * sin_a + cos_a * sin_b*sin_g;
44  res.rot[8] = cos_a * cos_b;
45 
46  return res;
47  }
48 
49 #if 0
50  double determinant( double const r[9] )
51  {
52  // |A| = aei + bfg + cdh - ceg - bdi - afh
53  return r[0] * r[4] * r[8] // aei
54  + r[1] * r[5] * r[6] // bfg
55  + r[2] * r[3] * r[7] // cdh
56  - r[2] * r[4] * r[6] // ceg
57  - r[1] * r[3] * r[8] // bdi
58  - r[0] * r[5] * r[7]; // afh
59  }
60 
61  rotation inverse( rotation const & r )
62  {
63 
64  }
65 
66  inline double3 operator*( const rotation & a, const rotation & b ) { return { dot( a.x,b ), dot( a.y,b ), dot( a.z,b ) }; }
67  inline rotation operator*( const rotation & a, const rotation & b )
68  {
69  return{ a*b.x, a*b.y, a*b.z };
70  }
71 #endif
72 
74  {
76  //% function [xAlpha,yBeta,zGamma] = extractAnglesFromRotMat(R)
77  //% xAlpha = atan2(-R(2,3),R(3,3));
78  //% yBeta = asin(R(1,3));
79  //% zGamma = atan2(-R(1,2),R(1,1));
80  // -> we transpose the coordinates!
81  res.alpha = atan2( -r[7], r[8] );
82  res.beta = asin( r[6] );
83  res.gamma = atan2( -r[3], r[0] );
84  // -> additional code is in the original function that catches some corner
85  // case, but since these have never occurred we were told not to use it
86 
87 #if 0
88  // TODO Sanity-check: can be removed
90  double const epsilon = 1e-8;
91  if( determinant( rot * inverse(r) - I ) > epsilon )
92  {
93  std::ostringstream ss;
94  ss << std::setprecision( 15 );
95  ss << "angles_from_rotation != rotation_from_angles!";
96  ss << "\n " << r[0] << " " << r[1] << " " << r[2]
97  << "\n " << r[3] << " " << r[4] << " " << r[5]
98  << "\n " << r[6] << " " << r[7] << " " << r[8];
99  ss << "\nvs:"
100  << "\n " << rot.rot[0] << " " << rot.rot[1] << " " << rot.rot[2]
101  << "\n " << rot.rot[3] << " " << rot.rot[4] << " " << rot.rot[5]
102  << "\n " << rot.rot[6] << " " << rot.rot[7] << " " << rot.rot[8];
103  ss << "\nangles:"
104  << "\n alpha= " << res.alpha
105  << "\n beta = " << res.beta
106  << "\n gamma= " << res.gamma;
107  ss << "\nsum= " << sum;
108  throw std::runtime_error( ss.str() );
109  }
110 #endif
111  return res;
112  }
113 
114 
115 }
116 }
117 }
rotation_in_angles extract_angles_from_rotation(const double r[9])
GLboolean GLboolean GLboolean b
float determinant(float3x3 const &r)
Definition: test-pose.cpp:116
float3 operator*(const float3 &a, float b)
Definition: src/types.h:581
e
Definition: rmse.py:177
GLboolean GLboolean GLboolean GLboolean a
GLdouble GLdouble r
float dot(float3 const &a, float3 const &b)
Definition: test-pose.cpp:74
GLuint res
Definition: glext.h:8856
matrix_3x3 extract_rotation_from_angles(const rotation_in_angles &rot_angles)


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:40