From f9792b22bc19dd0ffb1bf4316139bb32dcfcaabb Mon Sep 17 00:00:00 2001 From: Colin Date: Thu, 3 Sep 2020 13:11:47 +0100 Subject: [PATCH] Implemenated a few todo notes --- AstroMath.UnitTests/AstroMathsUnitTests.cs | 12 +- Meade.net.Telescope/AstroMaths/AstroMaths.cs | 104 +++--------------- .../Meade.net.Telescope.csproj | 1 + Meade.net.Telescope/Telescope.cs | 2 +- 4 files changed, 22 insertions(+), 97 deletions(-) diff --git a/AstroMath.UnitTests/AstroMathsUnitTests.cs b/AstroMath.UnitTests/AstroMathsUnitTests.cs index 489c873..2e4e37c 100644 --- a/AstroMath.UnitTests/AstroMathsUnitTests.cs +++ b/AstroMath.UnitTests/AstroMathsUnitTests.cs @@ -18,14 +18,14 @@ namespace AstroMath.UnitTests [Test] public void DegreesToRadians() { - var radians = _astroMath.DegreesToRadians(90); + var radians = 90.0.DegreesToRadians(); Assert.That(radians, Is.EqualTo(1.5707963267948966)); } [Test] public void RadiansToDegrees() { - var degrees = _astroMath.RadiansToDegrees(1.5707963267948966); + var degrees = 1.5707963267948966.RadiansToDegrees(); Assert.That(degrees, Is.EqualTo(90)); } @@ -34,7 +34,7 @@ namespace AstroMath.UnitTests public void DateTimeToDecimalHours_book() { DateTime dateTime = new DateTime(2019, 05, 18, 18, 31, 27, DateTimeKind.Utc); - var decimalHours = _astroMath.DateTimeToDecimalHours(dateTime); + var decimalHours = dateTime.DateTimeToDecimalHours(); Assert.That(decimalHours, Is.EqualTo(18.524166666666666)); } @@ -43,7 +43,7 @@ namespace AstroMath.UnitTests public void DateTimeToDecimalHours() { DateTime dateTime = new DateTime(2019, 05, 18, 22, 26, 15, DateTimeKind.Utc); - var decimalHours = _astroMath.DateTimeToDecimalHours(dateTime); + var decimalHours = dateTime.DateTimeToDecimalHours(); Assert.That(decimalHours, Is.EqualTo(22.4375)); } @@ -52,7 +52,7 @@ namespace AstroMath.UnitTests public void UTtoGST_book() { DateTime dateTime = new DateTime(1980, 04, 22, 14, 36, 51, 670, DateTimeKind.Utc); - double gst = _astroMath.UTtoGst(dateTime); + double gst = dateTime.UTtoGst(); Assert.That(gst, Is.EqualTo(4.667932706211154)); } @@ -61,7 +61,7 @@ namespace AstroMath.UnitTests public void UTtoGst() { DateTime dateTime = new DateTime(2019, 05, 18, 22, 26, 15, DateTimeKind.Utc); - double gst = _astroMath.UTtoGst(dateTime); + double gst = dateTime.UTtoGst(); Assert.That(gst, Is.EqualTo(14.191879687876451)); } diff --git a/Meade.net.Telescope/AstroMaths/AstroMaths.cs b/Meade.net.Telescope/AstroMaths/AstroMaths.cs index f8d7e77..efe0ae8 100644 --- a/Meade.net.Telescope/AstroMaths/AstroMaths.cs +++ b/Meade.net.Telescope/AstroMaths/AstroMaths.cs @@ -1,5 +1,4 @@ using System; -using ASCOM.Utilities; namespace ASCOM.Meade.net.AstroMaths { @@ -10,7 +9,7 @@ namespace ASCOM.Meade.net.AstroMaths public double RightAscensionToHourAngle(DateTime utcDateTime, double longitude, double rightAscension) { //var ut = DateTimeToDecimalHours( utcDateTime); - var gst = UTtoGst( utcDateTime); + var gst = utcDateTime.UTtoGst(); var lst = GsTtoLst( gst, longitude); var raHours = rightAscension; var h1 = lst - raHours; @@ -24,7 +23,7 @@ namespace ASCOM.Meade.net.AstroMaths private double HourAngleToRightAscension(DateTime utcDateTime, double longitude, double hourAngle ) { - var gst = UTtoGst(utcDateTime); + var gst = utcDateTime.UTtoGst(); var lst = GsTtoLst( gst, longitude); var raHours = hourAngle; var h1 = lst - raHours; @@ -39,17 +38,17 @@ namespace ASCOM.Meade.net.AstroMaths public EquatorialCoordinates ConvertHozToEq( DateTime utcDateTime, double latitude, double longitude, HorizonCoordinates altAz) { - var az = DegreesToRadians(altAz.Azimuth); - var alt = DegreesToRadians(altAz.Altitude); - var lat = DegreesToRadians(latitude); + var az = altAz.Azimuth.DegreesToRadians(); + var alt = altAz.Altitude.DegreesToRadians(); + var lat = latitude.DegreesToRadians(); var sinDec = Math.Sin(alt) * Math.Sin(lat) + Math.Cos(alt) * Math.Cos(lat) * Math.Cos(az); - var dec = RadiansToDegrees(Math.Asin(sinDec)); + var dec = Math.Asin(sinDec).RadiansToDegrees(); var y = -Math.Cos(alt) * Math.Cos(lat) * Math.Sin(az); var x = Math.Sin(alt) - Math.Sin(lat) * sinDec; var upperA = Math.Atan2(y,x); - var upperB = RadiansToDegrees(upperA); + var upperB = upperA.RadiansToDegrees(); var ha = upperB; @@ -72,19 +71,20 @@ namespace ASCOM.Meade.net.AstroMaths public HorizonCoordinates ConvertEqToHoz(double hourAngle, double latitude, EquatorialCoordinates raDec) { var h = hourAngle * 15; - var h1 = DegreesToRadians(h); - var d = DegreesToRadians(raDec.Declination); - var lat = DegreesToRadians(latitude); + var h1 = h.DegreesToRadians(); + var d = raDec.Declination.DegreesToRadians(); + var lat = latitude.DegreesToRadians(); var sinA = Math.Sin(d) * Math.Sin(lat) + Math.Cos(d) * Math.Cos(lat) * Math.Cos(h1); var y = -Math.Cos(d) * Math.Cos(lat) * Math.Sin(h1); var x = Math.Sin(d) - Math.Sin(lat) * sinA; var upperA = Math.Atan2(y, x); - var upperB = RadiansToDegrees(upperA); + var upperB = upperA.RadiansToDegrees(); var horizonCoordinates = new HorizonCoordinates { - Altitude = RadiansToDegrees(Math.Asin(sinA)), Azimuth = upperB + Altitude = Math.Asin(sinA).RadiansToDegrees(), + Azimuth = upperB }; @@ -96,82 +96,6 @@ namespace ASCOM.Meade.net.AstroMaths return horizonCoordinates; } - - //todo convert to extension method - public double DegreesToRadians(double degrees) - { - return (Math.PI / 180) * degrees; - } - - //todo convert to extension method - public double RadiansToDegrees(double radians) - { - double degrees = (180 / Math.PI) * radians; - return degrees; - } - - //todo convert to extension method - public double DateTimeToDecimalHours( DateTime utcDateTime) - { - double sec = utcDateTime.Second; - double min = utcDateTime.Minute; - double hour = utcDateTime.Hour; - - var a = Math.Abs(sec) / 60; - var b = (Math.Abs(min) + a) / 60; - var c = Math.Abs(hour) + b; - - var d = c; - - if ((hour < 0) || (min < 0) || (sec < 0)) - d = -c; - - return d; - } - - //todo convert to extension method - public double UTtoGst(DateTime utcDateTime) - { - Util util = new Util(); - - var jd = util.DateUTCToJulian(utcDateTime) - 0.5; - if ((jd % 1) <= 0.5 ) - jd = Math.Floor( jd ); - else - jd = Math.Floor( jd ) + 0.5; - - var s = jd - 2451545.0; - var t = s / 36525.0; - var t0 = 6.697374558 + (2400.051336 * t ) +(0.000025862 * (t * t) ); - - while (t0 < 0) - { - t0 += 24; - } - - while (t0 >= 24) - { - t0 -= 24; - } - - var ut = DateTimeToDecimalHours(utcDateTime); - var a = ut * 1.002737909; - - var t1 = t0 + a; - - while (t1 < 0) - { - t1 += 24; - } - - while (t1 >= 24) - { - t1 -= 24; - } - - return t1; - } - public double GsTtoLst(double gst, double longitude) { var l = longitude/ 15; @@ -189,4 +113,4 @@ namespace ASCOM.Meade.net.AstroMaths return lst; } } -} +} \ No newline at end of file diff --git a/Meade.net.Telescope/Meade.net.Telescope.csproj b/Meade.net.Telescope/Meade.net.Telescope.csproj index cc2feb8..9553298 100644 --- a/Meade.net.Telescope/Meade.net.Telescope.csproj +++ b/Meade.net.Telescope/Meade.net.Telescope.csproj @@ -116,6 +116,7 @@ + diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 4727742..5cc639c 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -872,7 +872,7 @@ namespace ASCOM.Meade.net LogMessage("Altitude", $"{altAz.Altitude}"); return altAz.Altitude; - ////todo firmware bug in 44Eg, :GA# is returning the dec, not the altitude! + //firmware bug in 44Eg, :GA# is returning the dec, not the altitude! //var result = _sharedResourcesWrapper.SendString("#:GA#"); ////:GA# Get Telescope Altitude ////Returns: sDD* MM# or sDD*MM’SS#