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 #include <cassert>
00026 #include <cmath>
00027
00028 INLINE
00029 CVertex::CVertex()
00030 {
00031 setXYZ(0,0,0);
00032 }
00033
00034 INLINE
00035 CVertex::CVertex(TCoordinate Ax, TCoordinate Ay, TCoordinate Az)
00036 {
00037 setXYZ(Ax,Ay,Az);
00038 }
00039
00040 INLINE
00041 CVertex::CVertex(TCoordinate ATab[3])
00042 {
00043 setXYZ(ATab[0],ATab[1],ATab[2]);
00044 }
00045
00046 INLINE
00047 CVertex::CVertex(const CVertex& AVector)
00048 {
00049 setXYZ(AVector.getX(), AVector.getY(), AVector.getZ());
00050 }
00051
00052 INLINE
00053 TCoordinate CVertex::getX() const
00054 {
00055 return FCoord[0];
00056 }
00057
00058 INLINE
00059 TCoordinate CVertex::getY() const
00060 {
00061 return FCoord[1];
00062 }
00063
00064 INLINE
00065 TCoordinate CVertex::getZ() const
00066 {
00067 return FCoord[2];
00068 }
00069
00070 INLINE
00071 TCoordinate CVertex::getCoord(int ADim) const
00072 {
00073 assert(0<=ADim && ADim<=2);
00074 return FCoord[ADim];
00075 }
00076
00077 INLINE
00078 void CVertex::setX(TCoordinate ANewX)
00079 {
00080 FCoord[0] = ANewX;
00081 }
00082
00083 INLINE
00084 void CVertex::setY(TCoordinate ANewY)
00085 {
00086 FCoord[1] = ANewY;
00087 }
00088
00089 INLINE
00090 void CVertex::setZ(TCoordinate ANewZ)
00091 {
00092 FCoord[2] = ANewZ;
00093 }
00094
00095 INLINE
00096 void CVertex::setCoord(int ADim, TCoordinate ANewCoord)
00097 {
00098 assert(0<=ADim && ADim<=2);
00099 FCoord[ADim] = ANewCoord;
00100 }
00101
00102 INLINE
00103 void CVertex::setXYZ(TCoordinate ANewX, TCoordinate ANewY, TCoordinate ANewZ)
00104 {
00105 setX(ANewX);
00106 setY(ANewY);
00107 setZ(ANewZ);
00108 }
00109
00110 INLINE
00111 CVertex& CVertex::operator=(const CVertex& AVector)
00112 {
00113 setXYZ(AVector.getX(), AVector.getY(), AVector.getZ());
00114 return *this;
00115 }
00116
00117 INLINE
00118 bool CVertex::operator==(const CVertex& AVector) const
00119 {
00120 return
00121 isZero(this->getX() - AVector.getX()) &&
00122 isZero(this->getY() - AVector.getY()) &&
00123 isZero(this->getZ() - AVector.getZ());
00124 }
00125
00126 INLINE
00127 bool CVertex::operator!=(const CVertex& AVector) const
00128 {
00129 return ! (*this == AVector);
00130 }
00131
00132 INLINE
00133 CVertex& CVertex::operator+=(const CVertex& AVector)
00134 {
00135 *this= *this + AVector;
00136 return *this;
00137 }
00138
00139 INLINE
00140 CVertex& CVertex::operator-=(const CVertex& AVector)
00141 {
00142 return *this= *this - AVector;
00143 }
00144
00145 INLINE
00146 CVertex CVertex::operator*(TCoordinate ACoef) const
00147 {
00148 return CVertex(getX()*ACoef, getY()*ACoef, getZ()*ACoef);
00149 }
00150
00151 INLINE
00152 CVertex CVertex::operator/(TCoordinate ACoef) const
00153 {
00154 assert(!isZero(ACoef));
00155 return CVertex(getX()/ACoef, getY()/ACoef, getZ()/ACoef);
00156 }
00157
00158 INLINE
00159 CVertex& CVertex::operator*=(TCoordinate ACoef)
00160 {
00161 return *this = *this * ACoef;
00162 }
00163
00164 INLINE
00165 CVertex& CVertex::operator/=(TCoordinate ACoef)
00166 {
00167 return *this = *this / ACoef;
00168 }
00169
00170 INLINE
00171 CVertex CVertex::operator+(const CVertex& AVector) const
00172 {
00173 return CVertex(getX() + AVector.getX(),
00174 getY() + AVector.getY(),
00175 getZ() + AVector.getZ());
00176 }
00177
00178 INLINE
00179 CVertex CVertex::operator-(const CVertex& AVector) const
00180 {
00181 return CVertex(getX() - AVector.getX(),
00182 getY() - AVector.getY(),
00183 getZ() - AVector.getZ());
00184 }
00185
00186 INLINE
00187 CVertex CVertex::operator+() const
00188 {
00189 return *this;
00190 }
00191
00192 INLINE
00193 CVertex CVertex::operator-() const
00194 {
00195 return CVertex(-getX(),-getY(),-getZ());
00196 }
00197
00198 INLINE
00199 CVertex CVertex::operator*(const CVertex& AVector) const
00200 {
00201 return CVertex(getY()*AVector.getZ() - AVector.getY()*getZ(),
00202 getZ()*AVector.getX() - AVector.getZ()*getX(),
00203 getX()*AVector.getY() - AVector.getX()*getY());
00204 }
00205
00206 INLINE
00207 CVertex CVertex::multiply(const CVertex& AVector) const
00208 {
00209 return CVertex(getX()*AVector.getX(),
00210 getY()*AVector.getY(),
00211 getZ()*AVector.getZ());
00212 }
00213
00214 INLINE
00215 CVertex CVertex::divide(const CVertex& AVector) const
00216 {
00217 assert(!isZero(AVector.getX()));
00218 assert(!isZero(AVector.getY()));
00219 assert(!isZero(AVector.getZ()));
00220
00221 return CVertex(getX()/AVector.getX(),
00222 getY()/AVector.getY(),
00223 getZ()/AVector.getZ());
00224 }
00225
00226 INLINE
00227 TCoordinate CVertex::dot(const CVertex& AVector) const
00228 {
00229 return
00230 getX()*AVector.getX() +
00231 getY()*AVector.getY() +
00232 getZ()*AVector.getZ();
00233 }
00234
00235 INLINE
00236 bool CVertex::isNull() const
00237 {
00238 return
00239 isZero(getX()) &&
00240 isZero(getY()) &&
00241 isZero(getZ());
00242 }
00243
00244 INLINE
00245 TCoordinate CVertex::norm() const
00246 {
00247 return sqrt(sqrNorm());
00248 }
00249
00250 INLINE
00251 TCoordinate CVertex::normalize()
00252 {
00253 TCoordinate n = norm();
00254 if (! isNull()) *this /= n;
00255 return n;
00256 }
00257
00258 INLINE
00259 CVertex CVertex::normalized() const
00260 {
00261 CVertex result(*this);
00262 result.normalize();
00263 return result;
00264 }
00265
00266 INLINE
00267 TCoordinate CVertex::sqrNorm() const
00268 {
00269 return sqr(getX()) + sqr(getY()) + sqr(getZ());
00270 }
00271
00272 INLINE
00273 CVertex operator*(TCoordinate ACoef, const CVertex& AVertex)
00274 {
00275 return AVertex*ACoef;
00276 }
00277
00278 INLINE
00279 std::ostream& operator<<(std::ostream& AStream, const CVertex& AVertex)
00280 {
00281 AStream << "(";
00282 AStream << "x="; AStream << AVertex.getX() << "\t";
00283
00284 AStream << ",";
00285 AStream << "y="; AStream << AVertex.getY() << "\t";
00286
00287 AStream << ",";
00288 AStream << "z="; AStream << AVertex.getZ() << "\t";
00289
00290 AStream << ")";
00291
00292 return AStream;
00293 }
00294