Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "Point3d.h"
00034 #include <cmath>
00036 CPoint3d::CPoint3d (void)
00037 :x (0), y (0), z (0)
00038 {
00039 }
00040
00041 CPoint3d::CPoint3d (float x, float y, float z)
00042 {
00043 this->x = x;
00044 this->y = y;
00045 this->z = z;
00046 }
00047
00048 CPoint3d::~CPoint3d (void)
00049 {
00050 }
00051
00052 CPoint3d::CPoint3d (const CPoint3d & tmpP)
00053 {
00054 this->x = tmpP.x;
00055 this->y = tmpP.y;
00056 this->z = tmpP.z;
00057 }
00058
00060 CPoint3d & CPoint3d::operator += (const CPoint3d & p)
00061 {
00062 this->x += p.x;
00063 this->y += p.y;
00064 this->z += p.z;
00065 return *this;
00066 }
00067
00068 CPoint3d & CPoint3d::operator -= (const CPoint3d & p)
00069 {
00070 this->x -= p.x;
00071 this->y -= p.y;
00072 this->z -= p.z;
00073 return *this;
00074 }
00075
00076 CPoint3d & CPoint3d::operator *= (float s)
00077 {
00078 this->x *= s;
00079 this->y *= s;
00080 this->z *= s;
00081 return *this;
00082 }
00083
00084 CPoint3d & CPoint3d::operator /= (float s)
00085 {
00086 this->x /= s;
00087 this->y /= s;
00088 this->z /= s;
00089 return *this;
00090 }
00091
00092
00093 CPoint3d operator + (const CPoint3d & p1, const CPoint3d & p2)
00094 {
00095 CPoint3d po;
00096 po.x = p1.x + p2.x;
00097 po.y = p1.y + p2.y;
00098 po.z = p1.z + p2.z;
00099 return po;
00100 }
00101
00102 CPoint3d operator - (const CPoint3d & p1, const CPoint3d & p2)
00103 {
00104 CPoint3d po;
00105 po.x = p1.x - p2.x;
00106 po.y = p1.y - p2.y;
00107 po.z = p1.z - p2.z;
00108 return po;
00109 }
00110
00111 CPoint3d operator * (const CPoint3d & p, float s)
00112 {
00113 CPoint3d po;
00114 po.x = p.x * s;
00115 po.y = p.y * s;
00116 po.z = p.z * s;
00117 return po;
00118 }
00119
00120 float operator * (const CPoint3d & p1, const CPoint3d & p2)
00121 {
00122 return (p1.x * p2.x + p1.y * p2.y + p1.z * p2.z);
00123 }
00124
00125 CPoint3d operator / (const CPoint3d & p, float num)
00126 {
00127 if (num != 0)
00128 {
00129 CPoint3d po;
00130 po.x = p.x / num;
00131 po.y = p.y / num;
00132 po.z = p.z / num;
00133 return po;
00134 }
00135 else
00136 {
00137 return CPoint3d (0, 0, 0);
00138 }
00139 }
00140
00141 CPoint3d operator ^ (const CPoint3d & p1, const CPoint3d & p2)
00142 {
00143 CPoint3d po (
00144 p1.y * p2.z - p1.z * p2.y,
00145 p1.z * p2.x - p1.x * p2.z,
00146 p1.x * p2.y - p1.y * p2.x
00147 );
00148 return po;
00149 }
00150
00151 bool operator < (const CPoint3d & p1, const CPoint3d & p2)
00152 {
00153 return (p1.z != p2.z) ? (p1.z < p2.z) :
00154 (p1.y != p2.y) ? (p1.y < p2.y) :
00155 (p1.x < p2.x);
00156 }
00157
00158 bool operator > (const CPoint3d & p1, const CPoint3d & p2)
00159 {
00160 return (p1.z != p2.z) ? (p1.z > p2.z) :
00161 (p1.y != p2.y) ? (p1.y > p2.y) :
00162 (p1.x > p2.x);
00163 }
00164
00165 bool operator == (const CPoint3d & p1, const CPoint3d & p2)
00166 {
00167 if (p1.x == p2.x && p1.y == p2.y && p1.z == p2.z)
00168 return true;
00169 else
00170 return false;
00171 }
00172
00173 bool operator != (const CPoint3d & p1, const CPoint3d & p2)
00174 {
00175 if (p1.x == p2.x && p1.y == p2.y && p1.z == p2.z)
00176 return false;
00177 else
00178 return true;
00179 }
00180
00181
00183 float CPoint3d::cpDist (void) const
00184 {
00185 return sqrt (x * x + y * y + z * z);
00186 }
00187
00188
00189 float CPoint3d::cpSquaredNorm () const
00190 {
00191 return (this->x * this->x + this->y * this->y + this->z * this->z);
00192 }
00193
00194
00195 float CPoint3d::cpDot (const CPoint3d & p) const
00196 {
00197 return (*this) * p;
00198 }
00199
00200
00201 CPoint3d & CPoint3d::cpNormalize ()
00202 {
00203 float n = float (sqrt (this->x * this->x + this->y * this->y + this->z * this->z));
00204 if (n > float (0))
00205 {
00206 this->x /= n;
00207 this->y /= n;
00208 this->z /= n;
00209 }
00210 return *this;
00211 }
00212
00213