Calculating celestial rotation

As some of you may know, I’m working on Armok Vison, a 3D renderer for dwarf fortress.

I’m trying to figure out how to calculate the rotation of the sun, moon, and stars. I have the following information at my disposal:

  • Local solar time
  • latitude and longitude (Approximately)
  • number of lunar cycles in the year (exactly 13, I believe)

It doesn’t need to be exactly accurate to earth, but the movements of all of them should at least look reasonable.

Anybody have any ideas?

1 Like

Do you have a skybox? Or are you using lat/longs of Earth and our skybox as you would see in real life?

Are you trying to simulate the sun’s varying angle above the horizon during the year…that sort of stuff? Not really sure what you’re trying to do exactly.

I’m using lat/longs of our night sky, yeah.

This one, specifically:

Then I blend it on top of the default unity procedural sky.

Ah, cool. I’m assuming you’re using dfhack to get that data?

Are you doing this for adventure mode or fortress mode? Or both?

So, from what I understand, what you want is the sun’s and moon’s position in the sky given a certain date and position? I think I remember an open source program that let you input latitude and longitude and date and showed you the sky for that position and time. I’ll see if I can find a link. Maybe you could use whatever method they are using, since from what I understand it’s basically what you want to do.

As for the phase of the moon, I think this information is useful, in case you haven’t found it yet:

Edit: The program I remembered was stellarium:

I found some stuff for getting the position of our sun given all the required parameters, but it doesn’t give enough data to get the rotation of the skybox, which I also need. Or at least, I don’t understand the math enough to infer it.

Moon phase would be automatic as long as the moon position is correct, or vise versa, I guess.

Also I don’t necessarily need it to be accurate to earth, since DF is not earth, so a lot of the calculations can be simplified.

Current best guess on how to do this would be to have the planet axis (around which the sun and moon move) rotate around a solar system axis, and correcting the day legth by adding or subtracting a day from the year, but something about it seems off.

Paging @kichae if he has any ideas?

1 Like

Disclaimer: I’ve never played DF, so I don’t know anything about DF’s celestial mechanics. That said…

If you’re thinking of going that far, I’d place the planet at the centre of the system and have it rotate once per day. Keep in mind that 1 day will actually involve a rotation through 360 + 360/336 (361.0714(…)) degrees.

Have Sun on a circular path, and have it advance 360/336 (1.0714 and change) degrees per day. Have the sun’s path tilted by whatever the axial tilt of the DF planet is, so that you can have seasonal changes in day length.

Have the Moon on a separate circular path. The Moon’s synodic period is given as 25.85 days. In 25.85 days, the Sun will have moved 27.6964 (and a bit) degrees, meaning the Moon will have to cover 387.6964(…) degrees in 25.85 days. That’s 14.9979(…) degrees per day.

Make sure the path of the Sun and the path of the Moon are tilted relative to one another, otherwise there will be a solar eclipse every new moon.

Rounding errors may cause the dates of the new and full moon to drift over time, so you may want to quietly reset the positions on an annual basis.

1 Like

That seems to make sense.

So if my coordinates are always relative to the surface of the planet, I would have to rotate the universe around it, right? And then do all the other rotations around it.

So the hierarchy would be:

  • planet axis, rotated according to longitude
  • universe axis, rotated by day
    *sun axis rotated once per year
    *moon axis, rotated 13 times per year

And everything inherits the rotation of the parent, obviously.

Did I get that right?

If you’re going to go through the trouble of rotating the universe (so, the skybox?), then I wouldn’t bother rotating the planet. Just have the skybox rotate by 360 degrees per day, and the sun and moon rotate by 360 degrees + the numbers given above.

I didn’t mean rotating the planet itself, that’s impossible with my current setup, I just meant rotating the planet’s axis, around which everything else rotates, to simulate the sun angle changing as you go closer to the poles.

Ohhh. If you can tilt the path of the sun and moon, don’t bother. There’s no need to tilt the planet’s axis if you can do that (the tilt of the sun’s path is the tilt of the planet’s axis).

I got it working, more or less, but didn’t do the moon yet. It’s always full moon.

The moon seems to be following a path opposite from the sun (When the sun is south, the moon’s path is north, and vice versa); I assume this is correct?

Also, for now, I’ve decided to just assume that everywhere in the world is 45 degrees north, for the purposes of the sun, since DF has a more-or-less mideval europe theme. I might change that later, but for now I’m lazy.

If it’s always full moon, then yes, the moon will be high in the sky when the sun is low, and vice versa. Just keep in mind that once you start moving the moon, if it doesn’t follow at least a slightly different path from the sun, every new moon will also be a solar eclipse.

I’m not too worried about that, because the way I do the rendering means that the sun shines through the moon anyway.