For my Cesium App (paragliding simulator online) I am searching a way to know the precise sun position in the sky, in terms of orientation and elevation on the horizon, knowing a position on the earth and an UTC time.
I know that there are very complicated formulas to do that… but since Cesium Engine have the capability to draw the sun in the sky… i thought that it had just done the “dirty job” :D… there is a way to retrieve those informations?
but i can’t understand how exactly… can somebody provide me an example?
serching in the source code i found also this : “viewer.scene.context.uniformState.sunPositionWC”… but similar to the other function (Simon1994PlanetaryPositions.computeSunPositionInEarthInertialFrame) this returns 3 numbers than i am not able to understand…
Cesium does indeed compute and draw the sun where it should be depending on the time. It looks like you found the function we use to do Simon1994PlanetaryPositions.computeSunPositionInEarthInertialFrame. That function takes a JulianDate as the input and returns a Cartesian3 for the sun’s position.
You will have to do your own calculations to figure out the orientation and elevation from a position on the earth surface.
Has any function been added since 2016 to know azimuth and altitude of Sun and Moon?
I have this function to calculate elevation of a point w.r.t.another but it does not work:
function getElevation(startPoint, endPoint) {
// Return elevation in degree of endPoint w.r.t. startPoint
// https://community.cesium.com/t/calculate-elevation-angle-between-two-points/5629/5
// https://sandcastle.cesium.com/?src=Hello%20World.html&label=Showcases&gist=d917ac40dfb225cb9899a84403b0c719
// startPoint = new Cesium.Cartesian3.fromDegrees(12.636018, 41.995557, 167); (lon, lat, alt)
// endPoint = new Cesium.Cartesian3.fromDegrees(12.801439, 42.058937, 1181); (lon, lat, alt)
//Obtain vector by taking difference of the end points
var scratch1= new Cesium.Cartesian3();
var difference = Cesium.Cartesian3.subtract(endPoint, startPoint, scratch1);
difference = Cesium.Cartesian3.normalize(difference, scratch1);
//console.log("Difference: " + difference);
//Obtain surface normal by normalizing the starting point position
var scratch2 = new Cesium.Cartesian3();
var surfaceNormal = Cesium.Cartesian3.normalize(startPoint, scratch2);
//console.log("Surface normal: " + surfaceNormal);
//Take the dot product of your given vector and the surface normal
var dotProduct = Cesium.Cartesian3.dot(difference, surfaceNormal);
//console.log("Dot product: " + dotProduct);
//Arcos the result
var angle = 90 - Math.acos(dotProduct) * Cesium.Math.DEGREES_PER_RADIAN ;
//console.log("Result: " + angle);
return angle;
}
Thank you for sharing this function with the community! To the best of my knowledge, we haven’t yet added this feature. I will check in with the rest of the development team and get back to you if there are any updates