If I rotate a vector then rotate it back again I don’t seem to to get back to the same value.
I extracted a minimal reproduction of this issue in this PG.
Note that this PG just outputs to the console log, so you need to open the dev tools to see the output. The code transforms a vector to spherical coordinates and back again, but the final value is not the same as the original value.
The reason that I think the vector rotation is the issue, is because if you swap these two lines:
const forwardQuaternion = BABYLON.Quaternion.FromEulerAngles(-1.445, 0, Math.PI / 2); const reverseQuaternion = BABYLON.Quaternion.FromEulerAngles(1.445, 0, -Math.PI / 2);
with these two lines:
const forwardQuaternion = BABYLON.Quaternion.FromEulerAngles(0, 0, 0); const reverseQuaternion = BABYLON.Quaternion.FromEulerAngles(0, 0, 0);
then the conversion to and from spherical coordinates round trips correctly and the final values match the original ones.
I am not listing this as a bug, just trying to understand why this doesn’t work the way I expected, and trying to find a solution to this problem.