00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef CSL_Point_H
00014 #define CSL_Point_H
00015
00016 #include "CSL_Types.h"
00017 #include <stdio.h>
00018 #include <math.h>
00019
00020 namespace csl {
00021
00022 #ifdef CSL_ENUMS
00023 typedef enum {
00024 kCartesian,
00025 kPolar
00026 } PointMode;
00027 #else
00028 #define kCartesian 0
00029 #define kPolar 1
00030 typedef int PointMode;
00031 #endif
00032
00033
00034
00035 class CPoint {
00036
00037 public:
00038 unsigned dimn;
00039 double x, y, z;
00040
00041
00042 CPoint() { dimn = 3; x = y = z = 0; }
00043
00044
00045 CPoint(int a) { dimn = 1; x = a; y = z = 0; }
00046 CPoint(float a) { dimn = 1; x = a; y = z = 0; }
00047 CPoint(double a) { dimn = 1; x = a; y = z = 0; }
00048
00049
00050 CPoint(int a, int b) { dimn = 2; x = a; y = b; z = 0; }
00051 CPoint(float a, float b) { dimn = 2; x = (double)a; y = (double)b; z = 0; }
00052 CPoint(double a, double b) { dimn = 2; x = a; y = b; z = 0; }
00053
00054
00055 CPoint(int a, int b, int c) { dimn = 3; x = a; y = b; z = c; }
00056 CPoint(float a, float b, float c) { dimn = 3; x = (double)a; y = (double)b; z = (double)c; }
00057 CPoint(double a, double b, double c) { dimn = 3; x = a; y = b; z = c; }
00058
00059
00060 CPoint(PointMode m, float tr, float ttheta);
00061 CPoint(char s, double tr, double ttheta) { dimn=2; x=tr * cos(ttheta); y=tr * sin(ttheta); z=0; }
00062
00063 CPoint(PointMode m, float tr, float ttheta, float psi);
00064 CPoint(char s, double tr, double ttheta, double tele){
00065 dimn=3; x=tr*cos(ttheta)*cos(tele); y=tr*sin(ttheta)*cos(tele); z=tr*sin(tele);}
00066
00067
00068 ~CPoint() { };
00069
00070
00071 void set(int a, int b) { dimn = 2; x = a; y = b; z = 0; }
00072 void set(int a, int b, int c) { dimn = 3; x = a; y = b; z = c; }
00073 void set(float a, float b) { dimn = 2; x = (double)a; y = (double)b; z = 0; }
00074 void set(float a, float b, float c) { dimn = 3; x = (double)a; y = (double)b; z = (double)c; }
00075 void set(double a, double b) { dimn = 2; x = a; y = b; z = 0; }
00076 void set(double a, double b, double c) { dimn = 3; x = a; y = b; z = c; }
00077 void set(PointMode m, float a, float b);
00078 void set(PointMode m, float a, float b, float c);
00079 void set(char s, double tr, double ttheta) { dimn=2; x=tr * cos(ttheta); y=tr * sin(ttheta); z=0; }
00080 void set(char s, double tr, double ttheta, double tele) {
00081 dimn=3; x=tr*cos(ttheta)*cos(tele); y=tr*sin(ttheta)*cos(tele); z=tr*sin(tele);}
00082
00083 void setAzimuth(double taz);
00084 void setElevation(double tele);
00085 void setMagnitude(double tmag);
00086
00087 unsigned dim() { return dimn; }
00088 unsigned setdim(unsigned);
00089
00090
00091
00092 CPoint operator-();
00093 CPoint operator~();
00094
00095 int operator == (CPoint);
00096
00097 int operator != (CPoint);
00098
00099
00100
00101
00102
00103
00104
00105
00106 CPoint operator+( CPoint);
00107 CPoint operator-( CPoint);
00108 double operator*( CPoint);
00109 double operator|( CPoint);
00110 CPoint operator^( CPoint);
00111
00112 CPoint& operator*=( double);
00113 CPoint& operator/=( double);
00114 CPoint& operator+=( CPoint);
00115 CPoint& operator-=( CPoint);
00116 CPoint& operator^=( CPoint);
00117
00118
00119
00120 friend CPoint operator * (int, CPoint);
00121 friend CPoint operator * (float, CPoint);
00122 friend CPoint operator * (double, CPoint);
00123 friend CPoint operator * (CPoint, int);
00124 friend CPoint operator * (CPoint, float);
00125 friend CPoint operator * (CPoint, double);
00126
00127 friend CPoint operator / (CPoint, int);
00128 friend CPoint operator / (CPoint, float);
00129 friend CPoint operator / (CPoint, double);
00130
00131 double distance(CPoint *);
00132 double distance2(CPoint *);
00133 double distance(CPoint &);
00134 double distance2(CPoint &);
00135
00136
00137 double operator () (unsigned idx) const;
00138
00139
00140
00141 double len() {
00142 return sqrt(x*x + y*y + z*z);
00143 }
00144
00145 double len2() {
00146 return (x*x + y*y + z*z);
00147 }
00148
00149 double r() { return len(); };
00150 double theta();
00151 double phi();
00152
00153 double ele();
00154
00155 void rotateBy(double angle);
00156
00157 void dump() { printf(" CP: %g @ %g @ %g", x, y, z); }
00158 void dumpPol() {
00159 printf(" CP: %g @ %g @ %g",
00160 r(),
00161 theta()* CSL_DEGS_PER_RAD,
00162 ele()* CSL_DEGS_PER_RAD);
00163 }
00164
00165 void normalize();
00166
00167 };
00168
00169 }
00170
00171 #endif // SS_Point_H