<p>All you really need to know is that the moon is rotating and one day on the moon is one month long.</p>

<p>The axial tilt of the moon is 1.5 degrees, so there are no significant seasons.</p>

<p>The path of the sun is (close to) a great circle in the sky. And is much like the path of sun on the Equinox on Earth. It rises, takes 7.4 days to reach the Meridian (at which point its altitude is equal to 90-latitude) and then it slowly sets over another 7.4 days. It is then dark until the sun rises again. The whole period takes one month, 29.5 days</p>

<p>If you need greater accuracy (if you want to point a telescope at the sun, not just a solar panel) you would need to account for the axial tilt, which is tricky because the moon's orbit is complex and non-Keplarian. </p>

<p>You don't need to account for the motion of the moon around the Earth. The parallax is not enough to invalidate the calculation of the position, for the sake of pointing a solar panel. So just treat the moon as a slowly spinning body with almost not axial tilt and forget about the Earth.</p>

<p>The prime meridian on the moon is the meridian facing Earth. On the Prime meridian the sun culminates at full moon</p>

<p>If you are 90degrees East then the sun will culminate 1/4 month earlier and 90degrees West, then 1/4 month later.</p>

CC BY-SA 4.0
2020-04-20T21:21:21.967Z
Cool! That does make it a lot simpler. Do you know how I could figure out the timing of the day/night cycle given an arbitrary location on the moon?
J. Ford
CC BY-SA 4.0
2020-04-20T21:29:33.763Z
On the prime meridian sun rise at first quarter, midday on full moon, sun set on third quarter.  At other longitudes add 7.4 days for every 90 degrees West.
James K
CC BY-SA 4.0
2020-04-20T20:47:37.033Z
2020-04-20T21:28:09.160Z
2020-04-20T21:28:09.160Z
James K
<p>If you like Python then see <a href="https://rhodesmill.org/skyfield/planetary.html" rel="nofollow noreferrer">Skyfield; Observing from a Moon location</a> which I believe will do exactly what you need! Also see for example <a href="https://space.stackexchange.com/a/42122/12102">this answer</a> to <em>Ephemeris for lunar body-centered body-fixed coordinates?</em> written by Skyfield's author.</p>

<p>For example, you posted your question at <code>2020-04-20 15:21:36 UTC</code>. Let's say your rover has just driven up to <a href="https://tools.wmflabs.org/geohack/geohack.php?pagename=Surveyor_3&amp;params=3.01612_S_23.41791_W_globe:moon" rel="nofollow noreferrer">Surveyor III</a> at <code>3° 0′ 58.03″ S, 23° 25′ 4.48″ W  (-3.01612°, -23.41791°)</code> (read more about Surveyor III in <a href="https://space.stackexchange.com/q/20353/12102">How did Apollo-12 manage to land next to Surveyor-3? First “Space-Tourists”?</a>)</p>

<p>At that moment the Sun was below the horizon. The output of the script below is</p>

<pre><code>RA:  01h 54m 39.28s
Dec:  +11deg 45' 38.6"
alt:  -38deg 30' 34.6" degrees (below the horizon)
az:  265deg 50' 21.5" degrees around the horizon from north
</code></pre>

<blockquote>
  <p>I can get the coordinates of the Earth-Moon barycenter using VSOP2013</p>
</blockquote>

<p>factoids: <a href="https://stackoverflow.com/q/34487170/3904031">VSOP is what PyEphem uses under the hood</a>. It is currently in <a href="https://rhodesmill.org/pyephem/" rel="nofollow noreferrer">maintenance mode</a> maintained by the same person who wrote Skyfield. </p>

<hr>

<pre><code>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# adapted from https://rhodesmill.org/skyfield/planetary.html

from skyfield.api import PlanetaryConstants, Loader

load = Loader('~/Documents/fishing/SkyData')  # avoids multiple copies of large files
ts = load.timescale(builtin=True)
t = ts.utc(2020, 4, 20, 15, 21, 36)

eph = load('de421.bsp')
earth, moon, sun = [eph[thing] for thing in ('earth', 'moon', 'sun')]

pc = PlanetaryConstants()
pc.read_text(load('moon_080317.tf'))
pc.read_text(load('pck00008.tpc'))
pc.read_binary(load('moon_pa_de421_1900-2050.bpc'))

frame = pc.build_frame_named('MOON_ME_DE421')
Surveyor_III = moon + pc.build_latlon_degrees(frame, latitude_degrees = -3.01612,
                                              longitude_degrees = -23.41791)

apparent = Surveyor_III.at(t).observe(sun).apparent()
ra, dec, distance = apparent.radec()
print('RA: ', ra)
print('Dec: ', dec)

alt, az, distance = apparent.altaz()
if alt.degrees &gt;= 0:
    print('alt: ', alt, 'degrees (above the horizon)')
