# These two functions should not be inverse or converted to each other, but the test results are not like this

**URL:** <https://community.cesium.com/t/these-two-functions-should-not-be-inverse-or-converted-to-each-other-but-the-test-results-are-not-like-this/33549>\
**Category:** CesiumJS\
**Created:** [July 5, 2024, 3:12am UTC](https://community.cesium.com/t/these-two-functions-should-not-be-inverse-or-converted-to-each-other-but-the-test-results-are-not-like-this/33549 "2024-07-05T03:12:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![shengqin\_guo](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/shengqin_guo/32/14581_2.png) [@shengqin\_guo](https://community.cesium.com/u/shengqin_guo)\
**Post date:** [July 5, 2024, 3:12am UTC](https://community.cesium.com/t/these-two-functions-should-not-be-inverse-or-converted-to-each-other-but-the-test-results-are-not-like-this/33549/1 "2024-07-05T03:12:48Z")

</div>

// 创建一个 HeadingPitchRoll 实例  
var originalHPR = new Cesium.HeadingPitchRoll(  
6.283185307179586, // heading  
-0.5000392228306918, // pitch  
6.283185307179586 // roll  
);

// 将 HeadingPitchRoll 转换为 Quaternion  
var quaternion = Cesium.Quaternion.fromHeadingPitchRoll(originalHPR);

// 再将 Quaternion 转换回 HeadingPitchRoll  
var convertedHPR = Cesium.HeadingPitchRoll.fromQuaternion(quaternion);

// 输出原始和转换后的值  
console.log(‘Original HPR:’, originalHPR);  
console.log(‘Converted HPR:’, convertedHPR);

// 检查是否接近原始值  
console.log(‘Heading match:’, Cesium.Math.equalsEpsilon(originalHPR.heading, convertedHPR.heading, Cesium.Math.EPSILON14));  
console.log(‘Pitch match:’, Cesium.Math.equalsEpsilon(originalHPR.pitch, convertedHPR.pitch, Cesium.Math.EPSILON14));  
console.log(‘Roll match:’, Cesium.Math.equalsEpsilon(originalHPR.roll, convertedHPR.roll, Cesium.Math.EPSILON14));

---

<div class="post-metadata">

**Author:** ![anneg](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/anneg/32/11217_2.png) [@anneg](https://community.cesium.com/u/anneg)\
**Post date:** [July 5, 2024, 9:39am UTC](https://community.cesium.com/t/these-two-functions-should-not-be-inverse-or-converted-to-each-other-but-the-test-results-are-not-like-this/33549/2 "2024-07-05T09:39:25Z")

</div>

This is a combination of 360° = 0° and floating precision issues.

The original heading is 6.283185307179586, which is 360°.  
The converted heading is -2.4492935982947064e-16, a very small number, very close to 0°.
