Index: celestiacore.cpp =================================================================== --- celestiacore.cpp (revision 4094) +++ celestiacore.cpp (working copy) @@ -3140,7 +3140,7 @@ Body& body, double t, double distance, - Vec3d /*viewVec*/) + Vec3d viewVec) { double kmDistance = astro::lightYearsToKilometers(distance); @@ -3161,6 +3161,47 @@ displayApparentDiameter(overlay, body.getRadius(), kmDistance); + // Display the phase angle + + // Find the parent star of the body. This can be slightly complicated if + // the body orbits a barycenter instead of a star. + Selection parent = Selection(&body).parent(); + while (parent.body() != NULL) + parent = parent.parent(); + + if (parent.star() != NULL) + { + bool showPhaseAngle = false; + + Star* sun = parent.star(); + if (sun->getVisibility()) + { + showPhaseAngle = true; + } + else + { + // The planet's orbit is defined with respect to a barycenter. If there's + // a single star orbiting the barycenter, we'll compute the phase angle + // for the planet with respect to that star. If there are no stars, the + // planet is an orphan, drifting through space with no star. We also skip + // displaying the phase angle when there are multiple stars (for now.) + if (sun->getOrbitingStars()->size() == 1) + { + sun = sun->getOrbitingStars()->at(0); + showPhaseAngle = sun->getVisibility(); + } + } + + if (showPhaseAngle) + { + Vec3d sunVec = Selection(&body).getPosition(t) - Selection(sun).getPosition(t); + sunVec.normalize(); + double cosPhaseAngle = sunVec * ((1.0 / viewVec.length()) * viewVec); + double phaseAngle = acos(cosPhaseAngle); + overlay.oprintf("Phase angle: %.1f%s\n", radToDeg(phaseAngle), UTF8_DEGREE_SIGN); + } + } + if (detail > 1) { if (body.getRotationModel()->isPeriodic())