-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAstroCalc.cs
183 lines (145 loc) · 6.3 KB
/
AstroCalc.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ASCOM.Astrometry;
using ASCOM.Utilities;
using CefSharp.Structs;
namespace EAACtrl
{
internal class AstroCalc
{
public void J2000ToJNOW(double RA2000, double Dec2000, out double RANOW, out double DecNOW, bool Apparent = false)
{
ASCOM.Astrometry.Transform.Transform T = new ASCOM.Astrometry.Transform.Transform();
ASCOM.Utilities.Util U = new ASCOM.Utilities.Util();
T.SiteLatitude = Properties.Settings.Default.SiteLat;
T.SiteLongitude = Properties.Settings.Default.SiteLng;
T.SiteElevation = Properties.Settings.Default.SiteElev;
T.SiteTemperature = 20.0;
T.JulianDateTT = U.DateLocalToJulian(DateTime.Now);
T.SetJ2000(RA2000, Dec2000);
if (Apparent)
{
RANOW = T.RAApparent;
DecNOW = T.DECApparent;
}
else
{
RANOW = T.RATopocentric;
DecNOW = T.DECTopocentric;
}
T.Dispose();
}
public void JNOWToJ2000(double RANOW, double DecNOW, out double RA2000, out double Dec2000)
{
ASCOM.Astrometry.Transform.Transform T = new ASCOM.Astrometry.Transform.Transform();
ASCOM.Utilities.Util U = new ASCOM.Utilities.Util();
T.SiteLatitude = Properties.Settings.Default.SiteLat;
T.SiteLongitude = Properties.Settings.Default.SiteLng;
T.SiteElevation = Properties.Settings.Default.SiteElev;
T.SiteTemperature = 20.0;
T.JulianDateTT = U.DateLocalToJulian(DateTime.Now);
T.SetTopocentric(RANOW, DecNOW);
RA2000 = T.RAJ2000;
Dec2000 = T.DecJ2000;
T.Dispose();
}
public bool J2000ToAltAz(double RA, double Dec, out double Altitude, out double Azimuth)
{
bool bResult = false;
Altitude = 999; Azimuth = 999;
try
{
ASCOM.Utilities.Util U = new ASCOM.Utilities.Util();
ASCOM.Astrometry.Transform.Transform T = new ASCOM.Astrometry.Transform.Transform();
T.SiteLatitude = Properties.Settings.Default.SiteLat;
T.SiteLongitude = Properties.Settings.Default.SiteLng;
T.SiteElevation = Properties.Settings.Default.SiteElev;
T.SiteTemperature = 20.0;
T.JulianDateTT = U.DateLocalToJulian(DateTime.Now);
T.SetJ2000(RA, Dec);
Altitude = T.ElevationTopocentric;
Azimuth = T.AzimuthTopocentric;
bResult = true;
}
catch {}
return bResult;
}
public bool JNOWToAltAz(double RA, double Dec, out double Altitude, out double Azimuth)
{
bool bResult = false;
Altitude = 999; Azimuth = 999;
try
{
ASCOM.Utilities.Util U = new ASCOM.Utilities.Util();
ASCOM.Astrometry.Transform.Transform T = new ASCOM.Astrometry.Transform.Transform();
T.SiteLatitude = Properties.Settings.Default.SiteLat;
T.SiteLongitude = Properties.Settings.Default.SiteLng;
T.SiteElevation = Properties.Settings.Default.SiteElev;
T.SiteTemperature = 20.0;
T.JulianDateTT = U.DateLocalToJulian(DateTime.Now);
T.SetTopocentric(RA, Dec);
Altitude = T.ElevationTopocentric;
Azimuth = T.AzimuthTopocentric;
bResult = true;
}
catch { }
return bResult;
}
public List<(double,double)> BoundingBox(double CentreRA, double CentreDec, double Height, double Width)
{
List<(double, double)> BoundingPolygonRough = new List<(double, double)>();
List<(double, double)> BoundingPolygon = new List<(double, double)>();
BoundingPolygonRough.Add((CentreRA - Width / 2.0, CentreDec + Height / 2.0));
BoundingPolygonRough.Add((CentreRA + Width / 2.0, CentreDec + Height / 2.0));
BoundingPolygonRough.Add((CentreRA + Width / 2.0, CentreDec - Height / 2.0));
BoundingPolygonRough.Add((CentreRA - Width / 2.0, CentreDec - Height / 2.0));
BoundingPolygonRough.Add((CentreRA - Width / 2.0, CentreDec + Height / 2.0));
foreach (var polygon in BoundingPolygonRough)
{
double RA = polygon.Item1;
double Dec= polygon.Item2;
// Check RA does not exceed bounds
if (polygon.Item1 < 0)
{
RA = 360.0 + polygon.Item1;
}
else if (polygon.Item1 > 360)
{
RA = polygon.Item1-360.0;
}
// Check if Dec does not exceed bounds
if (polygon.Item2 > 90)
{
Dec = (polygon.Item2 - 90.0)-90.0;
}
else if (polygon.Item2 < -90.0)
{
Dec = (Math.Abs(polygon.Item2) - 90.0)+-90.0;
}
BoundingPolygon.Add((RA,Dec));
}
return BoundingPolygon;
}
// From ASCOMPlateAlign v1.1
public double DeltaFromTwoRADec(double RA1, double Dec1, double RA2, double Dec2, bool RAInDegrees = true)
{
// Use Haversine for small angles
double D1 = (Dec1) * Math.PI / 180.0;
double D2 = (Dec2) * Math.PI / 180.0;
//RA is in Hours, Convert to radians
double DeltaRA = (RA2 - RA1) * Math.PI / 12.0;
if (RAInDegrees) DeltaRA *= 12.0 / 180.0;
double Sin_2_Dec = Math.Sin(0.5 * (D2 - D1));
Sin_2_Dec *= Sin_2_Dec;
double Sin_2_RA = Math.Sin(0.5 * DeltaRA);
Sin_2_RA *= Sin_2_RA;
double HalfSinDelta = Sin_2_Dec + Math.Cos(D1) * Math.Cos(D2) * Sin_2_RA;
HalfSinDelta = Math.Sqrt(HalfSinDelta);
double Delta = 2.0 * Math.Asin(HalfSinDelta) * 180D / Math.PI;
return Delta;
}
}
}