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 r, float theta);
00061 CPoint(char s, double r, double theta) { dimn=2; x=r * cos(theta); y=r * sin(theta); z=0; }
00062
00063 CPoint(PointMode m, float r, float theta, float psi);
00064 CPoint(char s, double r, double theta, double ele){ dimn=3; x=r*cos(theta)*cos(ele); y=r*sin(theta)*cos(ele); z=r*sin(ele);}
00065
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 r, double theta) { dimn=2; x=r * cos(theta); y=r * sin(theta); z=0; }
00080 void set(char s, double r, double theta, double ele){ dimn=3; x=r*cos(theta)*cos(ele); y=r*sin(theta)*cos(ele); z=r*sin(ele);}
00081
00082 unsigned dim() { return dimn; }
00083 unsigned setdim(unsigned);
00084
00085
00086
00087 CPoint operator-();
00088 CPoint operator~();
00089
00090 int operator == (CPoint);
00091
00092 int operator != (CPoint);
00093
00094
00095
00096
00097
00098
00099
00100
00101 CPoint operator+( CPoint);
00102 CPoint operator-( CPoint);
00103 double operator*( CPoint);
00104 double operator|( CPoint);
00105 CPoint operator^( CPoint);
00106
00107 CPoint& operator*=( double);
00108 CPoint& operator/=( double);
00109 CPoint& operator+=( CPoint);
00110 CPoint& operator-=( CPoint);
00111 CPoint& operator^=( CPoint);
00112
00113
00114
00115 friend CPoint operator * (int, CPoint);
00116 friend CPoint operator * (float, CPoint);
00117 friend CPoint operator * (double, CPoint);
00118 friend CPoint operator * (CPoint, int);
00119 friend CPoint operator * (CPoint, float);
00120 friend CPoint operator * (CPoint, double);
00121
00122 friend CPoint operator / (CPoint, int);
00123 friend CPoint operator / (CPoint, float);
00124 friend CPoint operator / (CPoint, double);
00125
00126 double distance(CPoint *);
00127 double distance2(CPoint *);
00128 double distance(CPoint &);
00129 double distance2(CPoint &);
00130
00131
00132
00133
00134 double len() {
00135 return sqrt(x*x + y*y + z*z);
00136 }
00137
00138 double len2() {
00139 return (x*x + y*y + z*z);
00140 }
00141
00142 double r() { return len(); };
00143 double theta();
00144 double phi();
00145
00146 double ele();
00147
00148 void rotateBy(double angle);
00149
00150 void dump() { printf(" CP: %g @ %g @ %g", x, y, z); }
00151
00152 void normalize();
00153
00154 };
00155
00156 }
00157
00158 #endif // SS_Point_H
00159