Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

vpvector3d.cpp

Go to the documentation of this file.
00001 //deprecated
00003 //
00004 //  PROJECT.....: vpat - Creating Virtual Patients
00005 //  RESPONSIBLE.: Carla Freitas e Luciana Nedel
00006 //
00007 //  FILE........: vpvector3D.cpp
00008 //  DESCRIPTION.: Contain the VPVector3D class implementation.
00009 //
00010 //  AUTHOR......: Maurício Drehmer
00011 //  DATE........: December/10/1999
00012 //  DESCRIPTION.: Class declaration.
00013 //
00014 //  AUTHOR......: Fernando Sola Pereira
00015 //  DATE........: May/21/2000
00016 //  DESCRIPTION.: Change the overloading operators methods.
00017 //
00018 //  AUTHOR......: Isabel Harb Manssour
00019 //  DATE........: July/10/2000
00020 //  DESCRIPTION.: Change the classes names and implements new 
00021 //                methods.
00022 //
00023 
00024 //  AUTHOR......: Isabel Harb Manssour
00025 
00026 //  DATE........: April/18/2001
00027 
00028 //  DESCRIPTION.: Class update in accordance with the changes in the 
00029 
00030 //                VPPoint3D attributes.
00031 
00032 //
00034 
00035 #include <cmath>
00036 
00037 #include <vpvector3d.h>
00038 
00039 
00041 // Description: Class "VPVector3D" constructor without parameter.
00042 // Parameters.: -
00043 // Return.....: -
00044 
00045 VPVector3D::VPVector3D(void) {
00046     x = 0;
00047     y = 0;
00048     z = 0;
00049 }
00050 
00051 
00052 
00053 
00054 
00056 // Description: Class "VPVector3D" constructor with parameters.
00057 // Parameters.: float xi (initial x value), 
00058 //              float yi (initial y value),
00059 //              float zi (initial z value).
00060 // Return.....: -
00061 
00062 VPVector3D::VPVector3D(const float xi, const float yi, const float zi) {
00063     x = xi;
00064     y = yi;
00065     z = zi;
00066 }
00067 
00068 
00069 
00071 // Description: Class "VPVector3D" constructor with parameters.
00072 // Parameters.: VPVector3D (object).
00073 // Return.....: -
00074 
00075 VPVector3D::VPVector3D(const VPVector3D &v) {
00076     x = v.x ;
00077     y = v.y ;
00078     z = v.z ;
00079 }
00080 
00081 
00083 // Description: Operator=
00084 // Parameters.: VPVector3D (object).
00085 // Return.....: VPVector3D (object).
00086 
00087 VPVector3D& VPVector3D :: operator= ( const VPVector3D& v ) {
00088       if ( this == &v ) return ( *this ) ;
00089       x = v.x ;
00090       y = v.y ;
00091       z = v.z ;
00092       return ( *this ) ;
00093 }
00094 
00095 
00096 
00097 
00099 // Description: Operator==
00100 // Parameters.: VPVector3D (object).
00101 // Return.....: TRUE if the vectors are same,
00102 //              FALSE if the vectors are not same.
00103 
00104 int VPVector3D :: operator== ( const VPVector3D& v1 ) {
00105     if ( ( x == v1.x ) &&
00106          ( y == v1.y ) &&
00107          ( z == v1.z ) )
00108         return true;
00109      else
00110         return false;
00111 }
00112 
00113 
00114 
00115 
00117 // Description: Operator!=
00118 // Parameters.: VPVector3D (object).
00119 // Return.....: TRUE if the vectors are not same,
00120 //              FALSE if the vectors are same.
00121 
00122 int VPVector3D :: operator!= ( const VPVector3D& v ) {
00123     if ( ( x != v.x ) ||
00124          ( y != v.y ) ||
00125          ( z != v.z ) )
00126         return true;
00127      else
00128         return false;
00129 }
00130 
00131 
00132 
00134 
00135 // Description: Operator+
00136 
00137 // Parameters.: VPPoint3D (object).
00138 
00139 // Return.....: VPPoint3D (object).
00140 
00141 
00142 
00143 VPPoint3D VPVector3D :: operator+ (VPPoint3D v) {
00144 
00145       VPPoint3D vv(x + v.vpGetX(), y + v.vpGetY(), z + v.vpGetZ());
00146 
00147       return ( vv );
00148 
00149 }
00150 
00151 
00152 
00153 
00154 
00156 
00157 // Description: Operator-
00158 
00159 // Parameters.: VPPoint3D (object).
00160 
00161 // Return.....: VPPoint3D (object).
00162 
00163 
00164 
00165 VPPoint3D VPVector3D :: operator- (VPPoint3D v) {
00166 
00167       VPPoint3D vv(x - v.vpGetX(), y - v.vpGetY(), z - v.vpGetZ());
00168 
00169       return ( vv );
00170 
00171 }
00172 
00173 
00174 
00175 
00177 // Description: Operator+
00178 // Parameters.: VPVector3D (object).
00179 // Return.....: VPVector3D (object).
00180 
00181 VPVector3D VPVector3D :: operator+ ( const VPVector3D& v ) {
00182       VPVector3D vv(x + v.x, y + v.y, z + v.z);
00183       return ( vv ) ;
00184 }
00185 
00186 
00188 // Description: Operator-
00189 // Parameters.: VPVector3D (object).
00190 // Return.....: VPVector3D (object).
00191 
00192 VPVector3D VPVector3D :: operator- ( const VPVector3D& v ) {
00193       VPVector3D vv(x - v.x, y - v.y, z - v.z);
00194       return ( vv ) ;
00195 }
00196 
00197 
00198 
00199 
00201 // Description: Operator-
00202 // Parameters.: -
00203 // Return.....: VPVector3D (object).
00204 
00205 VPVector3D VPVector3D :: operator- () {
00206       VPVector3D vv(- x, - y, - z);
00207       return ( vv ) ;
00208 }
00209 
00210 
00212 // Description: Operator*
00213 // Parameters.: float c (multiplies the vector).
00214 // Return.....: VPVector3D (object).
00215 
00216 VPVector3D VPVector3D :: operator* ( const float& c ) {
00217       VPVector3D vv(c * x, c * y, c * z);
00218       return ( vv ) ;
00219 }
00220 
00221 
00223 // Description: Operator*
00224 // Parameters.: VPVector3D (multiplies the vector).
00225 // Return.....: VPVector3D (object).
00226 
00227 VPVector3D VPVector3D :: operator* ( const VPVector3D& v ) {
00228   VPVector3D vv(y * v.z - (z * v.y),
00229     z * v.x - (x * v.z),
00230     x * v.y - (y * v.x));
00231   return ( vv ) ;
00232 
00233 }
00234 
00235 
00237 // Description: Operator/
00238 // Parameters.: float c (divides the vector).
00239 // Return.....: VPVector3D (object).
00240 
00241 VPVector3D VPVector3D :: operator/ ( const float& c ) {
00242       VPVector3D vv(x / c, y / c, z / c);
00243       return ( vv ) ;
00244 }
00245 
00246 
00247 
00249 // Description: Operator+=
00250 // Parameters.: VPVector3D (object).
00251 // Return.....: VPVector3D (object).
00252 
00253 VPVector3D& VPVector3D :: operator+= ( const VPVector3D& v ) {
00254       x += v.x ;
00255       y += v.y ;
00256       z += v.z ;
00257       return *this ;
00258 }
00259 
00260 
00261 
00263 // Description: Operator-=
00264 // Parameters.: VPVector3D (object).
00265 // Return.....: VPVector3D (object).
00266 
00267 VPVector3D& VPVector3D :: operator-= ( const VPVector3D& v ) {
00268       x -= v.x ;
00269       y -= v.y ;
00270       z -= v.z ;
00271       return *this ;
00272 }
00273 
00274 
00276 // Description: Operator*=
00277 // Parameters.: float c (multiplies the vector).
00278 // Return.....: VPVector3D (object).
00279 
00280 VPVector3D& VPVector3D :: operator*= ( const float& c ) {
00281       x *= c ;
00282       y *= c ;
00283       z *= c ;
00284       return *this ;
00285 }
00286 
00287 
00289 // Description: Operator/=
00290 // Parameters.: float c (divides the vector).
00291 // Return.....: VPVector3D (object).
00292 
00293 VPVector3D& VPVector3D :: operator/= ( const float& c ) {
00294       x /= c ;
00295       y /= c ;
00296       z /= c ;
00297       return *this ;
00298 }
00299 
00300 
00302 // Description: Vector module.
00303 // Parameters.: -
00304 // Return.....: size (module)
00305 
00306 float VPVector3D :: vpModule () {
00307     float size = (float) sqrt( (double) (x*x + y*y + z*z) );
00308     return size;
00309 }
00310 
00311 
00313 // Description: Vector normalization
00314 // Parameters.: -
00315 // Return.....: -
00316 
00317 void VPVector3D :: vpNormalize () {
00318       float l =  vpModule();
00319       if (l==0) return;
00320       x = x / l ;
00321       y = y / l ;
00322       z = z / l ;
00323 }
00324 
00325 
00327 // Description: Dot Product.
00328 // Parameters.: VPVector3D& v
00329 // Return.....: float d (dot product - angle cos * the two vectors module)
00330 
00331 float VPVector3D :: vpDotProduct ( const VPVector3D& v ) {
00332       float d ;
00333 
00334       d =  x * v.x + y * v.y + z * v.z;
00335 
00336     
00337       return ( d ) ;
00338 }
00339 
00340 
00342 // Description: Cross Product
00343 // Parameters.: 
00344 // Return.....: 
00345 
00346 VPVector3D VPVector3D :: vpCrossProduct ( const VPVector3D& v ) {
00347   VPVector3D vv(y * v.z - (z * v.y), 
00348                 z * v.x - (x * v.z), 
00349                 x * v.y - (y * v.x));
00350   return ( vv ) ;
00351 }
00352 
00353 
00355 // Description: Set the vector value.
00356 // Parameters.: VPPoint3D p
00357 // Return.....: -
00358 
00359 void VPVector3D :: vpSetVector3D(VPPoint3D p) {
00360     x = p.vpGetX();
00361     y = p.vpGetY();
00362     z = p.vpGetZ();
00363 }
00364 
00365 
00367 // Description: Set the vector value.
00368 // Parameters.: float x,
00369 //              float y,
00370 //              float z.
00371 // Return.....: -
00372 
00373 void VPVector3D :: vpSetVector3D(float xx,float yy,float zz) {
00374     x = xx;
00375     y = yy;
00376     z = zz;
00377 }
00378 
00379 
00380 
00382 // Description: Get the vector value.
00383 // Parameters.: float x,
00384 //              float y,
00385 //              float z.
00386 // Return.....: -
00387 
00388 void VPVector3D :: vpGetVector3D(float &xx,float &yy,float &zz) {
00389     xx = x;
00390     yy = y;
00391     zz = z;
00392 }
00393 
00394 
00396 // Description: Get the vector value.
00397 // Parameters.: -
00398 // Return.....: VPVector3D (object)
00399 
00400 VPVector3D VPVector3D :: vpGetVector3D(void) {
00401 
00402     return *this;
00403 
00404 }
00405 
00406 
00408 // Description: Get the X vector value. 
00409 // Parameters.: -
00410 // Return.....: float (x)
00411 
00412 float VPVector3D :: vpGetVector3DX(void) {
00413 
00414     return x;
00415 
00416 }
00417 
00418 
00420 // Description: Get the Y vector value.
00421 // Parameters.: -
00422 // Return.....: float (y)
00423 
00424 float VPVector3D :: vpGetVector3DY(void) {
00425 
00426     return y;
00427 
00428 }
00429 
00430 
00431 
00433 // Description: Get the Z vector value.
00434 // Parameters.: -
00435 // Return.....: float (z)
00436 
00437 float VPVector3D :: vpGetVector3DZ(void) {
00438 
00439     return z;
00440 
00441 }
00442 
00443 
00444 

Generated on Tue Sep 6 10:00:07 2005 for VPAT by  doxygen 1.4.4