# Sun position and elevation

**URL:** <https://community.cesium.com/t/sun-position-and-elevation/3967>\
**Category:** CesiumJS\
**Created:** [April 8, 2016, 8:49am UTC](https://community.cesium.com/t/sun-position-and-elevation/3967 "2016-04-08T08:49:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![RikM](https://avatars.discourse-cdn.com/v4/letter/r/9dc877/32.png) [@RikM](https://community.cesium.com/u/RikM)\
**Post date:** [April 8, 2016, 8:49am UTC](https://community.cesium.com/t/sun-position-and-elevation/3967/1 "2016-04-08T08:49:30Z")

</div>

Hello everybody! 🙂

For my Cesium App ([paragliding simulator online](http://paraglidinglogbook.com/simulator)) 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?

Thank you!

---

<div class="post-metadata">

**Author:** ![RikM](https://avatars.discourse-cdn.com/v4/letter/r/9dc877/32.png) [@RikM](https://community.cesium.com/u/RikM)\
**Post date:** [April 8, 2016, 11:45am UTC](https://community.cesium.com/t/sun-position-and-elevation/3967/2 "2016-04-08T11:45:57Z")

</div>

some time ago somebody suggested to me to use this functions :  
**"to get the sun position use [Simon1994PlanetaryPositions.computeSunPositionInEarthInertialFrame](https://www.google.com/url?q=https%3A%2F%2Fcesiumjs.org%2FCesium%2FBuild%2FDocumentation%2FSimon1994PlanetaryPositions.html%23.computeSunPositionInEarthInertialFrame&sa=D&sntz=1&usg=AFQjCNEU1tN1-CRPpKEElqnpRaFcJUhUGA) and [Transforms.computeTemeToPseudoFixedMatrix"](https://www.google.com/url?q=https%3A%2F%2Fcesiumjs.org%2FCesium%2FBuild%2FDocumentation%2FTransforms.html%23.computeTemeToPseudoFixedMatrix&sa=D&sntz=1&usg=AFQjCNE07OBFTfkpAjfdnzbKHRm8j7YkDw)**

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](https://www.google.com/url?q=https%3A%2F%2Fcesiumjs.org%2FCesium%2FBuild%2FDocumentation%2FSimon1994PlanetaryPositions.html%23.computeSunPositionInEarthInertialFrame&sa=D&sntz=1&usg=AFQjCNEU1tN1-CRPpKEElqnpRaFcJUhUGA)) this returns 3 numbers than i am not able to understand…

how to get the sun position elevation in degrees?

---

<div class="post-metadata">

**Author:** ![hannah](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/hannah/32/4509_2.png) [@hannah](https://community.cesium.com/u/hannah)\
**Post date:** [April 11, 2016, 3:27pm UTC](https://community.cesium.com/t/sun-position-and-elevation/3967/3 "2016-04-11T15:27:19Z")

</div>

Hello,

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.

Best,

Hannah

---

<div class="post-metadata">

**Author:** ![jumpjack](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/jumpjack/32/3589_2.png) [@jumpjack](https://community.cesium.com/u/jumpjack)\
**Post date:** [September 4, 2021, 9:41am UTC](https://community.cesium.com/t/sun-position-and-elevation/3967/4 "2021-09-04T09:41:09Z")

</div>

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:

```auto
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;
}

```

---

<div class="post-metadata">

**Author:** ![sam.rothstein](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/sam.rothstein/32/6584_2.png) [@sam.rothstein](https://community.cesium.com/u/sam.rothstein)\
**Post date:** [September 7, 2021, 6:12pm UTC](https://community.cesium.com/t/sun-position-and-elevation/3967/5 "2021-09-07T18:12:42Z")

</div>

@jumpjack

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 🚀 😀

-Sam
