# Finding the position of the sun

This topic is 4414 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I've been looking into making a small little app which displays a rectilinear map of the world, and overlays on it which parts are in daylight and which are at night.. My solution so far is to put everything into 3D coordinates. I have a function which can convert between lat, long, alt to earth centered coordinates, but getting the absolute position of the sun for any given day/hour/min of the year is a bit tricky... Does anyone know of any resources that would have such a algorithm? I'm using Delphi, so i have found an astronomical calculation unit for delphi which gives a sun position, but unfortunately doesnt take into account the rotation of the earth around its own axis. The accompanying article mentions simply applying a matrix of Sin(t)'s where t is time, but I've been unsuccesful so far (probably due to me not knowing what the hell was going on :P).

##### Share on other sites
The position of the sun wrt the world can quite comfortably be represented in geocentric cartesian coordinates (earth-centred x, y, z) but I think geodetic coordinates (lat, lon, alt) would be preferable.

To determine the position of the sun wrt the world, simply invert the rotation defining the position of the world wrt the sun. This rotation can then simply be applied on top of the axial rotation you already have to find where the sun is, compared to a point on the world's surface.

Depending on how accurately you want to model the celestial system, you have the opportunity to make a few optimisations:
If you approximate the earth's solar orbit to be circular, and take tan(x)~x (small x), then the longitudinal position of the sun wrt the earth simply increases by a constant value per unit time (taken modulo 2.Pi to avoid floating point inaccuracy/overflow).
If you further approximate the earth's polar axis to be orthogonal to its plane of orbit (ignoring the 23° tilt) then the sun's latitudinal position will be constantly zero (otherise, it will oscillate roughly sinusoidally).

Tell us how accurate this model must be and we'll be able to go into more detail.

Regards

##### Share on other sites
Well, consider, I'd like an image around 400x200 pixels displaying the world, and I'd like to see the day night cycle in real time, so it should only have to be accurate down to hours.

I'd have to have the axial tilt because I want the seasons to show up on the map.

I'm a bit weary of lat, long, alt coordinates because the way I was going to display the Light/Shadow map was to use a 3D sphere and a 3d position of the sun in earth centered coordinates then use vertex normals and a vector to the light to perform lambert shading on the sphere. that's the only way I could think of getting that sinusoidal pattern on the map...

So if we could work out a formula for determining which parts of the map are in shadow in lat,long,alt coordinates, that would be a good start!

##### Share on other sites
Check out www.SimGear.org that's the simulation kernel that's used by the open source FlightGear flight simulator that features proper sun/moon/planet modeling-all the required routines are contained in SimGear, and can be easily used-even if only for inspiration

1. 1
2. 2
3. 3
4. 4
Rutin
19
5. 5

• 13
• 14
• 9
• 9
• 9
• ### Forum Statistics

• Total Topics
632927
• Total Posts
3009250
• ### Who's Online (See full list)

There are no registered users currently online

×