PDA

View Full Version : How do I calculate sunrise/sunset times for non-Earth planets?

snoopy
07-15-2012, 01:53 AM
I am trying to create a world, and I don't like to do things halfway. So I am starting from scratch: new star, new planet. I plan to keep them similar to Earth, but not exactly, which means I can't just use Earth data for sunrise/sunset and moonrise/moonset times, like I could find here: http://aa.usno.navy.mil/data/docs/RS_OneYear.php.

What I am hoping to get is some sort of algorithm that would allow me to calculate these times for any planet, hopefully using custom time scales.

Input variables would include:

velocity of revolution
rotational velocity
orbit as defined by Keplerian orbital elements (length of year being calculated from ellipse size and velocity of revolution.)
axial tilt
distance at aphelion and perihelion (Those are probably already defined by the Keplerian orbit. Is that correct?)
planet radius (Does this matter, or is rotational velocity the only relevant input for day length?)
Time unit length (As in, having a planet where the inhabitants' hour is not the same length of time as our hour. In other words, I would like to use custom time units, and define day length in terms of them.)
probably more because I don't understand enough

I would also like to be able to calculate the points of sunrise/sunset and the arc that the sun would take through the sky.

Does anyone know of a program that would allow me to do this, and hopefully create tables such as the one in the link I posted? Or perhaps a planetary simulation program that would at least allow me to account for everything except point 7? I'm willing to be flexible on that, because it's likely more trouble than it's worth. Or perhaps there is someone on this forum with enough knowledge in astrophysics and programming to create such a program (unlikely, but I thought I'd ask)? Even a set of equations that would require manual solving would be a start.

Or am I mad to even consider attempting this level of detail for the sake of a fictional world?

Oh, and did I mention that it's in a binary star system, so I have an extra star whose positioning over time I will also need to track?

Anyway, hope my request is clear. Please ask for any clarification you need.

Gidde
07-15-2012, 06:54 AM
I think your best bet is most likely Celestia (it's free, and it's awesome -- http://www.shatters.net/celestia/). What it does is allow you to create a custom star system with the variables you mention, plus a few others, and then models it for you so that you can see exactly what it looks like. You can find some great tutorials at http://www.celestiamotherlode.net/catalog/documentation.html -- I'd start with the Introduction to Celestia Add-ons by Selden Ball, Jr. It goes through the process of creating a fictional star system. From there you'll know which tuts to look for.

As for whether you're mad to consider this level of detail: I've done it, so if you're mad so am I! Also consider that (arguably) what made Tolkien great was the insane amount of detail he put into his fictional world. So as far as I'm concerned, you're making it better with each detail. :)

xoxos
07-15-2012, 11:55 AM
:) i asked if there was any interest in such a program a month or so ago.. this is the only positive comment i've seen yet.

even without a script, you ought to be able to get there with some basic trig. if you want to write something and get involved, all the data is out there of course.. perhaps the henon oscillator model would allow you to feel sufficiently technically involved :)

snoopy
07-16-2012, 01:59 AM
I think your best bet is most likely Celestia (it's free, and it's awesome -- http://www.shatters.net/celestia/). What it does is allow you to create a custom star system with the variables you mention, plus a few others, and then models it for you so that you can see exactly what it looks like. You can find some great tutorials at http://www.celestiamotherlode.net/catalog/documentation.html -- I'd start with the Introduction to Celestia Add-ons by Selden Ball, Jr. It goes through the process of creating a fictional star system. From there you'll know which tuts to look for.

As for whether you're mad to consider this level of detail: I've done it, so if you're mad so am I! Also consider that (arguably) what made Tolkien great was the insane amount of detail he put into his fictional world. So as far as I'm concerned, you're making it better with each detail. :)
I took a look at it, but I think I prefer Space Engine. It's free too, and from what I've seen of what can be done in Celestia, even more awesome. More types of navigation controls, and most importantly, in addition to known celestial objects, Space Engine populates the rest of the universe with procedurally generated ones. As in millions of galaxies with trillions of star systems to explore. And you can land on all of the planets, stars, moons, etc. and explore the procedural terrains. It also allows you to create and import your own stars, planets, etc. with orbits defined by those parameters. I've actually got the two stars done and orbiting properly. No planets yet though.

Here's the link, if you don't know about this program yet: http://en.spaceengine.org/. If your computer can run it (it has rather high requirements), it's about the best thing you'll ever download.

But what these programs can't do that I know of is tell me the time of sunrise and sunset at a given location on a given date. The closest I could get was focusing on a particular longitude and latitude on a planet and watching the day/night boundary go by in Celestia. That's a bit cumbersome and imprecise unfortunately. What I really need is something like the Navy link I posted, something that will output charts with dates and times.

That Celestia tutorial had some nice links to information on orbital elements, by the way.

And yes, I completely agree about Tolkien. It might be that I am nerdy enough to be most of the way through the History of Middle-Earth books... Learning enough about linguistics and philology to create a good language might take me a while though. One thing at a time.

Lastly, you said you've done high detail work: Did you attempt anything similar? If so, how did you handle it?

i asked if there was any interest in such a program a month or so ago.. this is the only positive comment i've seen yet.

even without a script, you ought to be able to get there with some basic trig. if you want to write something and get involved, all the data is out there of course.. perhaps the henon oscillator model would allow you to feel sufficiently technically involved

I would most definitely be interested. It's a shame (if an unsurprising one) that there hasn't been any other interest. And that basic trig is one thing I'm hoping to learn, since I don't know how to apply it to this problem at the moment. Sadly, I lack the expertise to program anything, so I doubt I could turn it into automated form even after I learn the math.

vorropohaiah
07-16-2012, 07:21 AM
great link! I've been looking for something like this for my world for a while.

edit: though my graphics card is somewhat crap, so not sure i can run these effectively. will certainly try them though

call me mad too :)

