source: trunk/MagicSoft/Cosy/base/coord.h@ 1621

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