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 "camera_laser_calibration/basic_data/point3d.h"
00034 #include <cmath>
00036 CPoint3d::CPoint3d (void):x (0), y (0), z (0)
00037 {
00038 }
00039
00040 CPoint3d::CPoint3d (float x, float y, float z)
00041 {
00042 this->x = x;
00043 this->y = y;
00044 this->z = z;
00045 }
00046
00047 CPoint3d::~CPoint3d (void)
00048 {
00049 }
00050
00051 CPoint3d::CPoint3d (const CPoint3d & tmpP)
00052 {
00053 this->x = tmpP.x;
00054 this->y = tmpP.y;
00055 this->z = tmpP.z;
00056 }
00057
00059 CPoint3d & CPoint3d::operator += (const CPoint3d & p)
00060 {
00061 this->x += p.x;
00062 this->y += p.y;
00063 this->z += p.z;
00064
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
00074 return *this;
00075 }
00076
00077 CPoint3d & CPoint3d::operator *= (float s)
00078 {
00079 this->x *= s;
00080 this->y *= s;
00081 this->z *= s;
00082
00083 return *this;
00084 }
00085
00086 CPoint3d & CPoint3d::operator /= (float s)
00087 {
00088 this->x /= s;
00089 this->y /= s;
00090 this->z /= s;
00091
00092 return *this;
00093 }
00094
00095
00096 CPoint3d operator + (const CPoint3d & p1, const CPoint3d & p2)
00097 {
00098 CPoint3d po;
00099 po.x = p1.x + p2.x;
00100 po.y = p1.y + p2.y;
00101 po.z = p1.z + p2.z;
00102
00103 return po;
00104 }
00105
00106 CPoint3d operator - (const CPoint3d & p1, const CPoint3d & p2)
00107 {
00108 CPoint3d po;
00109 po.x = p1.x - p2.x;
00110 po.y = p1.y - p2.y;
00111 po.z = p1.z - p2.z;
00112
00113 return po;
00114 }
00115
00116 CPoint3d operator * (const CPoint3d & p, float s)
00117 {
00118 CPoint3d po;
00119 po.x = p.x * s;
00120 po.y = p.y * s;
00121 po.z = p.z * s;
00122
00123 return po;
00124 }
00125
00126 float operator * (const CPoint3d & p1, const CPoint3d & p2)
00127 {
00128 return (p1.x * p2.x + p1.y * p2.y + p1.z * p2.z);
00129 }
00130
00131 CPoint3d operator / (const CPoint3d & p, float num)
00132 {
00133 if (num != 0)
00134 {
00135 CPoint3d po;
00136 po.x = p.x / num;
00137 po.y = p.y / num;
00138 po.z = p.z / num;
00139
00140 return po;
00141 }
00142 else
00143 {
00144 return CPoint3d (0, 0, 0);
00145 }
00146 }
00147
00148 CPoint3d operator ^ (const CPoint3d & p1, const CPoint3d & p2)
00149 {
00150 CPoint3d po (p1.y * p2.z - p1.z * p2.y, p1.z * p2.x - p1.x * p2.z, p1.x * p2.y - p1.y * p2.x);
00151
00152 return po;
00153 }
00154
00155 bool operator < (const CPoint3d & p1, const CPoint3d & p2)
00156 {
00157 return (p1.z != p2.z) ? (p1.z < p2.z) : (p1.y != p2.y) ? (p1.y < p2.y) : (p1.x < p2.x);
00158 }
00159
00160 bool operator > (const CPoint3d & p1, const CPoint3d & p2)
00161 {
00162 return (p1.z != p2.z) ? (p1.z > p2.z) : (p1.y != p2.y) ? (p1.y > p2.y) : (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
00211 return *this;
00212 }