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