[C++] Quaternion to Euler ๋ณํ
Quaternion๊ณผ Euler(roll, pitch, yaw)์ ์ํธ ๋ณํ ํด๋ณด์
๊ฐ์
์ขํ๊ณ๋ฅผ ๋ค๋ฃจ๋ค ๋ณด๋ฉด ํด๋น ๊ฐ๋ ํํ์ ๋ง์ด ์ฌ์ฉํ๊ฒ ๋๋ค.
์์ฃผ ์ฌ์ฉํ๋๋ฐ๋ ํท๊ฐ๋ ค์ ๋ธ๋ก๊ทธ์ ๊ธฐ๋กํด๋๋ค.
Quaternion โ> Euler
#include <tf/tf.h>
// input : ์ฟผํฐ๋์ธ(quat)
tf::Quaternion q( quat.x, quat.y, quat.z, quat.w);
tf::Matrix3x3 m(q);
double roll, pitch, yaw;
m.getRPY(roll, pitch, yaw);
std::cout << "roll : " << roll << std::endl;
std::cout << "pitch : " << pitch << std::endl;
std::cout << "yaw : " << yaw << std::endl;
Euler โ> Quaternion
#include <tf2/LinearMath/Quaternion.h>
// input : ์ค์ผ๋ฌ ๊ฐ(roll, pitch, yaw)
tf2::Quaternion quat;
quat.setRPY(roll, pitch, yaw);
quat.normalize();
std::cout << "quat.w : " << quat.getW() << std::endl;
std::cout << "quat.x : " << quat.getX() << std::endl;
std::cout << "quat.y : " << quat.getY() << std::endl;
std::cout << "quat.z : " << quat.getZ() << std::endl;
Leave a comment