Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

C # how to realize the conversion between Euler angle and quaternion

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Editor to share with you how to achieve the conversion between Euler angle and quaternion, I believe that most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article. Let's learn about it.

/ / Euler Angle to Quaternion

Void cjx_from_euler (float roll, float pitch, float yaw)

{

Float cr2 = cosf (roll*0.5f)

Float cp2 = cosf (pitch*0.5f)

Float cy2 = cosf (yaw*0.5f)

Float sr2 = sinf (roll*0.5f)

Float sp2 = sinf (pitch*0.5f)

Float sy2 = sinf (yaw*0.5f)

Q1 = cr2*cp2*cy2 + sr2*sp2*sy2

Q2 = sr2*cp2*cy2-cr2*sp2*sy2

Q3 = cr2*sp2*cy2 + sr2*cp2*sy2

Q4 = cr2*cp2*sy2-sr2*sp2*cy2

}

# define RAD_TO_DEG 57.29577951f

/ / Radian to angle

Float degrees (float rad)

{

Return rad * RAD_TO_DEG

}

/ / Quaternion to Euler angle

Void cjx_to_euler (float * roll, float * pitch, float * yaw)

{

If (roll) {

* roll = degrees (atan2f (2.0f* (q1*q2 + q3*q4), 1-2.0f* (q2*q2 + q3*q3)

}

If (pitch) {

/ / use safe_asin () to deal with the singularity when pitch is close to 90-90.

* pitch = degrees (safe_asin (2.0f * (q1*q3-q2*q4)

}

If (yaw) {

* yaw = degrees (atan2f (2.0f* (q2*q3-q1*q4), 2.0f* (q1*q1 + q2*q2)-1))

}

}

These are all the contents of the article "how to convert Euler Angle to Quaternion". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report