eos 1.4.0
Loading...
Searching...
No Matches
rotation_angles.hpp
1/*
2 * eos - A 3D Morphable Model fitting library written in modern C++11/14.
3 *
4 * File: include/eos/fitting/rotation_angles.hpp
5 *
6 * Copyright 2023 Patrik Huber
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20#pragma once
21
22#ifndef EOS_FITTING_ROTATION_ANGLES_HPP
23#define EOS_FITTING_ROTATION_ANGLES_HPP
24
25#include "eos/core/math.hpp"
26
27#include "Eigen/Core"
28
29#include <cmath>
30
31namespace eos {
32namespace fitting {
33
40template <typename T>
41inline Eigen::Matrix<T, 3, 1> tait_bryan_angles(Eigen::Matrix<T, 3, 3> rotation_matrix, Eigen::Index axis_0,
42 Eigen::Index axis_1, Eigen::Index axis_2)
43{
44 Eigen::Matrix<T, 3, 1> euler_angles = rotation_matrix.eulerAngles(axis_0, axis_1, axis_2);
45 // Eigen::Matrix3X.eulerAngles() returns the solution where the first axis is constrained from 0 to PI.
46 // This is not what we usually want in robotics; we want the other solution (there are two in the general
47 // case) where the middle (pitch) axis is constrained to -PI/2 to PI/2. See
48 // https://gitlab.com/libeigen/eigen/-/issues/2617#note_1298729055
49 if (std::abs(euler_angles(1)) > T(core::pi<T> / 2.0))
50 {
51 euler_angles.array() -= T(core::pi<T>) * euler_angles.array().sign();
52 euler_angles(1) = -euler_angles(1);
53 }
54 return euler_angles;
55};
56
57} /* namespace fitting */
58} /* namespace eos */
59
60#endif /* EOS_FITTING_ROTATION_ANGLES_HPP */
Eigen::Matrix< T, 3, 1 > tait_bryan_angles(Eigen::Matrix< T, 3, 3 > rotation_matrix, Eigen::Index axis_0, Eigen::Index axis_1, Eigen::Index axis_2)
Computes Tait-Bryan angles (in radians) from the given rotation matrix and axes order.
Definition: rotation_angles.hpp:41
Namespace containing all of eos's 3D model fitting functionality.