Gidde
07-16-2012, 08:14 AM
Lastly, you said you've done high detail work: Did you attempt anything similar? If so, how did you handle it?

I'm still in the midst of that detail work, but I've done the modeling in celestia and then watching the horizon ;) I'm currently working on world map and culture/languge creation.

Sent from my iPhone using Tapatalk

vorropohaiah
07-16-2012, 10:30 AM
I'm still in the midst of that detail work, but I've done the modeling in celestia and then watching the horizon ;) I'm currently working on world map and culture/languge creation.

do you hav a blog or any threads following your progress? i always like seeing what other people are up to.

sorry for the OT post

xoxos
07-17-2012, 12:24 AM
I would most definitely be interested. It's a shame (if an unsurprising one) that there hasn't been any other interest. And that basic trig is one thing I'm hoping to learn, since I don't know how to apply it to this problem at the moment. Sadly, I lack the expertise to program anything, so I doubt I could turn it into automated form even after I learn the math.

tbh i think it would be fastest to blag it with a sine. take the sine of the date as a % of the year and set your minimum and maximum for summer and winter. you'd be close enough just to linear fade between them.

snoopy
07-17-2012, 05:09 PM
I have actually found a fair amount on the way it is calculated on Earth now. I still have to read more to understand it, but I think I have at least figured out how to use novel time scales, which is to define them in terms of angle. 1 hour on Earth (a sidereal hour) is equivalent 15 degrees around the axis of rotation. You can simply redefine an hour in terms of the number of degrees out of 360 the planet rotates in that time period. If you know the angular velocity of its rotation, then I think it should be easy to use this value in the 'normal' Earth equations.

This is very useful: http://en.wikipedia.org/wiki/Sunrise_equation

I should have known to go to Wikipedia first. :P

snoopy
07-18-2012, 10:44 PM
EDIT: I was right after all!

I'm probably being hasty, posting before I test my results, but I think I can solve for the hour angle now, which I believe I can use to get time using the method from my previous post.

Here we go:

1. Get the Mean Anomaly. You can do this by simply picking a value between 0 and 360, but it is the time since the planet last passed perihelion moving at its mean motion. In math terms:

