I also noticed that when trying to come up with the answer in the other thread. Here is a sandcastle where I inserted the relevant coordinate system axes (red, green and blue) for debugging:
It can be seen that the alignment is just a little off:
But I haven’t found the reason (or a solution) for that yet.
Maybe someone from the CesiumJS core team can have a look or has an idea here. For those who want to take a look: Here is a simplified sandcastle
It has comments, sensible variable names, and focusses on the actual question, which might make it easier to find a solution.
1 Like
Thanks for simplifying the problem. I hope CesiumJS core team can help us as well.
Thanks @sean_lilley for the solution: The computation of the angle between the (local) y-Axis of the plane and the UNIT_Z axis was wrong. It should have been the angle between the y-Axis and the projection of the UNIT_Z axis on the plane.
Here is the simplified sandcastle, with this change being applied:
The result is indeed the plane being properly aligned with the horizon:
The computation of the orientation is commented, and it should be possible to apply that more or less directly to the Sandcastle that you posted, near the line
const angle1 = Cesium.Cartesian3.angleBetween(ellipsoidNormal, Cesium.Cartesian3.UNIT_Z);
I did a quick check by inserting this solution in your Sandcastle here:
… but there are some computations that could be omitted now, or simplified, or optimized, or moved into own function - this is only to show that this should solve the issue in general.
1 Like