1 #ifndef TUW_GEOMETRY_UTILS 2 #define TUW_GEOMETRY_UTILS 5 #include <opencv2/core/mat.hpp> 6 #include <opencv2/core/matx.hpp> 10 typedef cv::Matx<double, 3, 3>
Tf2D;
19 inline cv::Vec<double, 3>
append (
const cv::Vec<double, 2> &src,
double value = 1.0 )
21 return cv::Vec<double, 3> ( src.val[0], src.val[1], value );
31 inline cv::Vec<double, 4>
append (
const cv::Vec<double, 3> &src,
double value = 1.0 )
33 return cv::Vec<double, 4> ( src.val[0], src.val[1], src.val[2], value );
43 inline double angle_normalize (
double angle,
double min_angle = -M_PI,
double max_angle = +M_PI )
45 while ( angle > max_angle ) {
48 while ( angle < min_angle ) {
61 return atan2 ( sin ( alpha0-angle1 ), cos ( alpha0-angle1 ) );
68 template <
typename Quaternion>
71 double cp = cos ( pitch * 0.5 );
72 double sp = sin ( pitch * 0.5 );
85 template <
typename Quaternion>
88 double cr = cos ( roll * 0.5 );
89 double sr = sin ( roll * 0.5 );
101 template <
typename Quaternion>
104 double cy = cos ( yaw * 0.5 );
105 double sy = sin ( yaw * 0.5 );
117 template <
typename Quaternion>
120 double cy = cos ( yaw * 0.5 );
121 double sy = sin ( yaw * 0.5 );
122 double cr = cos ( roll * 0.5 );
123 double sr = sin ( roll * 0.5 );
124 double cp = cos ( pitch * 0.5 );
125 double sp = sin ( pitch * 0.5 );
127 q.w = cy * cr * cp + sy * sr * sp;
128 q.x = cy * sr * cp - sy * cr * sp;
129 q.y = cy * cr * sp + sy * sr * cp;
130 q.z = sy * cr * cp - cy * sr * sp;
138 template <
typename Quaternion>
142 double sinr = +2.0 * ( q.w * q.x + q.y * q.z );
143 double cosr = +1.0 - 2.0 * ( q.x * q.x + q.y * q.y );
144 roll = atan2 ( sinr, cosr );
150 template <
typename Quaternion>
154 double sinp = +2.0 * ( q.w * q.y - q.z * q.x );
155 if ( fabs ( sinp ) >= 1 ) {
156 pitch = copysign ( M_PI / 2, sinp );
158 pitch = asin ( sinp );
165 template <
typename Quaternion>
169 double siny = +2.0 * ( q.w * q.z + q.x * q.y );
170 double cosy = +1.0 - 2.0 * ( q.y * q.y + q.z * q.z );
171 yaw = atan2 ( siny, cosy );
178 template <
typename Quaternion>
184 std::string
format (
const cv::Mat_<int8_t> &m );
185 std::string
format (
const cv::Mat_<int> &m );
186 std::string
format (
const cv::Mat_<float> &m );
187 std::string
format (
const cv::Mat_<double> &m );
188 std::string
format (
const cv::Matx33d &m );
191 #endif // TUW_GEOMETRY_UTILS double angle_normalize(double angle, double min_angle=-M_PI, double max_angle=+M_PI)
void QuaternionToYaw(const Quaternion &q, double &yaw)
cv::Vec< double, 3 > append(const cv::Vec< double, 2 > &src, double value=1.0)
void QuaternionToRoll(const Quaternion &q, double &roll)
void QuaternionToEuler(const Quaternion &q, double &roll, double &pitch, double &yaw)
void QuaternionToPitch(const Quaternion &q, double &pitch)
void EulerYawToQuaternion(double yaw, Quaternion &q)
double angle_difference(double alpha0, double angle1)
void EulerToQuaternion(double roll, const Quaternion &q)
cv::Matx< double, 3, 3 > Tf2D
std::string format(const cv::Mat_< int8_t > &m)
void EulerPitchToQuaternion(double pitch, Quaternion &q)