1 | #ifndef COORD_H
|
---|
2 | #define COORD_H
|
---|
3 |
|
---|
4 | #include <math.h> // floor
|
---|
5 | #include <iostream>
|
---|
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 istream& operator>>(istream &in, XY &xy);
|
---|
40 | friend ostream& operator<<(ostream &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 std::istream& operator>>(std::istream &in, XY &xy) { in >> xy.fX; in >> xy.fY; return in; }
|
---|
76 | inline std::ostream& operator<<(std::ostream &out, const XY &xy) { out << xy.X() << " " << xy.Y(); 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 XY &c) { fX/=c.X(); fY/=c.Y(); }
|
---|
93 | void operator-=(const AltAz &c) { fX-=c.fX; fY-=c.fY; }
|
---|
94 | void operator+=(const AltAz &c) { fX+=c.fX; fY+=c.fY; }
|
---|
95 |
|
---|
96 | AltAz operator/(double c) const { return AltAz(fX/c, fY/c); }
|
---|
97 | AltAz operator*(double c) const { return AltAz(fX*c, fY*c); }
|
---|
98 | AltAz operator*(const XY &c) const { return AltAz(fX*c.X(), fY*c.Y()); }
|
---|
99 | AltAz operator/(const XY &c) const { return AltAz(fX/c.X(), fY/c.Y()); }
|
---|
100 | AltAz operator+(const AltAz &c) const { return AltAz(fX+c.fX, fY+c.fY); }
|
---|
101 | AltAz operator-(const AltAz &c) const { return AltAz(fX-c.fX, fY-c.fY); }
|
---|
102 | AltAz operator-() const { return AltAz(-fX, -fY); }
|
---|
103 | };
|
---|
104 |
|
---|
105 | class ZdAz : public XY
|
---|
106 | {
|
---|
107 | public:
|
---|
108 | ZdAz(double zd=0, double az=0) : XY(zd, az) {}
|
---|
109 | ZdAz(const ZdAz &c) : XY(c) {}
|
---|
110 |
|
---|
111 | void operator*=(double c) { fX*=c; fY*=c; }
|
---|
112 | void operator/=(double c) { fX*=c; fY*=c; }
|
---|
113 |
|
---|
114 | double Zd() const { return fX; }
|
---|
115 | double Az() const { return fY; }
|
---|
116 |
|
---|
117 | void Zd(double d) { fX=d; }
|
---|
118 | void Az(double d) { fY=d; }
|
---|
119 | void operator*=(const XY &c) { fX*=c.X(); fY*=c.Y(); }
|
---|
120 | void operator/=(const XY &c) { fX/=c.X(); fY/=c.Y(); }
|
---|
121 | void operator-=(const ZdAz &c) { fX-=c.fX; fY-=c.fY; }
|
---|
122 | void operator+=(const ZdAz &c) { fX+=c.fX; fY+=c.fY; }
|
---|
123 |
|
---|
124 | ZdAz operator/(double c) const { return ZdAz(fX/c, fY/c); }
|
---|
125 | ZdAz operator*(double c) const { return ZdAz(fX*c, fY*c); }
|
---|
126 | ZdAz operator*(const XY &c) const { return ZdAz(fX*c.X(), fY*c.Y()); }
|
---|
127 | ZdAz operator/(const XY &c) const { return ZdAz(fX/c.X(), fY/c.Y()); }
|
---|
128 | ZdAz operator+(const ZdAz &c) const { return ZdAz(fX+c.fX, fY+c.fY); }
|
---|
129 | ZdAz operator-(const ZdAz &c) const { return ZdAz(fX-c.fX, fY-c.fY); }
|
---|
130 | ZdAz operator-() const { return ZdAz(-fX, -fY); }
|
---|
131 | };
|
---|
132 |
|
---|
133 | class RaDec : public XY
|
---|
134 | {
|
---|
135 | public:
|
---|
136 | RaDec(double ra=0, double dec=0) : XY(ra, dec) {}
|
---|
137 |
|
---|
138 | double Ra() const { return fX; }
|
---|
139 | double Dec() const { return fY; }
|
---|
140 |
|
---|
141 | void operator*=(double c) { fX*=c; fY*=c; }
|
---|
142 | void operator/=(double c) { fX*=c; fY*=c; }
|
---|
143 |
|
---|
144 | void Ra(double x) { fX = x; }
|
---|
145 | void Dec(double y) { fY = y; }
|
---|
146 |
|
---|
147 | RaDec operator/(double c) const { return RaDec(fX/c, fY/c); }
|
---|
148 | RaDec operator*(double c) const { return RaDec(fX*c, fY*c); }
|
---|
149 | RaDec operator*(const XY &c) const { return RaDec(fX*c.X(), fY*c.Y()); }
|
---|
150 | RaDec operator+(const RaDec &c) const { return RaDec(fX+c.fX, fY+c.fY); }
|
---|
151 | RaDec operator-(const RaDec &c) const { return RaDec(fX-c.fX, fY-c.fY); }
|
---|
152 | RaDec operator-() const { return RaDec(-fX, -fY); }
|
---|
153 | };
|
---|
154 |
|
---|
155 | inline double Rad2Deg(double rad)
|
---|
156 | {
|
---|
157 | return kRad2Deg*rad;
|
---|
158 | }
|
---|
159 |
|
---|
160 | inline double Deg2Rad(double rad)
|
---|
161 | {
|
---|
162 | return kDeg2Rad*rad;
|
---|
163 | }
|
---|
164 | #endif
|
---|