Implemenated a few todo notes

This commit is contained in:
2020-09-03 13:11:47 +01:00
parent 8d097fefe1
commit f9792b22bc
4 changed files with 22 additions and 97 deletions
+6 -6
View File
@@ -18,14 +18,14 @@ namespace AstroMath.UnitTests
[Test] [Test]
public void DegreesToRadians() public void DegreesToRadians()
{ {
var radians = _astroMath.DegreesToRadians(90); var radians = 90.0.DegreesToRadians();
Assert.That(radians, Is.EqualTo(1.5707963267948966)); Assert.That(radians, Is.EqualTo(1.5707963267948966));
} }
[Test] [Test]
public void RadiansToDegrees() public void RadiansToDegrees()
{ {
var degrees = _astroMath.RadiansToDegrees(1.5707963267948966); var degrees = 1.5707963267948966.RadiansToDegrees();
Assert.That(degrees, Is.EqualTo(90)); Assert.That(degrees, Is.EqualTo(90));
} }
@@ -34,7 +34,7 @@ namespace AstroMath.UnitTests
public void DateTimeToDecimalHours_book() public void DateTimeToDecimalHours_book()
{ {
DateTime dateTime = new DateTime(2019, 05, 18, 18, 31, 27, DateTimeKind.Utc); 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)); Assert.That(decimalHours, Is.EqualTo(18.524166666666666));
} }
@@ -43,7 +43,7 @@ namespace AstroMath.UnitTests
public void DateTimeToDecimalHours() public void DateTimeToDecimalHours()
{ {
DateTime dateTime = new DateTime(2019, 05, 18, 22, 26, 15, DateTimeKind.Utc); 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)); Assert.That(decimalHours, Is.EqualTo(22.4375));
} }
@@ -52,7 +52,7 @@ namespace AstroMath.UnitTests
public void UTtoGST_book() public void UTtoGST_book()
{ {
DateTime dateTime = new DateTime(1980, 04, 22, 14, 36, 51, 670, DateTimeKind.Utc); 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)); Assert.That(gst, Is.EqualTo(4.667932706211154));
} }
@@ -61,7 +61,7 @@ namespace AstroMath.UnitTests
public void UTtoGst() public void UTtoGst()
{ {
DateTime dateTime = new DateTime(2019, 05, 18, 22, 26, 15, DateTimeKind.Utc); 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)); Assert.That(gst, Is.EqualTo(14.191879687876451));
} }
+14 -90
View File
@@ -1,5 +1,4 @@
using System; using System;
using ASCOM.Utilities;
namespace ASCOM.Meade.net.AstroMaths namespace ASCOM.Meade.net.AstroMaths
{ {
@@ -10,7 +9,7 @@ namespace ASCOM.Meade.net.AstroMaths
public double RightAscensionToHourAngle(DateTime utcDateTime, double longitude, double rightAscension) public double RightAscensionToHourAngle(DateTime utcDateTime, double longitude, double rightAscension)
{ {
//var ut = DateTimeToDecimalHours( utcDateTime); //var ut = DateTimeToDecimalHours( utcDateTime);
var gst = UTtoGst( utcDateTime); var gst = utcDateTime.UTtoGst();
var lst = GsTtoLst( gst, longitude); var lst = GsTtoLst( gst, longitude);
var raHours = rightAscension; var raHours = rightAscension;
var h1 = lst - raHours; var h1 = lst - raHours;
@@ -24,7 +23,7 @@ namespace ASCOM.Meade.net.AstroMaths
private double HourAngleToRightAscension(DateTime utcDateTime, double longitude, double hourAngle ) private double HourAngleToRightAscension(DateTime utcDateTime, double longitude, double hourAngle )
{ {
var gst = UTtoGst(utcDateTime); var gst = utcDateTime.UTtoGst();
var lst = GsTtoLst( gst, longitude); var lst = GsTtoLst( gst, longitude);
var raHours = hourAngle; var raHours = hourAngle;
var h1 = lst - raHours; var h1 = lst - raHours;
@@ -39,17 +38,17 @@ namespace ASCOM.Meade.net.AstroMaths
public EquatorialCoordinates ConvertHozToEq( DateTime utcDateTime, double latitude, double longitude, HorizonCoordinates altAz) public EquatorialCoordinates ConvertHozToEq( DateTime utcDateTime, double latitude, double longitude, HorizonCoordinates altAz)
{ {
var az = DegreesToRadians(altAz.Azimuth); var az = altAz.Azimuth.DegreesToRadians();
var alt = DegreesToRadians(altAz.Altitude); var alt = altAz.Altitude.DegreesToRadians();
var lat = DegreesToRadians(latitude); var lat = latitude.DegreesToRadians();
var sinDec = Math.Sin(alt) * Math.Sin(lat) + Math.Cos(alt) * Math.Cos(lat) * Math.Cos(az); 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 y = -Math.Cos(alt) * Math.Cos(lat) * Math.Sin(az);
var x = Math.Sin(alt) - Math.Sin(lat) * sinDec; var x = Math.Sin(alt) - Math.Sin(lat) * sinDec;
var upperA = Math.Atan2(y,x); var upperA = Math.Atan2(y,x);
var upperB = RadiansToDegrees(upperA); var upperB = upperA.RadiansToDegrees();
var ha = upperB; var ha = upperB;
@@ -72,19 +71,20 @@ namespace ASCOM.Meade.net.AstroMaths
public HorizonCoordinates ConvertEqToHoz(double hourAngle, double latitude, EquatorialCoordinates raDec) public HorizonCoordinates ConvertEqToHoz(double hourAngle, double latitude, EquatorialCoordinates raDec)
{ {
var h = hourAngle * 15; var h = hourAngle * 15;
var h1 = DegreesToRadians(h); var h1 = h.DegreesToRadians();
var d = DegreesToRadians(raDec.Declination); var d = raDec.Declination.DegreesToRadians();
var lat = DegreesToRadians(latitude); var lat = latitude.DegreesToRadians();
var sinA = Math.Sin(d) * Math.Sin(lat) + Math.Cos(d) * Math.Cos(lat) * Math.Cos(h1); 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 y = -Math.Cos(d) * Math.Cos(lat) * Math.Sin(h1);
var x = Math.Sin(d) - Math.Sin(lat) * sinA; var x = Math.Sin(d) - Math.Sin(lat) * sinA;
var upperA = Math.Atan2(y, x); var upperA = Math.Atan2(y, x);
var upperB = RadiansToDegrees(upperA); var upperB = upperA.RadiansToDegrees();
var horizonCoordinates = new HorizonCoordinates 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; 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) public double GsTtoLst(double gst, double longitude)
{ {
var l = longitude/ 15; var l = longitude/ 15;
@@ -189,4 +113,4 @@ namespace ASCOM.Meade.net.AstroMaths
return lst; return lst;
} }
} }
} }
@@ -116,6 +116,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="AstroMaths\AltitudeData.cs" /> <Compile Include="AstroMaths\AltitudeData.cs" />
<Compile Include="AstroMaths\AstroMathExtensions.cs" />
<Compile Include="AstroMaths\AstroMaths.cs" /> <Compile Include="AstroMaths\AstroMaths.cs" />
<Compile Include="AstroMaths\EquatorialCoordinates.cs" /> <Compile Include="AstroMaths\EquatorialCoordinates.cs" />
<Compile Include="AstroMaths\HorizonCoordinates.cs" /> <Compile Include="AstroMaths\HorizonCoordinates.cs" />
+1 -1
View File
@@ -872,7 +872,7 @@ namespace ASCOM.Meade.net
LogMessage("Altitude", $"{altAz.Altitude}"); LogMessage("Altitude", $"{altAz.Altitude}");
return 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#"); //var result = _sharedResourcesWrapper.SendString("#:GA#");
////:GA# Get Telescope Altitude ////:GA# Get Telescope Altitude
////Returns: sDD* MM# or sDD*MMSS# ////Returns: sDD* MM# or sDD*MMSS#