else:
    print('alt: ', alt, 'degrees (below the horizon)')
print('az: ', az, 'degrees around the horizon from north')
</code></pre>

CC BY-SA 4.0
2020-04-21T13:26:50.327Z
Wow! Awesome! I actually found skyfield and used it to solve this problem on Earth, but for the life of me I couldn't figure out how to do the same on the Moon. Thank you so much!
J. Ford
CC BY-SA 4.0
2020-04-21T14:07:18.613Z
@J.Ford Skyfield is a really excellent package and under constant development and expansion. I've linked to a 2013 talk by the author in [How to pronounce “Ephemerides”?](https://english.stackexchange.com/q/370655/217285) and it seems to have been a real labor of love. It also has a [github page](https://github.com/skyfielders/python-skyfield) and an active discussions in the issues section.
uhoh
CC BY-SA 4.0
2020-04-21T05:52:37.300Z
2020-04-21T06:45:27.917Z
2020-04-21T06:45:27.917Z
uhoh
<p>I'm a robotics researcher writing orienteering code for a solar-powered lunar rover.
I have two similar problems:</p>

<ol>
<li><p>Given the position of a robot on the moon in <a href="https://en.wikipedia.org/wiki/Selenographic_coordinates" rel="noreferrer">lunar latitude/longitude</a>, where is the sun? That is, which direction should I orient my solar panel to maximize incidence?</p></li>
<li><p>For testing purposes, I need to solve the same problem on Earth. Given Earth lat/lon, where is the sun?</p></li>
</ol>

<p>To be honest, I'm not even sure what coordinate system to use to express the answer to these questions. I was considering a coordinate frame centered on the rover with East, North, and Up axes, but I'm open to a better suggestion!</p>

<p>So far, I've found some information about VSOP87 and ELP2000, and I've started reading "Astronomical Algorithms", but I'd appreciate help from the experts.</p>

<h2>Edit</h2>

<p>Here's what I've got so far. I can get the coordinates of the Earth-Moon barycenter using VSOP2013. If I can get from the barycenter to the center of the Earth, I can probably use EPS2000/82 to find the position of the Moon in heliocentric coordinates.</p>

<p>Sun->VSOP->Earth-Moon Barycenter->Earth->EPS2000->Moon</p>

<p>At very least, I think this would get me the moon coordinates in the sun frame. I'm hoping it would also give me the orientation of the Moon in the sun frame?</p>