M = sqrt((G/(m1+m2))/a^3)*t
where
M is the mean anomaly
G is the gravitational constant in m^3 kg^-1 s^-2 (which you could define in terms of your custom time scale)
m1 and m2 are the masses of your orbiting bodies in kg
a is the semi-major axis of your planets orbit in meters
t is the time in seconds (don't forget to convert to custom time if you did that for the gravitational constant as well)

2. Use the mean anomaly to calculate the equation of center, which is the difference between true anomaly (actual angle along the ecliptic) and mean anomaly (which treats the ecliptic as a circle). This is done with the (accurate to 4 decimal places) approximation

C = (2e-0.25e^3)*sinM + 1.25e^2*sin2M + (13/12)e^3*sin3M
where
C is the equation of center
e is the eccentricity of the orbit (which you will need to decide on yourself)
M is the mean anomaly (I think it needs to be in degrees, even though it would appear to output an answer in radians. This seems wrong, but it gave me the correct answer when I was following an explanation. This will definitely be something I double check)

3. Find the ecliptic longitude using

λ = M + C + Π + 180
where
λ is the ecliptical longitude
Π is the longitude of perihelion (pericenter, periapsis) in degrees (you obtain this by adding the Argument of Perihelion and the Longitude of the Ascending Node, both of which you will have from defining your orbit. If you do it in Space Engine, remember that the values in that are relative to our sun. You will need to get the difference in those values between your sun and your planet)
180 because it is the sun viewed from the planet, not the planet viewed from the sun

4. Find the declination of the sun using

sinδ = sinλ + sinA
where
δ is the declination
A is the axial tilt in degrees

5. Calculate the hour angle using

cosω = (sin(-0.83)-sin(Phi)*sinδ) / (cos(Phi)*cosδ)
where
ω is the hour angle
-0.83 degrees because of atmospheric refraction (assumes Earth-like atmosphere)
Phi is the latitude of the observer

And there it is, generalized for other planets. Correctly, I hope.

I found this link very helpful: http://aa.quae.nl/en/reken/zonpositie.html

snoopy
07-19-2012, 02:45 PM
So after thinking that it was wrong, I went through everything a couple more times. Turns out what I did incorrectly was checking my answer on the Navy site I posted earlier. I forgot to enter time zone when picking a location. Once I did that, the times I got for sunrise and sunset using the equations I posted were within 5 minutes of the correct times!

It's not done yet though. To get from hour angle (the last value I solved for in my previous post) to the times, I used the equations on the Sunrise Equation Wikipedia page, which involve the Julian date. Obviously, another planet would not use Julian date. What matters is the time elapsed since epoch though, so it should be a simple matter of defining my own epochs, using an equivalent of the Julian date. This would make use of the custom planet's day length, so all of parameters involving time will need to take that into account. This means using ratios to change the length of my second and the value of my gravitational constant.

Now, if only I could code...

xoxos
07-20-2012, 02:08 PM
here's a basic c/c++ script i use when i need to calculate stuff..

#include <fstream>
#include <stdlib.h>
#include <windows.h>
#include "math.h"
#include "iomanip.h"
#include <iostream>

using namespace std;

ofstream out;

int main() {
double o;

out.open("solve.txt");

for(int i = 2700; i <= 2800; i++) {

o = (double)i;
o += 5773500000;
o *= .0000000001;
o = o - o * o * o;

out << setprecision(16) << i << ",\t" << o << "\r\n";
}

out.close();

return 0;
}

..here's the same thing with annotations... i use an old compiler.. borland's fclt.. which is a 5 meg install. low commitment, still works.. simple as such to use..

#include <fstream> // necessary for writing txt file
#include <stdlib.h> // stuff you write
#include <windows.h> // not necessary in this program
#include "math.h"
#include "iomanip.h" // necessary for setprecision statement
#include <iostream> // necessary for writing txt file

using namespace std; // stuff you write

ofstream out; // open filestream to write a file

int main() { // begin main program statement
double o; // declare a double length floating point variable

out.open("solve.txt"); // create text file

for(int i = 2700; i <= 2800; i++) { // do the calculations i needed

o = (double)i;
o += 5773500000;
o *= .0000000001;
o = o - o * o * o;

out << setprecision(16) << i << ",\t" << o << "\r\n"; // write variables i and o to text file, with a tab and a line break
}

out.close(); // close file

return 0; // execution of program ends
}

Relic Kimah
07-17-2013, 09:52 AM
I have an English degree and I can't do anything beyond fifth-grade math, so if you even understand the last post, you are light-years beyond me. But I would remind you: any astrophysics of multiple stars and planets also involve laws of physics. If you have a long time span in mind for the focus of a planet, or multiple planets, eventually their orbital velocities and speeds of rotation taper off. I don't know if you'll get that precise, but it is a factor to consider. Also- a somewhat obvious point- the binary system creates significantly more heat than a single medium-sized "yellow" star. Any planetoid with Terran qualities in temperature cannot be the same size and relative distance from the system's center.

I hope that is not too confusing. It's hard to articulate things like this when so many people think two-dimensionally. Good luck with your creative endeavor!

snoopy
10-23-2013, 12:07 AM
I don't think I ever saw this last post, so I might as well respond (and hope I don't get this thread closed for being necro'd).

I don't need it to be so accurate as to include orbital/rotational slowing over time. I'm pretty sure I decided to disregard Milankovich cycles for the most part as well. Just way too many factors. I suppose I'll have to think about Milankovich cycles in vague terms if I want to guesstimate (which is apparently an accepted word here) ice age times.

To answer the second part, that shouldn't be an issue at all. The planet orbits only one of the stars in the system. The second star is a lowly K-class star that is 80 AU distant at closest approach, which adds essentially zero heat.

Unfortunately, that code means nothing to me either. This whole endeavor got put on hold anyway. I'll pick it up again some time, but I don't think the time is now.