Skip to content

Commit 0c9b43f

Browse files
committed
added rotation.hpp
1 parent 5bf5fa2 commit 0c9b43f

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

include/rotation.hpp

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#ifndef __DSO_GEODESY_ROTATIONS_HPP__
2+
#define __DSO_GEODESY_ROTATIONS_HPP__
3+
4+
#include <cmath>
5+
#include "eigen3/Eigen/Eigen"
6+
7+
namespace dso {
8+
/** @brief Compare 3x3 rotation matrices.
9+
*
10+
* Let P and Q be orthogonal matrices representing two rotations in the same
11+
* basis. Let Q^T denote the matrix transpose. The difference rotation
12+
* matrix that represents the difference rotation is defined as:
13+
* R = P * Q^T
14+
* The distance between rotations represented by rotation matrices P and Q
15+
* is the angle of the difference rotation represented by the rotation
16+
* matrix R.
17+
* We can retrieve the angle of the difference rotation from the trace of R
18+
* trR = 1 + 2 * cosθ
19+
* or
20+
* θ = acos( (trR - 1) / 2 )
21+
*
22+
* @param[in] P Rotation matrix of size 3x3
23+
* @param[in] Q Rotation matrix of size 3x3
24+
* @return The angle theta in [rad] defined as:
25+
* θ = acos( (trR - 1) / 2 ), with R = P * Q^T
26+
*/
27+
inline double rotation_distance(const Eigen::Matrix<double, 3, 3> &P,
28+
const Eigen::Matrix<double, 3, 3> &Q) noexcept {
29+
return std::acos((P * Q.transpose()).trace() / 2e0);
30+
}
31+
} /* namespace dso */
32+
33+
#endif

0 commit comments

Comments
 (0)