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