00001
00027 #ifndef POINT3_H_
00028 #define POINT3_H_
00029 using namespace std;
00030 #include<iostream>
00031 class Point3 {
00032 double x, y, z;
00033 public:
00034
00035 Point3(double v) {
00036 this->set(v);
00037 }
00038 Point3(double x, double y, double z) {
00039 this->x = x;
00040 this->y = y;
00041 this->z = z;
00042 }
00043 Point3(const Point3 & pt) {
00044 this->x = pt.x;
00045 this->y = pt.y;
00046 this->z = pt.z;
00047 }
00048 double getSum() const{
00049 return x + y + z;
00050 }
00051 double getLen() const{
00052 return x*x + y*y + z*z;
00053 }
00054 void scale(double factor) {
00055 x *= factor;
00056 y *= factor;
00057 z *= factor;
00058 }
00059 void add(const Point3 & pt) {
00060 x += pt.x;
00061 y += pt.y;
00062 z += pt.z;
00063 }
00064 void sub(const Point3 & pt) {
00065 x -= pt.x;
00066 y -= pt.y;
00067 z -= pt.z;
00068 }
00069 void set(double n) {
00070 x = y = z = n;
00071 }
00072 void set(double x, double y, double z) {
00073 this->x = x;
00074 this->y = y;
00075 this->z = z;
00076 }
00077 void set(const Point3 & other) {
00078 x = other.x;
00079 y = other.y;
00080 z = other.z;
00081 }
00082 bool setIfMax(double nx, double ny, double nz) {
00083 bool ret = false;
00084 if (nx > x) {
00085 x = nx;
00086 ret = true;
00087 }
00088 if (ny > y) {
00089 y = ny;
00090 ret = true;
00091 }
00092 if (nz > z) {
00093 z = nz;
00094 ret = true;
00095 }
00096 return ret;
00097 }
00098 bool setIfMin(double nx, double ny, double nz) {
00099 bool ret = false;
00100 if (nx < x) {
00101 x = nx;
00102 ret = true;
00103 }
00104 if (ny < y) {
00105 y = ny;
00106 ret = true;
00107 }
00108 if (nz < z) {
00109 z = nz;
00110 ret = true;
00111 }
00112 return ret;
00113 }
00114 bool setIfMax(const Point3 & other) {
00115 return setIfMax(other.x, other.y, other.z);
00116 }
00117 bool setIfMin(const Point3 & other) {
00118 return setIfMin(other.x, other.y, other.z);
00119 }
00120 double getX()const {
00121 return x;
00122 }
00123 double getY() const{
00124 return y;
00125 }
00126 double getZ() const{
00127 return z;
00128 }
00129
00130 bool equals(const Point3 & other)const {
00131 return (x==other.x) && (y==other.y) && (z==other.z);
00132 }
00133 friend ostream & operator<<(ostream & s, const Point3 & pt);
00134
00135 };
00136 ostream & operator<<(ostream & s, const Point3 & pt) {
00137 s << "[" << pt.x << "," << pt.y << "," << pt.z << "]";
00138 return s;
00139 }
00140
00141 #endif