# Recommended open source library: TransForms3d_Cpp

Hello, everyone, I am xiaozhi, the recent shenzhen weather is very strange, sunny and rainy, now everywhere to take an umbrella. Yesterday I was going to do a tutorial on running Gazebo on a graphics card today, so let’s have dessert first and save the good food for later.

Today I recommend an open source library, small wisdom is currently using a library, personally think it is very easy to use ha (because this library is small wisdom wrote, ha ha ha), if you are doing engineering can be used, small wisdom will use it to the actual robot project development, or very comfortable.

Open source Gitee: gitee.com/ohhuo/trans… Open source Gitee: github.com/aiotrobot/t…

## I. Introduction and installation

• Based on Eigen library, some common transformations are encapsulated
• Realize the transformation of euler Angle and rotation matrix, and the transformation of Euler Angle to quaternion
• Realize quaternion and rotation matrix conversion, quaternion to euler Angle conversion
• Through homogeneous matrix synthesis and partial conversion

### 1. Source code introduction

TransForms. CPP and TransForms. H to your project

### 2. Compile and install

``````git clone https://gitee.com/ohhuo/transforms3d_cpp.git
cd transforms3d_cpp
mkdir build
cd build
cmake ..
make
sudo make install
sudo ldconfig
Copy the code``````

## 2. Function list

### 1. Basics

#### 1.1 Angle Conversion

``/** * @description: Static double Degrees(double Angle); static double Degrees(double Angle); static double Degrees(double Angle);Copy the code``
``/** * @description: * @param {double} degrees * @return {double} degrees */ static double Angle(double degree);Copy the code``

#### 1.2 Euler Angle part

##### Euler’s angular rotation matrix
``/** * @description: Angle of euler Angle rotation matrix, this function is the rotation of the default sequence x - y - z. * @ param {double} rx around the rotation of the x axis. * @ param {double} ry around y axis rotation. * @ param {double} rz around the z axis rotation. * @return {Matrix3d} Returns 3 * 3 * rotation matrix. */ static Matrix3d EulerAngle2Mat(double rx, double ry, double rz);Copy the code``
##### Euler’s angular rotation matrix
``/** * @description: * @param {Vector3d} eular Euler Angle rx,ry,rz * @return {Matrix3d} Returns a 3 * 3 rotation matrix. */ static Matrix3d EulerAngle2Mat(Vector3d eular);Copy the code``
##### Euler Angle rotation quaternion
``/ * * * @ description: euler Angle turn quaternion * @ param {double} rx around the rotation of the x axis * @ param {double} ry around y axis rotation * @ param {double} rz around the z axis rotation * @ the return */ Static Quaterniond Euler2Quat(double rx, double ry, double rz);Copy the code``
##### Angle system euler angular rotation quaternion
``/** * @description: Turn Angle of euler Angle quaternion * @ param {double} rx around the rotation of the x axis * @ param {double} ry around y axis rotation * @ param {double} rz around the z axis rotation * @ return {Quaterniond} Return the corresponding Quaterniond */ Static Quaterniond EulerAngle2Quat(double rx, double ry, double rz);Copy the code``
##### Rotation matrix to Euler Angle (in radians)
``/** * @description: Rotation matrix Euler Angle (radians) * @param {Matrix3d} 3 * 3 Rotation matrix * @return {Vector3d} Euler Angle */ static Vector3d Mat2Euler(Matrix3d mat);Copy the code``
##### Euler’s angular rotation matrix
``/** * @description: Turn euler Angle of rotation matrix * @ param {double} rx around the rotation of the x axis * @ param {double} ry around y axis rotation * @ param {double} rz around the z axis rotation * @ return} {* * / static Matrix3d Euler2Mat(double rx, double ry, double rz);Copy the code``
##### The rotation matrix rotation Angle is euler Angle
``/** * @description: * @param {Matrix3d} 3 * 3 * Rotation matrix * @return {Vector3d} Eulerangle */ static Vector3d Mat2EulerAngle(Matrix3d mat);Copy the code``

#### 1.3 The quaternion part

##### Quaternion rotation matrix
``/** * @description: @param {Quaterniond} @return {Matrix3d} | / static Matrix3d Quat2Mat(Quaterniond quat);Copy the code``
##### Quaternion to Euler Angle
``/** * @description: * @param {Quaterniond} Quaterniond * @return {Vector3d} Corresponding to the Euler Angle */ Static Vector3d Quat2Eular(Quaterniond Quat);Copy the code``
``/** * @description: Quaternion radian Euler Angle(Angle) * @param {Quaterniond} quaternion * @return {Vector3d} Corresponding To The Euler Angle */ Static Vector3d Quat2EularAngle(Vecniond) quat);Copy the code``
``/** * @description: * @param {Matrix3d} 3 * 3 rotation matrix * @return {Quaterniond} Corresponding Quaterniond */ static Quaterniond Mat2Quat(Matrix3d mat);Copy the code``

#### 1.4 Part of homogeneous matrix

##### Synthesizes a homogeneous matrix by position and Euler Angle
``/** * @description: Synthesize a homogenous matrix by position and Euler Angle * @param {Vector3d} Positon translation position * @param {Vector3d} rotEular rotation transformation (Euler form) * @return {*} */ static Matrix4d Compose(Vector3d positon, Vector3d rotEular);Copy the code``
##### Synthesizes a homogeneous matrix by position and quaternion
``/** * @description: @param {Vector3d} positon shift position * @param {Quaterniond} quat quaternion * @return {Matrix4d} homogeneous matrix */ static Matrix4d Compose(Vector3d positon, Quaterniond quat);Copy the code``
##### We synthesize a homogeneous matrix with three positions and three Euler angles
``/** * @description: @param {double} @param {double} @param {double} @param {double} @param {double} @param {double} @param {double} @param {double} @param {double} @param {double} @param {double} @param {double} @param {double} @param {double} @param {double} @param {double} @param {double} Rotation rx around x * @param {double} ry around y * @param {double} rz around z * @return {Matrix4d} Returns 4 * 4 * static Matrix4d ComposeEuler(double x, double y, double z, double rx, double ry, double rz);Copy the code``
##### The homogeneous matrix is transformed into translation and Euler Angle form, which is easy to understand
``/** * @description: To convert the homogeneous matrix into translation and Euler Angle form, * @param {Matrix4d} 4 * 4 * VectorXd * @return {VectorXd} x,y,z,rx,ry,rz */ static VectorXd H2EulerAngle(Matrix4d t);Copy the code``

This article is a bit long, and the most important part is not highlighted. I will update it in the next issue. By the way, I like the python version better than the long and complicated syntax of c++

Finally, welcome everyone to pay attention to xiaozhi’s wechat public number (wit), Xiaozhi will continue to update ~