CC BY-SA 4.0
2020-04-20T16:54:30.200Z
Part 2 is fairly easy (assuming you don't need high precision). You should take a look at some resources on sundial theory. There are several websites with that material. It's also helpful to have some familiarity with spherical trig, to do the various coordinate transformations that crop up in this sort of work.
PM 2Ring
CC BY-SA 4.0
2020-04-20T21:21:54.867Z
You're right, reading about sundials is definitely helpful here.
J. Ford
CC BY-SA 4.0
2020-04-21T05:56:19.257Z
only tangentially related to sundials: [How many sundials & Sun compasses are there on solar system bodies?](https://space.stackexchange.com/q/32348/12102)
uhoh
<the-sun><the-moon><mathematics>
Where is the sun relative to my lunar rover?
J. Ford
# Where is the sun relative to my lunar rover?

(Asked by: username_0 on 2020-04-20)

I'm a robotics researcher writing orienteering code for a solar-powered lunar rover.
I have two similar problems:

1. Given the position of a robot on the moon in [lunar latitude/longitude](https://en.wikipedia.org/wiki/Selenographic_coordinates), where is the sun? That is, which direction should I orient my solar panel to maximize incidence?
2. For testing purposes, I need to solve the same problem on Earth. Given Earth lat/lon, where is the sun?

To be honest, I'm not even sure what coordinate system to use to express the answer to these questions. I was considering a coordinate frame centered on the rover with East, North, and Up axes, but I'm open to a better suggestion!

So far, I've found some information about VSOP87 and ELP2000, and I've started reading "Astronomical Algorithms", but I'd appreciate help from the experts.

## Edit

Here's what I've got so far. I can get the coordinates of the Earth-Moon barycenter using VSOP2013. If I can get from the barycenter to the center of the Earth, I can probably use EPS2000/82 to find the position of the Moon in heliocentric coordinates.

Sun->VSOP->Earth-Moon Barycenter->Earth->EPS2000->Moon

At very least, I think this would get me the moon coordinates in the sun frame. I'm hoping it would also give me the orientation of the Moon in the sun frame?

**Tags:** the-sun, the-moon, mathematics

> **Comments:**
> **username_1**: Part 2 is fairly easy (assuming you don't need high precision). You should take a look at some resources on sundial theory. There are several websites with that material. It's also helpful to have some familiarity with spherical trig, to do the various coordinate transformations that crop up in this sort of work.  
> **username_0**: You're right, reading about sundials is definitely helpful here.  
> **username_2**: only tangentially related to sundials: [How many sundials & Sun compasses are there on solar system bodies?](https://space.stackexchange.com/q/32348/12102)  

---

## 2 answers

### Answer by username_2 on 2020-04-21. Score: 4 | Accepted answer

If you like Python then see Skyfield; Observing from a Moon location which I believe will do exactly what you need! Also see for example this answer to Ephemeris for lunar body-centered body-fixed coordinates? written by Skyfield's author.
For example, you posted your question at 2020-04-20 15:21:36 UTC. Let's say your rover has just driven up to Surveyor III at 3° 0′ 58.03″ S, 23° 25′ 4.48″ W  (-3.01612°, -23.41791°) (read more about Surveyor III in How did Apollo-12 manage to land next to Surveyor-3? First “Space-Tourists”?)
At that moment the Sun was below the horizon. The output of the script below is
RA:  01h 54m 39.28s
Dec:  +11deg 45' 38.6"
alt:  -38deg 30' 34.6" degrees (below the horizon)
az:  265deg 50' 21.5" degrees around the horizon from north


I can get the coordinates of the Earth-Moon barycenter using VSOP2013

factoids: VSOP is what PyEphem uses under the hood. It is currently in maintenance mode maintained by the same person who wrote Skyfield. 

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# adapted from https://rhodesmill.org/skyfield/planetary.html

from skyfield.api import PlanetaryConstants, Loader

load = Loader('~/Documents/fishing/SkyData')  # avoids multiple copies of large files
ts = load.timescale(builtin=True)
t = ts.utc(2020, 4, 20, 15, 21, 36)

eph = load('de421.bsp')
earth, moon, sun = [eph[thing] for thing in ('earth', 'moon', 'sun')]

pc = PlanetaryConstants()
pc.read_text(load('moon_080317.tf'))
pc.read_text(load('pck00008.tpc'))
pc.read_binary(load('moon_pa_de421_1900-2050.bpc'))

frame = pc.build_frame_named('MOON_ME_DE421')
Surveyor_III = moon + pc.build_latlon_degrees(frame, latitude_degrees = -3.01612,
                                              longitude_degrees = -23.41791)

apparent = Surveyor_III.at(t).observe(sun).apparent()
ra, dec, distance = apparent.radec()
print('RA: ', ra)
print('Dec: ', dec)

alt, az, distance = apparent.altaz()
if alt.degrees >= 0:
    print('alt: ', alt, 'degrees (above the horizon)')
else:
    print('alt: ', alt, 'degrees (below the horizon)')
print('az: ', az, 'degrees around the horizon from north')

> **Comments:**
> **username_0**: Wow! Awesome! I actually found skyfield and used it to solve this problem on Earth, but for the life of me I couldn't figure out how to do the same on the Moon. Thank you so much!  
> **username_2**: @J.Ford Skyfield is a really excellent package and under constant development and expansion. I've linked to a 2013 talk by the author in [How to pronounce “Ephemerides”?](https://english.stackexchange.com/q/370655/217285) and it seems to have been a real labor of love. It also has a [github page](https://github.com/skyfielders/python-skyfield) and an active discussions in the issues section.  

---

### Answer by username_3 on 2020-04-20. Score: 4

All you really need to know is that the moon is rotating and one day on the moon is one month long.

The axial tilt of the moon is 1.5 degrees, so there are no significant seasons.

The path of the sun is (close to) a great circle in the sky. And is much like the path of sun on the Equinox on Earth. It rises, takes 7.4 days to reach the Meridian (at which point its altitude is equal to 90-latitude) and then it slowly sets over another 7.4 days. It is then dark until the sun rises again. The whole period takes one month, 29.5 days

If you need greater accuracy (if you want to point a telescope at the sun, not just a solar panel) you would need to account for the axial tilt, which is tricky because the moon's orbit is complex and non-Keplarian.

You don't need to account for the motion of the moon around the Earth. The parallax is not enough to invalidate the calculation of the position, for the sake of pointing a solar panel. So just treat the moon as a slowly spinning body with almost not axial tilt and forget about the Earth.

The prime meridian on the moon is the meridian facing Earth. On the Prime meridian the sun culminates at full moon

If you are 90degrees East then the sun will culminate 1/4 month earlier and 90degrees West, then 1/4 month later.

> **Comments:**
> **username_0**: Cool! That does make it a lot simpler. Do you know how I could figure out the timing of the day/night cycle given an arbitrary location on the moon?  
> **username_3**: On the prime meridian sun rise at first quarter, midday on full moon, sun set on third quarter.  At other longitudes add 7.4 days for every 90 degrees West.  

---

