1 | #ifndef COORD_H
|
---|
2 | #define COORD_H
|
---|
3 |
|
---|
4 | #include <math.h> // floor
|
---|
5 |
|
---|
6 | #include "slalib/slamac.h" // D2PI
|
---|
7 |
|
---|
8 | class Deg
|
---|
9 | {
|
---|
10 | protected:
|
---|
11 | double fDeg;
|
---|
12 |
|
---|
13 | public:
|
---|
14 | Deg(const double d) : fDeg(d) {}
|
---|
15 | Deg(const Deg &c) { fDeg = c.fDeg; }
|
---|
16 |
|
---|
17 | void Set(double d) { fDeg=d; }
|
---|
18 |
|
---|
19 | double operator()() { return fDeg; }
|
---|
20 |
|
---|
21 | operator double() const { return fDeg*D2PI/360.0; }
|
---|
22 | };
|
---|
23 |
|
---|
24 | class XY
|
---|
25 | {
|
---|
26 | protected:
|
---|
27 | double fX;
|
---|
28 | double fY;
|
---|
29 |
|
---|
30 | public:
|
---|
31 | XY(double x=0, double y=0) : fX(x), fY(y) {}
|
---|
32 | XY(const XY &c) { fX = c.fX; fY = c.fY; }
|
---|
33 |
|
---|
34 | void Set(double x, double y) { fX=x; fY=y; }
|
---|
35 |
|
---|
36 | double X() const { return fX; }
|
---|
37 | double Y() const { return fY; }
|
---|
38 |
|
---|
39 | void operator/=(double c) { fX/=c; fY/=c; }
|
---|
40 | void operator*=(double c) { fX*=c; fY*=c; }
|
---|
41 |
|
---|
42 | XY operator/(double c) const { return XY(fX/c, fY/c); }
|
---|
43 | XY operator*(double c) const { return XY(fX*c, fY*c); }
|
---|
44 | XY operator*(const XY &c) const { return XY(fX*c.fX, fY*c.fY); }
|
---|
45 | XY operator/(const XY &c) const { return XY(fX/c.fX, fY/c.fY); }
|
---|
46 | XY operator+(const XY &c) const { return XY(fX+c.fX, fY+c.fY); }
|
---|
47 | XY operator-(const XY &c) const { return XY(fX-c.fX, fY-c.fY); }
|
---|
48 |
|
---|
49 | double Sqr() const { return fX*fX + fY*fY; }
|
---|
50 | double Sqrt() const { return sqrt(Sqr()); }
|
---|
51 | double Ratio() const { return fX/fY; }
|
---|
52 | void Round() { fX=(int)(floor(fX+.5)); fY=(int)(floor(fY+.5)); }
|
---|
53 | };
|
---|
54 |
|
---|
55 | class AltAz : public XY
|
---|
56 | {
|
---|
57 | public:
|
---|
58 | AltAz(double alt=0, double az=0) : XY(alt, az) {}
|
---|
59 |
|
---|
60 | double Alt() const { return fX; }
|
---|
61 | double Az() const { return fY; }
|
---|
62 |
|
---|
63 | void Alt(double d) { fX=d; }
|
---|
64 | void Az(double d) { fY=d; }
|
---|
65 | void operator*=(const XY &c) { fX*=c.X(); fY*=c.Y(); }
|
---|
66 | void operator-=(const AltAz &c) { fX-=c.fX; fY-=c.fY; }
|
---|
67 |
|
---|
68 | AltAz operator/(double c) const { return AltAz(fX/c, fY/c); }
|
---|
69 | AltAz operator*(double c) const { return AltAz(fX*c, fY*c); }
|
---|
70 | AltAz operator*(const XY &c) const { return AltAz(fX*c.X(), fY*c.Y()); }
|
---|
71 | AltAz operator/(const XY &c) const { return AltAz(fX/c.X(), fY/c.Y()); }
|
---|
72 | AltAz operator+(const AltAz &c) const { return AltAz(fX+c.fX, fY+c.fY); }
|
---|
73 | AltAz operator-(const AltAz &c) const { return AltAz(fX-c.fX, fY-c.fY); }
|
---|
74 | };
|
---|
75 |
|
---|
76 | class ZdAz : public XY
|
---|
77 | {
|
---|
78 | public:
|
---|
79 | ZdAz(double zd=0, double az=0) : XY(zd, az) {}
|
---|
80 |
|
---|
81 | double Zd() const { return fX; }
|
---|
82 | double Az() const { return fY; }
|
---|
83 |
|
---|
84 | void Zd(double d) { fX=d; }
|
---|
85 | void Az(double d) { fY=d; }
|
---|
86 | void operator*=(const XY &c) { fX*=c.X(); fY*=c.Y(); }
|
---|
87 | void operator-=(const ZdAz &c) { fX-=c.fX; fY-=c.fY; }
|
---|
88 | void operator+=(const ZdAz &c) { fX+=c.fX; fY+=c.fY; }
|
---|
89 |
|
---|
90 | ZdAz operator/(double c) const { return ZdAz(fX/c, fY/c); }
|
---|
91 | ZdAz operator*(double c) const { return ZdAz(fX*c, fY*c); }
|
---|
92 | ZdAz operator*(const XY &c) const { return ZdAz(fX*c.X(), fY*c.Y()); }
|
---|
93 | ZdAz operator/(const XY &c) const { return ZdAz(fX/c.X(), fY/c.Y()); }
|
---|
94 | ZdAz operator+(const ZdAz &c) const { return ZdAz(fX+c.fX, fY+c.fY); }
|
---|
95 | ZdAz operator-(const ZdAz &c) const { return ZdAz(fX-c.fX, fY-c.fY); }
|
---|
96 | };
|
---|
97 |
|
---|
98 | class RaDec : public XY
|
---|
99 | {
|
---|
100 | public:
|
---|
101 | RaDec(double ra=0, double dec=0) : XY(ra, dec) {}
|
---|
102 |
|
---|
103 | double Ra() const { return fX; }
|
---|
104 | double Dec() const { return fY; }
|
---|
105 |
|
---|
106 | RaDec operator/(double c) const { return RaDec(fX/c, fY/c); }
|
---|
107 | RaDec operator*(double c) const { return RaDec(fX*c, fY*c); }
|
---|
108 | RaDec operator*(const XY &c) const { return RaDec(fX*c.X(), fY*c.Y()); }
|
---|
109 | RaDec operator+(const RaDec &c) const { return RaDec(fX+c.fX, fY+c.fY); }
|
---|
110 | RaDec operator-(const RaDec &c) const { return RaDec(fX-c.fX, fY-c.fY); }
|
---|
111 | };
|
---|
112 |
|
---|
113 | inline double Rad2Deg(double rad)
|
---|
114 | {
|
---|
115 | return 360.0/D2PI*rad;
|
---|
116 | }
|
---|
117 |
|
---|
118 | inline double Deg2Rad(double rad)
|
---|
119 | {
|
---|
120 | return D2PI/360.0*rad;
|
---|
121 | }
|
---|
122 | #endif
|
---|