-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmainwindow.cpp
executable file
·268 lines (211 loc) · 9.91 KB
/
mainwindow.cpp
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "aaplus/AA+.h"
#include <cstdio>
#include <cmath>
#include <QDebug>
#include "options.h"
extern Options opts;
static inline double MapToMinus180To180Range(double Degrees)
{
double fResult = CAACoordinateTransformation::MapTo0To360Range(Degrees);
if (fResult > 180)
fResult = fResult - 360;
return fResult;
}
void HoursTohms(double inhours, int &hours, int &minutes, int &seconds)
{
hours = (int)(inhours);
double drest = inhours - hours;
int bla = (int)(drest*3600.0);
minutes = bla/60;
seconds = bla%60;
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
qDebug() << "opts.geolastsat = " << opts.geosatindex;
scale = 20;
scene = new GridScene(-1000, -1000, 2000, 2000, scale);
z = new Graphics_view_zoom(ui->graphicsView);
z->set_modifiers(Qt::NoModifier);
ui->graphicsView->setScene(scene);
//ui->graphicsView->setRenderHint(QPainter::Antialiasing);
QBrush moonBrush(Qt::yellow);
QBrush earthBrush(Qt::blue);
QPen blackpen(Qt::black);
blackpen.setWidth(1);
earth = scene->addEllipse(-8.7*scale, -8.7*scale, 17.4*scale, 17.4*scale,blackpen, earthBrush);
earth->setZValue(-1);
//CalcMoon(ui->calendarWidget->selectedDate());
connect(ui->calendarWidget, SIGNAL(clicked(QDate)), this, SLOT(CalcMoon(QDate)));
SetupCombo();
ui->cmbGeoSat->setCurrentIndex(opts.geosatindex);
ui->rdb10min->setChecked(true);
//QString strlon = opts.geostationarylistlon.at(ui->cmbGeoSat->currentIndex());
QStringList::Iterator itslon = opts.geostationarylistlon.begin();
while( itslon != opts.geostationarylistlon.end() )
{
// For AA+ longitudes West are positive, hence 180.0 - lon;
//qDebug() << QString("name = %1").arg(*itsname);
double opposietlong = MapToMinus180To180Range(180 - (*itslon).toFloat());
qDebug() << "lon = " << (*itslon) << " opposietlong = " << opposietlong;
geolonlist << opposietlong;
++itslon;
}
}
void MainWindow::SetupCombo()
{
QStringList items;
for (int i = 0; i < opts.geostationarylistname.size(); ++i)
{
float lon = opts.geostationarylistlon.at(i).toFloat();
QString eastwest = lon > 0 ? "E" : "W";
items << QString("%1 %2 %3").arg(opts.geostationarylistname.at(i)).arg(fabs(lon)).arg(eastwest);
}
ui->cmbGeoSat->addItems(items);
}
void MainWindow::CalcMoon(QDate selected)
{
double hours, minutes;
int day, year, month;
int min;
if(ui->rdb10min->isChecked())
min = 10;
else
min = 15;
year = selected.year();
month = selected.month();
day = selected.day();
QBrush moonBrush(Qt::yellow);
QPen blackpen(Qt::black);
blackpen.setWidth(1);
while (!moonlist.isEmpty())
scene->removeItem(moonlist.takeFirst());
moonlist.clear();
while (!textlist.isEmpty())
scene->removeItem(textlist.takeFirst());
scene->update();
textlist.clear();
qDebug() << QString("Calculating for satellite at %1°").arg(geolonlist.at(geosatindex));
ui->listWidget->clear();
for( int hours = 0; hours < 24; hours++)
{
for( int minutes = 0; minutes < 60; minutes += min)
{
double dday = static_cast<double>(day) + static_cast<double>(hours)/24.0 + static_cast<double>(minutes)/(24.0*60.0);
double JD = CAADate::DateToJD(year, month, dday, true);
double JDMoon = CAADynamicalTime::UTC2TT(JD);
double MoonLong = CAAELP2000::EclipticLongitude(JDMoon);
double MoonLat = CAAELP2000::EclipticLatitude(JDMoon);
int MoonLongdeg, MoonLongmin, MoonLongsec;
int MoonLatdeg, MoonLatmin, MoonLatsec;
HoursTohms(MoonLong, MoonLongdeg, MoonLongmin, MoonLongsec);
HoursTohms(MoonLat, MoonLatdeg, MoonLatmin, MoonLatsec);
CAA2DCoordinate Equatorial = CAACoordinateTransformation::Ecliptic2Equatorial(MoonLong, MoonLat, CAANutation::TrueObliquityOfEcliptic(JDMoon));
double MoonRad = CAAELP2000::RadiusVector(JDMoon);
//MoonRad /= 149597870.691; //Convert KM to AU
double AST = CAASidereal::ApparentGreenwichSiderealTime(JDMoon);
double LongtitudeAsHourAngle = CAACoordinateTransformation::DegreesToHours( geolonlist.at(geosatindex) );
double LocalHourAngle = AST - LongtitudeAsHourAngle - Equatorial.X;
double LHA = CAACoordinateTransformation::MapTo0To24Range(LocalHourAngle);
int LHAhour, LHAmin, LHAsec;
HoursTohms(LHA, LHAhour, LHAmin, LHAsec);
int DEdeg, DEmin, DEsec;
HoursTohms(Equatorial.Y, DEdeg, DEmin, DEsec);
int RAhour, RAmin, RAsec;
HoursTohms(Equatorial.X, RAhour, RAmin, RAsec);
//printf("%d/%d/%d %2d:%02d UTC Ecliptic long = %02d°%02d'%02d\" lat = %02d°%02d'%02d\" RA = %02dh%02dm%02ds localHourAngle = %02dh%02dm%02ds DE = %02d°%02d'%02d\" MoonRad = %f\n",
// year, month, day, hours, minutes, MoonLongdeg, MoonLongmin, MoonLongsec, MoonLatdeg, MoonLatmin, MoonLatsec, RAhour, RAmin, RAsec, LHAhour, LHAmin, LHAsec, DEdeg, DEmin, DEsec, MoonRad);
double diffangle = 20.0;
double HourAngleDegrees = MapToMinus180To180Range(CAACoordinateTransformation::HoursToDegrees(LHA));
double DecLHA = sqrt(HourAngleDegrees * HourAngleDegrees + Equatorial.Y * Equatorial.Y);
double parallax = 5.92 * sin(CAACoordinateTransformation::DegreesToRadians(DecLHA));
double deltaY = Equatorial.Y*parallax/DecLHA;
double deltaX = HourAngleDegrees*parallax/DecLHA;
double illuminated_fraction = 0;
double position_angle = 0;
double phase_angle = 0;
GetMoonIllumination(JD, true, illuminated_fraction, position_angle, phase_angle);
if(HourAngleDegrees - deltaX > -diffangle && HourAngleDegrees - deltaX < diffangle && Equatorial.Y - deltaY < diffangle && Equatorial.Y - deltaY > -diffangle)
{
printf("==%d/%d/%d %2d:%02d UTC Ecliptic long = %f° lat = %f° RA = %fh DE = %f° localHourAngle = %f° AST = %f MoonRad = %f parallax = %f\n",
year, month, day, hours, minutes, MoonLong, MoonLat, Equatorial.X, Equatorial.Y, HourAngleDegrees, AST, MoonRad, parallax);
fflush(stdout);
int mooncoordX = (int)((HourAngleDegrees - deltaX) * scale);
int mooncoordY = - (int)((Equatorial.Y - deltaY) * scale);
moonlist.append(scene->addEllipse(mooncoordX - 0.25*scale, mooncoordY - 0.25*scale, 0.5*scale, 0.5*scale, blackpen, moonBrush));
QGraphicsTextItem *text = scene->addText(QString("%1:%2").arg(hours, 2, 'f', 0, '0').arg(minutes, 2, 'f', 0, '0'));
textlist.append(text);
text->setPos(mooncoordX-scale, mooncoordY+0.5*scale);
int ilfraction = static_cast<int>((illuminated_fraction * 100) + 0.5);
ui->listWidget->addItem(new QListWidgetItem(QString("%1:%2 illumination = %3 ").arg(hours, 2, 'f', 0, '0').arg(minutes, 2, 'f', 0, '0').arg(ilfraction), ui->listWidget));
}
// else
// {
// printf("%d/%d/%d %2d:%02d UTC Ecliptic long = %f° lat = %f° RA = %fh DE = %f° localHourAngle = %f° AST = %f MoonRad = %f parallax = %f\n",
// year, month, day, hours, minutes, MoonLong, MoonLat, Equatorial.X, Equatorial.Y, HourAngleDegrees, AST, MoonRad, parallax);
// fflush(stdout);
// }
}
}
ui->graphicsView->update();
}
void MainWindow::GetMoonIllumination(double JD, bool bHighPrecision, double& illuminated_fraction, double& position_angle, double& phase_angle)
{
double moon_alpha{0};
double moon_delta{0};
GetLunarRaDecByJulian(JD, moon_alpha, moon_delta);
double sun_alpha{0};
double sun_delta{0};
GetSolarRaDecByJulian(JD, bHighPrecision, sun_alpha, sun_delta);
const double geo_elongation{CAAMoonIlluminatedFraction::GeocentricElongation(moon_alpha, moon_delta, sun_alpha, sun_delta)};
position_angle = CAAMoonIlluminatedFraction::PositionAngle(sun_alpha, sun_delta, moon_alpha, moon_delta);
phase_angle = CAAMoonIlluminatedFraction::PhaseAngle(geo_elongation, 368410.0, 149971520.0);
illuminated_fraction = CAAMoonIlluminatedFraction::IlluminatedFraction(phase_angle);
}
void MainWindow::GetLunarRaDecByJulian(double JD, double& RA, double& Dec)
{
const double JDMoon{CAADynamicalTime::UTC2TT(JD)};
const double lambda{CAAMoon::EclipticLongitude(JDMoon)};
const double beta{CAAMoon::EclipticLatitude(JDMoon)};
const double epsilon{CAANutation::TrueObliquityOfEcliptic(JDMoon)};
CAA2DCoordinate Lunarcoord{CAACoordinateTransformation::Ecliptic2Equatorial(lambda, beta, epsilon)};
RA = Lunarcoord.X;
Dec = Lunarcoord.Y;
}
void MainWindow::GetSolarRaDecByJulian(double JD, bool bHighPrecision, double& RA, double& Dec)
{
const double JDSun{CAADynamicalTime::UTC2TT(JD)};
const double lambda{CAASun::ApparentEclipticLongitude(JDSun, bHighPrecision)};
const double beta{CAASun::ApparentEclipticLatitude(JDSun, bHighPrecision)};
const double epsilon{CAANutation::TrueObliquityOfEcliptic(JDSun)};
CAA2DCoordinate Solarcoord{CAACoordinateTransformation::Ecliptic2Equatorial(lambda, beta, epsilon)};
RA = Solarcoord.X;
Dec = Solarcoord.Y;
}
MainWindow::~MainWindow()
{
opts.geosatindex = ui->cmbGeoSat->currentIndex();
opts.Save();
delete ui;
}
void MainWindow::on_actionExit_triggered()
{
this->close();
}
void MainWindow::on_cmbGeoSat_currentIndexChanged(int index)
{
geosatindex = index;
qDebug() << "on_cmbGeoSat geolastsat = " << index;
}
void MainWindow::on_rdb10min_clicked()
{
this->CalcMoon(ui->calendarWidget->selectedDate());
}
void MainWindow::on_rdb15min_clicked()
{
this->CalcMoon(ui->calendarWidget->selectedDate());
}