Skip to content

Commit

Permalink
Merge pull request #23 from jfcarr-astronomy/sun/solar-elongation
Browse files Browse the repository at this point in the history
Calculate -> Solar elongation
  • Loading branch information
Jim Carr committed Nov 29, 2020
2 parents beb9724 + c53c74c commit 94bfde0
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 1 deletion.
6 changes: 6 additions & 0 deletions PALib.Tests/PASun.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,11 @@ public void EquationOfTime()
{
Assert.Equal((6, 31.52), _paSun.EquationOfTime(27, 7, 2010));
}

[Fact]
public void SolarElongation()
{
Assert.Equal(24.78, _paSun.SolarElongation(10, 6, 45, 11, 57, 27, 27.8333333, 7, 2010));
}
}
}
36 changes: 36 additions & 0 deletions PALib/PAMacros.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2607,5 +2607,41 @@ public static (double a, double x, double y, double la, string s) ETwilight_L371

return (a, x, y, la, s);
}

/// <summary>
/// Calculate the angle between two celestial objects
/// </summary>
/// <remarks>
/// Original macro name: Angle
/// </remarks>
/// <param name="xx1"></param>
/// <param name="xm1"></param>
/// <param name="xs1"></param>
/// <param name="dd1"></param>
/// <param name="dm1"></param>
/// <param name="ds1"></param>
/// <param name="xx2"></param>
/// <param name="xm2"></param>
/// <param name="xs2"></param>
/// <param name="dd2"></param>
/// <param name="dm2"></param>
/// <param name="ds2"></param>
/// <param name="s"></param>
/// <returns></returns>
public static double Angle(double xx1, double xm1, double xs1, double dd1, double dm1, double ds1, double xx2, double xm2, double xs2, double dd2, double dm2, double ds2, PAAngleMeasure s
)
{
var a = (s.Equals(PAAngleMeasure.Hours)) ? DegreeHoursToDecimalDegrees(HMStoDH(xx1, xm1, xs1)) : DegreesMinutesSecondsToDecimalDegrees(xx1, xm1, xs1);
var b = a.ToRadians();
var c = DegreesMinutesSecondsToDecimalDegrees(dd1, dm1, ds1);
var d = c.ToRadians();
var e = (s.Equals(PAAngleMeasure.Hours)) ? DegreeHoursToDecimalDegrees(HMStoDH(xx2, xm2, xs2)) : DegreesMinutesSecondsToDecimalDegrees(xx2, xm2, xs2);
var f = e.ToRadians();
var g = DegreesMinutesSecondsToDecimalDegrees(dd2, dm2, ds2);
var h = g.ToRadians();
var i = (d.Sine() * h.Sine() + d.Cosine() * h.Cosine() * (b - f).Cosine()).ACosine();

return Degrees(i);
}
}
}
26 changes: 26 additions & 0 deletions PALib/PASun.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,5 +240,31 @@ public class PASun

return (equationOfTimeMin, equationOfTimeSec);
}

/// <summary>
/// Calculate solar elongation for a celestial body.
/// </summary>
/// <remarks>
/// Solar elongation is the angle between the lines of sight from the Earth to the Sun and from the Earth to the celestial body.
/// </remarks>
/// <param name="raHour"></param>
/// <param name="raMin"></param>
/// <param name="raSec"></param>
/// <param name="decDeg"></param>
/// <param name="decMin"></param>
/// <param name="decSec"></param>
/// <param name="gwdateDay"></param>
/// <param name="gwdateMonth"></param>
/// <param name="gwdateYear"></param>
/// <returns>solarElongationDeg -- Solar elongation, in degrees</returns>
public double SolarElongation(double raHour, double raMin, double raSec, double decDeg, double decMin, double decSec, double gwdateDay, int gwdateMonth, int gwdateYear)
{
var sunLongitudeDeg = PAMacros.SunLong(0, 0, 0, 0, 0, gwdateDay, gwdateMonth, gwdateYear);
var sunRAHours = PAMacros.DecimalDegreesToDegreeHours(PAMacros.EcRA(sunLongitudeDeg, 0, 0, 0, 0, 0, gwdateDay, gwdateMonth, gwdateYear));
var sunDecDeg = PAMacros.EcDec(sunLongitudeDeg, 0, 0, 0, 0, 0, gwdateDay, gwdateMonth, gwdateYear);
var solarElongationDeg = PAMacros.Angle(sunRAHours, 0, 0, sunDecDeg, 0, 0, raHour, raMin, raSec, decDeg, decMin, decSec, PAAngleMeasure.Hours);

return Math.Round(solarElongationDeg, 2);
}
}
}
6 changes: 6 additions & 0 deletions PALib/PATypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@ public enum PATwilightType
Nautical = 12,
Astronomical = 18
}

public enum PAAngleMeasure
{
Degrees,
Hours
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ If you're interested in this topic, please buy the book! It provides far more de
- [x] Calculate -> Local sunrise and sunset
- [x] Calculate -> Morning and evening twilight
- [x] Calculate -> Equation of time
- [ ] Calculate -> Solar elongation
- [x] Calculate -> Solar elongation

### Planets

Expand Down

0 comments on commit 94bfde0

Please sign in to comment.