Thanks for your time, but it does not work.
Here the full code I’m using.
function createHPRFromDegrees(h,p,r){
//arguments are in degree
this.h = warpTo360(h);
this.p = warpTo360§;
this.r = warpTo360®;
return Cesium.HeadingPitchRoll.fromDegrees(this.h,this.p,this.r, new Cesium.HeadingPitchRoll());
}
function warpTo360(degree){
if(!degree || isNaN(degree)){
return 0;
}
var result = degree;
result = result % 360;
if(result === 0){
//just for handling ‘-0’
return 0;
}
else if(result < 0) {
return (result + 360);
} else {
return result;
}
}
function calcAngleBetweenHeadingPitchRolls(hpr1, hpr2){
if(!(hpr1 instanceof Cesium.HeadingPitchRoll) || !(hpr2 instanceof Cesium.HeadingPitchRoll)){
throw “Invalid input”;
}
var q1 = Cesium.Quaternion.fromHeadingPitchRoll(hpr1,new Cesium.Quaternion());
var q2 = Cesium.Quaternion.fromHeadingPitchRoll(hpr2,new Cesium.Quaternion());
console.log(q1);
console.log(q2);
if(q1.equals(q2)){
return 0;
}
var qDiff = Cesium.Quaternion.subtract(q2, q1, new Cesium.Quaternion());
console.log(qDiff);
var diffAngleRadians = Cesium.Quaternion.computeAngle(qDiff);
console.log("diffAngleRad: " + diffAngleRadians);
console.log("diffAngleDeg: " + Cesium.Math.toDegrees(diffAngleRadians));
return diffAngleRadians;
}
``
If use it like the following it sholud give me 10 degree but returning 180 degree
var camHPR = createHPRFromDegrees(15,0,0);
var imgHPR = createHPRFromDegrees(5,0,0);
calcAngleBetweenHeadingPitchRolls(camHPR, imgHPR);
diffAngleRad: 3.1263857866503817
diffAngleDeg: 179.1287107047547
``