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