GSoC/GCI Archive
Google Code-in 2013 KDE

Marble: Display lunar phases

completed by: Illya Kovalevskyy

mentors: Torsten Rahn, Dennis Nienhüser, René Küttner

In

http://www.google-melange.com/gci/task/view/google/gci2013/5875395068952576

the moon pixmap has been added. In this task we want to add phases to the moon.

By coincidence the astrolib provides

void SolarSystem::getLunarPhase (double &phase, double &ildisk, double &amag)

The interesting values for us are ildisk=illuminated disc and phase:

Here the illuminated disk is the fraction of the visible disk which is illuminated (1 for Full Moon, 0.5 for
Quarter Moon) while phase is 0 for New Moon, 0.25 for First Quarter, 0.5 for Full Moon and 0.75 for
Last Quarter. (So the illuminated disk corresponds to the value returned for phase for the physical
ephemerides of the planets - a little confusing, sorry!)

So to draw the phase we can use two QPainterPath 180 degree arcs:

QPainterPath::arcTo ( const QRectF & rectangle, qreal startAngle, qreal sweepLength )

One arc is circular and has the apparent diameter of the moon (diamMoon). The other arc is Elliptical where the width of the ellipse corresponds to

width = 2 * abs( ildisk - 0.5) * diamMoon

Now comes the tricky part:The orientation of the two arcs needs to be chosen according to the phase of the moon. Make yourself familiar with the lunar phases to understand how this needs to be chosen.

The whole QPainterPath should get filled with a 75% opaque black color. It should get drawn on top of the moon's pixmap and needs to be tilted just like the pixmap