| 1 | //
|
|---|
| 2 | // This File contains the definition of the MGCoordinates-class
|
|---|
| 3 | //
|
|---|
| 4 | // Author: Thomas Bretz
|
|---|
| 5 | // Version: V1.0 (1-8-2000)
|
|---|
| 6 |
|
|---|
| 7 | #include "MGSkyPosition.h"
|
|---|
| 8 |
|
|---|
| 9 | #include <iostream.h> // cout
|
|---|
| 10 |
|
|---|
| 11 | #include <TArc.h>
|
|---|
| 12 | #include <TLine.h>
|
|---|
| 13 | #include <TText.h>
|
|---|
| 14 | #include <TList.h>
|
|---|
| 15 | #include <TCanvas.h>
|
|---|
| 16 |
|
|---|
| 17 | #include "coord.h"
|
|---|
| 18 | #include "SlaStars.h"
|
|---|
| 19 | #include "SlaPlanets.h"
|
|---|
| 20 |
|
|---|
| 21 | ClassImp(MGSkyPosition);
|
|---|
| 22 |
|
|---|
| 23 | void MGSkyPosition::InitArc(TArc *arc, Int_t fillstyle, Int_t fillcolor, Int_t linecolor)
|
|---|
| 24 | {
|
|---|
| 25 | arc->SetFillStyle(fillstyle); // (s. TAttFill)
|
|---|
| 26 | arc->SetFillColor(fillcolor); // (s. TAttFill)
|
|---|
| 27 | arc->SetLineColor(linecolor);
|
|---|
| 28 | arc->Draw();
|
|---|
| 29 | }
|
|---|
| 30 |
|
|---|
| 31 | void MGSkyPosition::InitPlanets()
|
|---|
| 32 | {
|
|---|
| 33 | //
|
|---|
| 34 | // Magnitudes:
|
|---|
| 35 | // -----------
|
|---|
| 36 | // Moon -12.8
|
|---|
| 37 | // Jupiter -4.6
|
|---|
| 38 | // Venus -4.0
|
|---|
| 39 | // Mars -2.0
|
|---|
| 40 | // Merkur 0.0
|
|---|
| 41 | // Saturn 0.7
|
|---|
| 42 | // Uranus 5.5
|
|---|
| 43 | // Neptun 7.8
|
|---|
| 44 | //
|
|---|
| 45 | fSlaPlanet = new SlaPlanets;
|
|---|
| 46 | fSlaStar = new SlaStars;
|
|---|
| 47 |
|
|---|
| 48 | //
|
|---|
| 49 | // Colors: black .. white:
|
|---|
| 50 | //
|
|---|
| 51 | // 1, 12, 13, 14, 15, 16, 17, 18, 19, 10
|
|---|
| 52 | //
|
|---|
| 53 | fMars = new TArc(0, 0, 1);
|
|---|
| 54 | fVenus = new TArc(0, 0, 2);
|
|---|
| 55 | fJupiter = new TArc(0, 0, 2);
|
|---|
| 56 | fMoon = new TArc(0, 0, 3, 290, 70);
|
|---|
| 57 | fSun = new TArc(0, 0, 2);
|
|---|
| 58 |
|
|---|
| 59 | InitArc(fMars, 1001, 13, 12);
|
|---|
| 60 | InitArc(fVenus, 1001, 15, 14);
|
|---|
| 61 | InitArc(fJupiter, 1001, 17, 16);
|
|---|
| 62 | InitArc(fMoon, 1001, 19, 15);
|
|---|
| 63 | InitArc(fSun, 1001, 10, 19);
|
|---|
| 64 |
|
|---|
| 65 | for (int i=0; i<4; i++)
|
|---|
| 66 | {
|
|---|
| 67 | fSunL[i] = new TLine(0,0,0,0);
|
|---|
| 68 | fSunL[i]->SetLineColor(10); // white gray
|
|---|
| 69 | fSunL[i]->SetLineStyle(1); // solid (s. TAttLine)
|
|---|
| 70 | fSunL[i]->Draw();
|
|---|
| 71 |
|
|---|
| 72 | fList->Add(fSunL[i]);
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | fList->Add(fMars);
|
|---|
| 76 | fList->Add(fVenus);
|
|---|
| 77 | fList->Add(fJupiter);
|
|---|
| 78 | fList->Add(fMoon);
|
|---|
| 79 | fList->Add(fSun);
|
|---|
| 80 |
|
|---|
| 81 | //
|
|---|
| 82 | // Reset 'static' positions of planets
|
|---|
| 83 | //
|
|---|
| 84 | for (int i=0; i<9; i++)
|
|---|
| 85 | {
|
|---|
| 86 | fX[i] = ~0;
|
|---|
| 87 | fY[i] = ~0;
|
|---|
| 88 | }
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | void MGSkyPosition::InitText()
|
|---|
| 92 | {
|
|---|
| 93 | fText = new TText(105, 105, "");
|
|---|
| 94 | //fText->SetFillStyle(4000); // transparent
|
|---|
| 95 | fText->SetTextAlign(33); // right, top
|
|---|
| 96 | fText->SetTextColor(10); // white
|
|---|
| 97 | fText->Draw();
|
|---|
| 98 |
|
|---|
| 99 | fList->Add(fText);
|
|---|
| 100 | }
|
|---|
| 101 |
|
|---|
| 102 | void MGSkyPosition::DrawCoordinateSystem()
|
|---|
| 103 | {
|
|---|
| 104 | TArc arc;
|
|---|
| 105 | arc.SetFillStyle(4000); // transparent
|
|---|
| 106 | arc.SetLineColor(13); // dark gray
|
|---|
| 107 | arc.SetLineStyle(1); // solid (s. TAttLine)
|
|---|
| 108 | arc.DrawArc(0, 0, 90);
|
|---|
| 109 | arc.DrawArc(0, 0, 67.5);
|
|---|
| 110 | arc.DrawArc(0, 0, 45);
|
|---|
| 111 | arc.DrawArc(0, 0, 22.5);
|
|---|
| 112 |
|
|---|
| 113 | //
|
|---|
| 114 | // FIXME? Use TAxis?
|
|---|
| 115 | //
|
|---|
| 116 | TLine line;
|
|---|
| 117 | line.SetLineColor(1); // black
|
|---|
| 118 | line.SetLineStyle(1); // solid (s. TAttLine)
|
|---|
| 119 | line.DrawLine(-95, 0, 95, 0);
|
|---|
| 120 | line.DrawLine( 0, -95, 0, 95);
|
|---|
| 121 |
|
|---|
| 122 | TText text;
|
|---|
| 123 | text.SetTextAlign(22); // centered, centered (s.TAttText)
|
|---|
| 124 | text.SetTextColor(13); // dark gray
|
|---|
| 125 | text.DrawText(0.71*22.5, 0.71*22.5, "22.5\xb0");
|
|---|
| 126 | text.DrawText(0.71*45.0, 0.71*45.0, "45\xb0");
|
|---|
| 127 | text.DrawText(0.71*67.5, 0.71*67.5, "67.5\xb0");
|
|---|
| 128 | text.DrawText(0.71*90.0, 0.71*90.0, "90\xb0");
|
|---|
| 129 |
|
|---|
| 130 | text.SetTextAlign(22); // centered, centered (s.TAttText)
|
|---|
| 131 | text.SetTextColor(1); // black
|
|---|
| 132 |
|
|---|
| 133 | text.DrawText(0, 102, "N (0\xb0)");
|
|---|
| 134 | text.DrawText(0, -102, "S (180\xb0)");
|
|---|
| 135 |
|
|---|
| 136 | text.SetTextAngle(270);
|
|---|
| 137 | text.DrawText( 102, 0, "E (90\xb0)");
|
|---|
| 138 |
|
|---|
| 139 | text.SetTextAngle(90);
|
|---|
| 140 | text.DrawText(-102, 0, "W (270\xb0)");
|
|---|
| 141 | }
|
|---|
| 142 |
|
|---|
| 143 | void MGSkyPosition::InitPosition()
|
|---|
| 144 | {
|
|---|
| 145 | fLin1a = new TLine(0, 0, 0, 0);
|
|---|
| 146 | fLin1b = new TLine(0, 0, 0, 0);
|
|---|
| 147 | fLin2 = new TLine(0, 0, 0, 0);
|
|---|
| 148 |
|
|---|
| 149 | fLin1a->SetLineColor(5); // yellow (s. TAttFill)
|
|---|
| 150 | fLin1b->SetLineColor(5); // yellow
|
|---|
| 151 | fLin2 ->SetLineColor(10); // white
|
|---|
| 152 | fLin1a->SetLineStyle(1); // solid (s. TAttLine)
|
|---|
| 153 | fLin1b->SetLineStyle(2); // dashed
|
|---|
| 154 |
|
|---|
| 155 | fLin1a->Draw();
|
|---|
| 156 | fLin1b->Draw();
|
|---|
| 157 | fLin2->Draw();
|
|---|
| 158 |
|
|---|
| 159 | fList->Add(fLin1a);
|
|---|
| 160 | fList->Add(fLin1b);
|
|---|
| 161 | fList->Add(fLin2);
|
|---|
| 162 |
|
|---|
| 163 | for (int i=0; i<6; i++)
|
|---|
| 164 | {
|
|---|
| 165 | fDot[i] = new TArc(0, 0, 1);
|
|---|
| 166 | InitArc(fDot[i], 1001, 10, 19);
|
|---|
| 167 | fList->Add(fDot[i]);
|
|---|
| 168 | }
|
|---|
| 169 | }
|
|---|
| 170 |
|
|---|
| 171 | MGSkyPosition::MGSkyPosition(const TGWindow* p, const UInt_t w)
|
|---|
| 172 | : MGEmbeddedCanvas("SkyPosition", p, w, 110)
|
|---|
| 173 | {
|
|---|
| 174 | cout << "MGSkyPosition: Initilizing." << endl;
|
|---|
| 175 | DrawCoordinateSystem();
|
|---|
| 176 | InitPlanets();
|
|---|
| 177 | InitPosition();
|
|---|
| 178 | InitText();
|
|---|
| 179 | InitCanvas();
|
|---|
| 180 | cout << "MGSkyPosition: Initilizing done." << endl;
|
|---|
| 181 | }
|
|---|
| 182 |
|
|---|
| 183 | MGSkyPosition::~MGSkyPosition()
|
|---|
| 184 | {
|
|---|
| 185 | delete fSlaPlanet;
|
|---|
| 186 | delete fSlaStar;
|
|---|
| 187 |
|
|---|
| 188 | cout << "MGSkyPosition destroyed." << endl;
|
|---|
| 189 | }
|
|---|
| 190 |
|
|---|
| 191 | void MGSkyPosition::SetLin1(Float_t x, Float_t y)
|
|---|
| 192 | {
|
|---|
| 193 | fLin1a->SetX2(x);
|
|---|
| 194 | fLin1a->SetY2(y);
|
|---|
| 195 | fLin1b->SetX2(-x);
|
|---|
| 196 | fLin1b->SetY2(-y);
|
|---|
| 197 | }
|
|---|
| 198 |
|
|---|
| 199 | void MGSkyPosition::SetLin2(Float_t x1, Float_t y1, Float_t x2, Float_t y2)
|
|---|
| 200 | {
|
|---|
| 201 | fLin2->SetX1(x1);
|
|---|
| 202 | fLin2->SetX2(x2);
|
|---|
| 203 | fLin2->SetY1(y1);
|
|---|
| 204 | fLin2->SetY2(y2);
|
|---|
| 205 | }
|
|---|
| 206 |
|
|---|
| 207 | void MGSkyPosition::SetDot(TArc *arc, RaDec &radec, Int_t off)
|
|---|
| 208 | {
|
|---|
| 209 | RaDec rd(radec.Ra()+off*360/24*kDeg2Rad, radec.Dec());
|
|---|
| 210 | ZdAz zdaz = fSlaStar->CalcZdAzFast(rd);
|
|---|
| 211 |
|
|---|
| 212 | const float s = sin(zdaz.Az());
|
|---|
| 213 | const float c = cos(zdaz.Az());
|
|---|
| 214 |
|
|---|
| 215 | const float x = s*zdaz.Zd()*kRad2Deg; // [deg]
|
|---|
| 216 | const float y = c*zdaz.Zd()*kRad2Deg; // [deg]
|
|---|
| 217 |
|
|---|
| 218 | arc->SetX1(x);
|
|---|
| 219 | arc->SetY1(y);
|
|---|
| 220 |
|
|---|
| 221 | SetModified();
|
|---|
| 222 | }
|
|---|
| 223 |
|
|---|
| 224 | void MGSkyPosition::UpdatePosition(RaDec &radec, Float_t zd, Float_t az)
|
|---|
| 225 | {
|
|---|
| 226 | //
|
|---|
| 227 | // zd [deg]
|
|---|
| 228 | // az [deg]
|
|---|
| 229 | //
|
|---|
| 230 | static int X =~0;
|
|---|
| 231 | static int Y =~0;
|
|---|
| 232 | static int Rx=~0;
|
|---|
| 233 | static int Ry=~0;
|
|---|
| 234 |
|
|---|
| 235 | const float rad = az*kDeg2Rad; // [rad]
|
|---|
| 236 |
|
|---|
| 237 | const float s = sin(rad);
|
|---|
| 238 | const float c = cos(rad);
|
|---|
| 239 |
|
|---|
| 240 | const float x = s*zd; // [deg]
|
|---|
| 241 | const float y = c*zd; // [deg]
|
|---|
| 242 |
|
|---|
| 243 | const int pixx = (int)(x/fPix);
|
|---|
| 244 | const int pixy = (int)(y/fPix);
|
|---|
| 245 |
|
|---|
| 246 | const int rx = (int)(s*fWidth/2.);
|
|---|
| 247 | const int ry = (int)(c*fWidth/2.);
|
|---|
| 248 |
|
|---|
| 249 | if (X==pixx && Y==pixy && Rx==rx && Ry==ry)
|
|---|
| 250 | return;
|
|---|
| 251 |
|
|---|
| 252 | X = pixx;
|
|---|
| 253 | Y = pixy;
|
|---|
| 254 |
|
|---|
| 255 | Rx = rx;
|
|---|
| 256 | Ry = ry;
|
|---|
| 257 |
|
|---|
| 258 | const float dx = s*4.;
|
|---|
| 259 | const float dy = c*4.;
|
|---|
| 260 |
|
|---|
| 261 | SetLin1(s*95., c*95.);
|
|---|
| 262 | SetLin2(x+dy, y-dx, x-dy, y+dx);
|
|---|
| 263 |
|
|---|
| 264 | if (zd<80)
|
|---|
| 265 | {
|
|---|
| 266 | for(int i=0; i<3; i++)
|
|---|
| 267 | SetDot(fDot[i], radec, i-3);
|
|---|
| 268 | for(int i=3; i<6; i++)
|
|---|
| 269 | SetDot(fDot[i], radec, i-2);
|
|---|
| 270 | }
|
|---|
| 271 |
|
|---|
| 272 | SetModified();
|
|---|
| 273 | }
|
|---|
| 274 |
|
|---|
| 275 | void MGSkyPosition::UpdateText(Float_t x, Float_t y)
|
|---|
| 276 | {
|
|---|
| 277 | static int X = ~0;
|
|---|
| 278 | static int Y = ~0;
|
|---|
| 279 |
|
|---|
| 280 | int xd = (int)floor(x);
|
|---|
| 281 | int yd = (int)floor(y);
|
|---|
| 282 | x *= 60.;
|
|---|
| 283 | y *= 60.;
|
|---|
| 284 |
|
|---|
| 285 | int fx = (int)floor(x*10.);
|
|---|
| 286 | int fy = (int)floor(y*10.);
|
|---|
| 287 |
|
|---|
| 288 | if (X==fx && Y==fy)
|
|---|
| 289 | return;
|
|---|
| 290 |
|
|---|
| 291 | X = fx;
|
|---|
| 292 | Y = fy;
|
|---|
| 293 |
|
|---|
| 294 | float xm = fmod(fabs(x), 60.);
|
|---|
| 295 | float ym = fmod(fabs(y), 60.);
|
|---|
| 296 |
|
|---|
| 297 | char txt[100];
|
|---|
| 298 | sprintf(txt, "Zd=%d\xb0%02.1f'\nAz=%d\xb0%02.1f'",
|
|---|
| 299 | xd, xm, yd, ym);
|
|---|
| 300 |
|
|---|
| 301 | fText->SetText(fText->GetX(), fText->GetY(), txt);
|
|---|
| 302 |
|
|---|
| 303 | SetModified();
|
|---|
| 304 | }
|
|---|
| 305 |
|
|---|
| 306 |
|
|---|
| 307 | void MGSkyPosition::Update(ZdAz &pos)
|
|---|
| 308 | {
|
|---|
| 309 | //
|
|---|
| 310 | // calculate actual time for planet positions
|
|---|
| 311 | //
|
|---|
| 312 | fSlaPlanet->SetMjd2Now();
|
|---|
| 313 | fSlaStar->SetMjd2Now();
|
|---|
| 314 |
|
|---|
| 315 | UpdatePlanet(kESun, fSun);
|
|---|
| 316 | UpdatePlanet(kEMoon, fMoon);
|
|---|
| 317 | UpdatePlanet(kEJupiter, fJupiter);
|
|---|
| 318 | UpdatePlanet(kEVenus, fVenus);
|
|---|
| 319 | UpdatePlanet(kEMars, fMars);
|
|---|
| 320 |
|
|---|
| 321 | RaDec radec = fSlaStar->CalcRaDecFast(pos*kDeg2Rad);
|
|---|
| 322 |
|
|---|
| 323 | UpdatePosition(radec, pos.Zd(), pos.Az());
|
|---|
| 324 | UpdateText(pos.Zd(), pos.Az());
|
|---|
| 325 |
|
|---|
| 326 | UpdateCanvas();
|
|---|
| 327 | }
|
|---|
| 328 |
|
|---|
| 329 | void MGSkyPosition::UpdatePlanet(Int_t planet, TArc *arc)
|
|---|
| 330 | {
|
|---|
| 331 | //
|
|---|
| 332 | // calculate actual position of planet
|
|---|
| 333 | //
|
|---|
| 334 | fSlaPlanet->UpdatePlanetPos((ePlanets_t)planet);
|
|---|
| 335 |
|
|---|
| 336 | ZdAz zdaz = fSlaPlanet->GetPlanetPos((ePlanets_t)planet);
|
|---|
| 337 |
|
|---|
| 338 | //
|
|---|
| 339 | // check whether we have to change the position where it is drawn
|
|---|
| 340 | //
|
|---|
| 341 | const float s = sin(zdaz.Az());
|
|---|
| 342 | const float c = cos(zdaz.Az());
|
|---|
| 343 |
|
|---|
| 344 | const float deg = zdaz.Zd()*kRad2Deg;
|
|---|
| 345 |
|
|---|
| 346 | const float x = s*deg;
|
|---|
| 347 | const float y = c*deg;
|
|---|
| 348 |
|
|---|
| 349 | const int pixx = (int)(x/fPix);
|
|---|
| 350 | const int pixy = (int)(y/fPix);
|
|---|
| 351 |
|
|---|
| 352 | if (fX[planet]==pixx && fY[planet]==pixy)
|
|---|
| 353 | return;
|
|---|
| 354 |
|
|---|
| 355 | fX[planet] = pixx;
|
|---|
| 356 | fY[planet] = pixy;
|
|---|
| 357 |
|
|---|
| 358 | //
|
|---|
| 359 | // Set new position
|
|---|
| 360 | //
|
|---|
| 361 | arc->SetX1(x);
|
|---|
| 362 | arc->SetY1(y);
|
|---|
| 363 |
|
|---|
| 364 | SetModified();
|
|---|
| 365 |
|
|---|
| 366 | if (planet!=kESun)
|
|---|
| 367 | return;
|
|---|
| 368 |
|
|---|
| 369 | // cout << "Sun: x=" << x << " y=" << y;
|
|---|
| 370 | // cout << " Zd=" << deg << " Az=" << 360./D2PI*zdaz.Az() << endl;
|
|---|
| 371 |
|
|---|
| 372 | fSunL[0]->SetX1(x-3.5); fSunL[0]->SetX2(x+3.5);
|
|---|
| 373 | fSunL[1]->SetX1(x-2.5); fSunL[1]->SetX2(x+2.5);
|
|---|
| 374 | fSunL[2]->SetX1(x-2.5); fSunL[2]->SetX2(x+2.5);
|
|---|
| 375 | fSunL[3]->SetX1(x); fSunL[3]->SetX2(x);
|
|---|
| 376 |
|
|---|
| 377 | fSunL[0]->SetY1(y); fSunL[0]->SetY2(y);
|
|---|
| 378 | fSunL[1]->SetY1(y-2.5); fSunL[1]->SetY2(y+2.5);
|
|---|
| 379 | fSunL[2]->SetY1(y+2.5); fSunL[2]->SetY2(y-2.5);
|
|---|
| 380 | fSunL[3]->SetY1(y-3.5); fSunL[3]->SetY2(y+3.5);
|
|---|
| 381 | }
|
|---|