# VelocityOrientationProperty with "manual" pitch roll

**URL:** <https://community.cesium.com/t/velocityorientationproperty-with-manual-pitch-roll/7912>\
**Category:** CesiumJS\
**Created:** [January 18, 2019, 6:10pm UTC](https://community.cesium.com/t/velocityorientationproperty-with-manual-pitch-roll/7912 "2019-01-18T18:10:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Niklas\_B](https://avatars.discourse-cdn.com/v4/letter/n/ba9def/32.png) [@Niklas\_B](https://community.cesium.com/u/Niklas_B)\
**Post date:** [January 18, 2019, 6:10pm UTC](https://community.cesium.com/t/velocityorientationproperty-with-manual-pitch-roll/7912/1 "2019-01-18T18:10:25Z")

</div>

Hi,

I'm animating a model based on recorded data, using lat/lon, altitude and heading/pitch/roll. The model is animated along a path. This works well, but then I have a case where the heading is faulty and I'm trying to correct it. I'm trying to use heading from VelocityOrientationProperty but with my own pitch and roll.

This is not a bug in Cesium, I just can't figure out the math.

I think I'm confusing my units, since I can't get even get this working:

&nbsp;&nbsp;let q = orientation\_velocity.getValue(time);  
&nbsp;&nbsp;let velocity\_hpr = Cesium.HeadingPitchRoll.fromQuaternion(q);  
&nbsp;&nbsp;let orientation = Cesium.Transforms.headingPitchRollQuaternion(  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;posSamples.getValue(time),  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;velocity\_hpr  
&nbsp;&nbsp;);  
&nbsp;&nbsp;orientationSamples.addSample(time, orientation);

If I convert a Quaternion to a HeadingPitchRoll, then convert HPR to a Quaternion (using the same position) shouldn't it work? Obviously it's fictitious example, but if I can't even get that to work.. the above sample gives me the same odd behaviour as TRY #2 below, i.e the forward tip of the model points upwards.

Longer Story:  
When I have a working heading (these are executed in a for loop):

&nbsp;&nbsp;let hpRoll = new Cesium.HeadingPitchRoll(  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Cesium.Math.toRadians(data['HEADING'][i]),  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Cesium.Math.toRadians(data['PITCH'][i]),  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Cesium.Math.toRadians(data['BANK'][i]),  
&nbsp;&nbsp;);  
&nbsp;&nbsp;let orientation = Cesium.Transforms.headingPitchRollQuaternion(  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;positions[i], // position  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hpRoll,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Cesium.Ellipsoid.WGS84,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Cesium.Transforms.northWestUpToFixedFrame,  
&nbsp;&nbsp;);  
&nbsp;&nbsp;orientationSamples.addSample(time, orientation);

I can also use the VelocityOrientationProperty:

TRY #1:  
&nbsp;&nbsp;orientation\_velocity = new Cesium.VelocityOrientationProperty(posSamples);

Gives a perfect heading along the path, but obviously without PITCH/ROLL.

However, now I'm trying to use heading from VelocityOrientationProperty but my own PITCH and BANK.

TRY #2 (TLDR: 90 degrees (forward tip of the model points upwards)  
&nbsp;&nbsp;let q = orientation\_velocity.getValue(time);  
&nbsp;&nbsp;let velocity\_hpr = Cesium.HeadingPitchRoll.fromQuaternion(q);

&nbsp;&nbsp;let hpRoll = new Cesium.HeadingPitchRoll(  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Cesium.Math.toRadians(data['HEADING'][i]),  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Cesium.Math.toRadians(data['PITCH'][i]),  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Cesium.Math.toRadians(data['BANK'][i])  
&nbsp;&nbsp;);

&nbsp;&nbsp;// Replace pitch and roll from VelocityOrientationProperty Quaternion  
&nbsp;&nbsp;hpRoll['pitch'] = velocity\_hpr['pitch']  
&nbsp;&nbsp;hpRoll['roll'] = velocity\_hpr['roll']

&nbsp;&nbsp;let orientation = Cesium.Transforms.headingPitchRollQuaternion(  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;posSamples.getValue(time),  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hpRoll,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Cesium.Ellipsoid.WGS84,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Cesium.Transforms.northWestUpToFixedFrame,  
&nbsp;&nbsp;);

This creates a model where the front of the model points pretty much straight up and not forward.

TRY #3: (TLDR: Doesn't point straight forwards, rotates 180 degrees randomly when turning)  
&nbsp;&nbsp;let q = orientation\_velocity.getValue(time);  
&nbsp;&nbsp;let velocity\_hpr = Cesium.HeadingPitchRoll.fromQuaternion(q);  
&nbsp;&nbsp;let heading = Cesium.Math.toDegrees(velocity\_hpr['heading']);

&nbsp;&nbsp;let hpRoll = new Cesium.HeadingPitchRoll(  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;velocity\_hpr['heading'],  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Cesium.Math.toRadians(data['PITCH'][i]),  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Cesium.Math.toRadians(data['BANK'][i])  
&nbsp;&nbsp;);  
&nbsp;&nbsp;let orientation = Cesium.Transforms.headingPitchRollQuaternion(  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;positions[i], // position  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hpRoll,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Cesium.Ellipsoid.WGS84,  
&nbsp;&nbsp;);  
&nbsp;&nbsp;orientationSamples.addSample(time, orientation);

---

<div class="post-metadata">

**Author:** ![Niklas\_B](https://avatars.discourse-cdn.com/v4/letter/n/ba9def/32.png) [@Niklas\_B](https://community.cesium.com/u/Niklas_B)\
**Post date:** [January 21, 2019, 8:36am UTC](https://community.cesium.com/t/velocityorientationproperty-with-manual-pitch-roll/7912/2 "2019-01-21T08:36:10Z")

</div>

Hi,

I hope I'm not breaking any forum rules here, but I would like to offer a gratitude reward (150USD) if anyone can solve this within 12 hours.

Regards,  
Niklas
