diff --git a/PALib.Tests/PASun.cs b/PALib.Tests/PASun.cs
index fdf674f..fb06789 100644
--- a/PALib.Tests/PASun.cs
+++ b/PALib.Tests/PASun.cs
@@ -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));
+ }
}
}
\ No newline at end of file
diff --git a/PALib/PAMacros.cs b/PALib/PAMacros.cs
index 394e3f9..ff53191 100644
--- a/PALib/PAMacros.cs
+++ b/PALib/PAMacros.cs
@@ -2607,5 +2607,41 @@ public static (double a, double x, double y, double la, string s) ETwilight_L371
return (a, x, y, la, s);
}
+
+ ///
+ /// Calculate the angle between two celestial objects
+ ///
+ ///
+ /// Original macro name: Angle
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ 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);
+ }
}
}
\ No newline at end of file
diff --git a/PALib/PASun.cs b/PALib/PASun.cs
index ff5ef5e..92e5f40 100644
--- a/PALib/PASun.cs
+++ b/PALib/PASun.cs
@@ -240,5 +240,31 @@ public class PASun
return (equationOfTimeMin, equationOfTimeSec);
}
+
+ ///
+ /// Calculate solar elongation for a celestial body.
+ ///
+ ///
+ /// Solar elongation is the angle between the lines of sight from the Earth to the Sun and from the Earth to the celestial body.
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ /// solarElongationDeg -- Solar elongation, in degrees
+ 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);
+ }
}
}
\ No newline at end of file
diff --git a/PALib/PATypes.cs b/PALib/PATypes.cs
index a89fb5b..52083a2 100644
--- a/PALib/PATypes.cs
+++ b/PALib/PATypes.cs
@@ -13,4 +13,10 @@ public enum PATwilightType
Nautical = 12,
Astronomical = 18
}
+
+ public enum PAAngleMeasure
+ {
+ Degrees,
+ Hours
+ }
}
\ No newline at end of file
diff --git a/README.md b/README.md
index 78ca6c0..ecef4bc 100644
--- a/README.md
+++ b/README.md
@@ -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