Biomechanical Joint Model
 Author: Anderson Maciel

comevector3d.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2001 by Anderson Maciel                                 *
00003  *   andi.maciel@gmail.com                                                 *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  **************************************************************************/
00020 
00031 
00032 #include <cmath>
00033 #include <math.h>
00034 #include <algebra/comevector3d.h>
00035 #include <algebra/comematrix.h>
00036 
00037 
00039 // Description: Class "COME_Vector3D" constructor without parameter.
00040 // Parameters.: -
00041 // Return.....: -
00042 
00043 COME_Vector3D::COME_Vector3D(void) {
00044         x = 0;
00045     y = 0;
00046     z = 0;
00047 }
00048 
00050 // Description: Class "COME_Vector3D" constructor with parameters.
00051 // Parameters.: double xi (initial x value), 
00052 //                              double yi (initial y value),
00053 //                              double zi (initial z value).
00054 // Return.....: -
00055 
00056 COME_Vector3D::COME_Vector3D(const double xi, const double yi, const double zi) {
00057         x = xi;
00058     y = yi;
00059     z = zi;
00060 }
00061 
00062 
00063 
00065 // Description: Class "COME_Vector3D" constructor with parameters.
00066 // Parameters.: COME_Vector3D (object).
00067 // Return.....: -
00068 
00069 COME_Vector3D::COME_Vector3D(const COME_Vector3D &v) {
00070         x = v.x ;
00071     y = v.y ;
00072     z = v.z ;
00073 }
00074 
00076 // Description: Class "COME_Vector3D" constructor with parameters.
00077 // Parameters.: VPpoint3D (object).
00078 // Return.....: -
00079 
00080 COME_Vector3D::COME_Vector3D(const COME_Point3D &v) {
00081         x = v.x ;
00082     y = v.y ;
00083     z = v.z ;
00084 }
00085 
00087 // Description: Operator=
00088 // Parameters.: COME_Vector3D (object).
00089 // Return.....: COME_Vector3D (object).
00090 
00091 COME_Vector3D& COME_Vector3D :: operator= ( const COME_Vector3D& v ) {
00092       if ( this == &v ) return ( *this ) ;
00093       x = v.x ;
00094       y = v.y ;
00095       z = v.z ;
00096       return ( *this ) ;
00097 }
00098 
00099 
00101 // Description: Operator=
00102 // Parameters.: COME_Vector3D (object).
00103 // Return.....: COME_Vector3D (object).
00104 
00105 COME_Vector3D& COME_Vector3D :: operator= ( const COME_Point3D& p ) {
00106       if ( this == &p ) return ( *this ) ;
00107       x = p.x ;
00108       y = p.y ;
00109       z = p.z ;
00110       return ( *this ) ;
00111 }
00112 
00113 
00114 
00116 // Description: Operator==
00117 // Parameters.: COME_Vector3D (object).
00118 // Return.....: TRUE if the vectors are same,
00119 //              FALSE if the vectors are not same.
00120 
00121 int COME_Vector3D :: operator== ( const COME_Vector3D& v1 ) {
00122         if ( ( x == v1.x ) &&
00123          ( y == v1.y ) &&
00124          ( z == v1.z ) )
00125             return true;
00126          else
00127             return false;
00128 }
00129 
00130 
00131 
00132 
00134 // Description: Operator!=
00135 // Parameters.: COME_Vector3D (object).
00136 // Return.....: TRUE if the vectors are not same,
00137 //              FALSE if the vectors are same.
00138 
00139 int COME_Vector3D :: operator!= ( const COME_Vector3D& v ) {
00140         if ( ( x != v.x ) ||
00141          ( y != v.y ) ||
00142          ( z != v.z ) )
00143             return true;
00144          else
00145             return false;
00146 }
00147 
00148 
00149 
00151 
00152 // Description: Operator+
00153 // Parameters.: COME_Point3D (object).
00154 // Return.....: COME_Point3D (object).
00155 
00156 COME_Point3D COME_Vector3D :: operator+ (COME_Point3D v) const{
00157 
00158       COME_Point3D vv(x + v.getX(), y + v.getY(), z + v.getZ());
00159 
00160       return ( vv );
00161 
00162 }
00163 
00164 
00166 // Description: Operator-
00167 // Parameters.: COME_Point3D (object).
00168 // Return.....: COME_Point3D (object).
00169 
00170 COME_Point3D COME_Vector3D :: operator- (COME_Point3D v) {
00171 
00172       COME_Point3D vv(x - v.getX(), y - v.getY(), z - v.getZ());
00173       return ( vv );
00174 }
00175 
00177 // Description: Operator+
00178 // Parameters.: COME_Vector3D (object).
00179 // Return.....: COME_Vector3D (object).
00180 
00181 COME_Vector3D COME_Vector3D :: operator+ ( const COME_Vector3D& v ) const {
00182       COME_Vector3D vv(x + v.x, y + v.y, z + v.z);
00183       return ( vv ) ;
00184 }
00185 
00186 
00188 // Description: Operator-
00189 // Parameters.: COME_Vector3D (object).
00190 // Return.....: COME_Vector3D (object).
00191 
00192 COME_Vector3D COME_Vector3D :: operator- ( const COME_Vector3D& v ) {
00193       COME_Vector3D 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.....: COME_Vector3D (object).
00204 
00205 COME_Vector3D COME_Vector3D :: operator- () {
00206       COME_Vector3D vv(- x, - y, - z);
00207       return ( vv ) ;
00208 }
00209 
00210 
00212 // Description: Operator*
00213 // Parameters.: double c (multiplies the vector).
00214 // Return.....: COME_Vector3D (object).
00215 
00216 COME_Vector3D COME_Vector3D :: operator* ( const double& c ) const {
00217       COME_Vector3D vv(c * x, c * y, c * z);
00218       return ( vv ) ;
00219 }
00220 
00221 
00223 // Description: Operator*
00224 // Parameters.: COME_Vector3D (multiplies the vector).
00225 // Return.....: COME_Vector3D (object).
00226 
00227 COME_Vector3D COME_Vector3D :: operator* ( const COME_Vector3D& v ) {
00228   COME_Vector3D 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 
00236 // Description: Operator*
00237 // Parameters.: COME_Vector3D (multiplies the vector).
00238 // Return.....: COME_Vector3D (object).
00239 
00240 COME_Vector3D COME_Vector3D :: operator* ( const COME_Matrix& m ) {
00241   
00242         double xl,yl,zl;
00243 
00244         xl =    m.getValueAt(0,0) * x + m.getValueAt(1,0) * y + m.getValueAt(2,0) * z;
00245         yl =    m.getValueAt(0,1) * x + m.getValueAt(1,1) * y + m.getValueAt(2,1) * z;
00246         zl =    m.getValueAt(0,2) * x + m.getValueAt(1,2) * y + m.getValueAt(2,2) * z;
00247         
00248         COME_Vector3D resultV( xl, yl, zl );
00249         return resultV;
00250 
00251 }
00252 
00254 // Description: Operator*
00255 // Parameters.: COME_Vector3D (multiplies the vector).
00256 // Return.....: COME_Vector3D (object).
00257 
00258 COME_Vector3D COME_Vector3D :: operator* ( const COME_Point3D& v ) {
00259   COME_Vector3D vv(y * v.z - (z * v.y),
00260         z * v.x - (x * v.z),
00261         x * v.y - (y * v.x));
00262   return ( vv ) ;
00263 
00264 }
00265 
00266 
00268 // Description: Operator/
00269 // Parameters.: double c (divides the vector).
00270 // Return.....: COME_Vector3D (object).
00271 
00272 COME_Vector3D COME_Vector3D :: operator/ ( const double& c ) {
00273       COME_Vector3D vv(x / c, y / c, z / c);
00274       return ( vv ) ;
00275 }
00276 
00277 
00278 
00280 // Description: Operator+=
00281 // Parameters.: COME_Vector3D (object).
00282 // Return.....: COME_Vector3D (object).
00283 
00284 COME_Vector3D& COME_Vector3D :: operator+= ( const COME_Vector3D& v ) {
00285       x += v.x ;
00286       y += v.y ;
00287       z += v.z ;
00288       return *this ;
00289 }
00290 
00291 
00292 
00294 // Description: Operator-=
00295 // Parameters.: COME_Vector3D (object).
00296 // Return.....: COME_Vector3D (object).
00297 
00298 COME_Vector3D& COME_Vector3D :: operator-= ( const COME_Vector3D& v ) {
00299       x -= v.x ;
00300       y -= v.y ;
00301       z -= v.z ;
00302       return *this ;
00303 }
00304 
00305 
00307 // Description: Operator*=
00308 // Parameters.: double c (multiplies the vector).
00309 // Return.....: COME_Vector3D (object).
00310 
00311 COME_Vector3D& COME_Vector3D :: operator*= ( const double& c ) {
00312       x *= c ;
00313       y *= c ;
00314       z *= c ;
00315       return *this ;
00316 }
00317 
00318 
00320 // Description: Operator/=
00321 // Parameters.: double c (divides the vector).
00322 // Return.....: COME_Vector3D (object).
00323 
00324 COME_Vector3D& COME_Vector3D :: operator/= ( const double& c ) {
00325       x /= c ;
00326       y /= c ;
00327       z /= c ;
00328       return *this ;
00329 }
00330 
00331 
00333 // Description: Vector module.
00334 // Parameters.: -
00335 // Return.....: size (module)
00336 
00337 double COME_Vector3D :: vpModule () const {
00338         double size = (double) sqrt( (double) (x*x + y*y + z*z) );
00339         return size;
00340 }
00341 
00342 
00344 // Description: Vector normalization
00345 // Parameters.: -
00346 // Return.....: -
00347 
00348 COME_Vector3D COME_Vector3D :: vpNormalize () {
00349       double l =  vpModule();
00350       if (l==0) return COME_Vector3D();
00351       x = x / l ;
00352       y = y / l ;
00353       z = z / l ;
00354           return COME_Vector3D( x, y, z );
00355 }
00356 
00357 
00359 // Description: Dot Product.
00360 // Parameters.: COME_Vector3D& v
00361 // Return.....: double d (dot product - angle cos * the two vectors module)
00362 
00363 double COME_Vector3D :: vpDotProduct ( const COME_Vector3D& v ) {
00364       double    d ;
00365 
00366       d =  x * v.x + y * v.y + z * v.z;
00367 
00368         
00369       return ( d ) ;
00370 }
00371 
00372 
00374 // Description: Cross Product
00375 // Parameters.: 
00376 // Return.....: 
00377 
00378 COME_Vector3D COME_Vector3D :: vpCrossProduct ( const COME_Vector3D& v ) {
00379   COME_Vector3D vv(y * v.z - (z * v.y), 
00380                             z * v.x - (x * v.z), 
00381                             x * v.y - (y * v.x));
00382   return ( vv ) ;
00383 }
00384 
00385 
00387 // Description: Set the vector value.
00388 // Parameters.: COME_Point3D p
00389 // Return.....: -
00390 
00391 void COME_Vector3D :: setVector3D(COME_Point3D p) {
00392         x = p.getX();
00393         y = p.getY();
00394         z = p.getZ();
00395 }
00396 
00397 
00399 // Description: Set the vector value.
00400 // Parameters.: double x,
00401 //              double y,
00402 //                      double z.
00403 // Return.....: -
00404 
00405 void COME_Vector3D :: setVector3D(double xx,double yy,double zz) {
00406         x = xx;
00407         y = yy;
00408         z = zz;
00409 }
00410 
00411 
00412 
00414 // Description: Get the vector value.
00415 // Parameters.: double x,
00416 //              double y,
00417 //                      double z.
00418 // Return.....: -
00419 
00420 void COME_Vector3D :: getVector3D(double &xx,double &yy,double &zz) {
00421         xx = x;
00422         yy = y;
00423         zz = z;
00424 }
00425 
00426 
00428 // Description: Get the vector value.
00429 // Parameters.: -
00430 // Return.....: COME_Vector3D (object)
00431 
00432 COME_Vector3D COME_Vector3D :: getVector3D(void) {
00433 
00434         return *this;
00435 
00436 }
00437 
00438 
00440 // Description: Get the X vector value. 
00441 // Parameters.: -
00442 // Return.....: double (x)
00443 
00444 double COME_Vector3D :: getVector3DX(void) {
00445 
00446         return x;
00447 
00448 }
00449 
00450 
00452 // Description: Get the Y vector value.
00453 // Parameters.: -
00454 // Return.....: double (y)
00455 
00456 double COME_Vector3D :: getVector3DY(void) {
00457 
00458         return y;
00459 
00460 }
00461 
00462 
00463 
00465 // Description: Get the Z vector value.
00466 // Parameters.: -
00467 // Return.....: double (z)
00468 
00469 double COME_Vector3D :: getVector3DZ(void) {
00470 
00471         return z;
00472 
00473 }
00474 
00476 // Returns the bigger absolute value of x, y, z
00477 double
00478 COME_Vector3D::maxK(void) {
00479 
00480         //( fabs(x) > fabs(y) ) ? ( ( fabs(z) > fabs(x)) ? return z : return x ) : ( ( fabs(y) > fabs(z) ) ? return y : return z );
00481         if( fabs(x) > fabs(y) ){
00482                 if( fabs(z) > fabs(x)){
00483                         return z;
00484                 } else {
00485                         return x;
00486                 }
00487         } else if( fabs(y) > fabs(z) ){
00488                 return y;
00489         } else {
00490                 return z;
00491         }
00492         return 0.0;
00493 }
00494 
00495 
00496 COME_Point3D
00497 COME_Vector3D::getVectorAsPoint3D(){
00498 
00499         return COME_Point3D( x, y, z );
00500 }
00501 
00502 
00503 
00504 double
00505 COME_Vector3D::getAngle( COME_Vector3D& v ){
00506 
00507         double cosine = ( this->vpDotProduct( v ) ) / ( this->vpModule() * v.vpModule() );
00508         if ( ( cosine >= -1.000001 ) && ( cosine <= -0.99999999999 ) ) return M_PI;
00509         double angle = acos( cosine );
00510         /*if( ( angle < - M_PI ) || ( angle > M_PI ) ){
00511                 printf(" angulo louco ");
00512                 angle = acos( ( this->vpDotProduct( v ) ) / ( this->vpModule() * v.vpModule() ) );
00513                 angle = acos( -0.018 / ( 0.135 * 0.135 ) );
00514         }*/
00515 
00516         return angle;
00517 }
00518 
00519 
00520 COME_Matrix
00521 COME_Vector3D :: transMult ( COME_Vector3D& v ) {
00522 
00523         
00524         double result [4][4];
00525 
00526         result[0][0] =  x * v.getX();
00527         result[0][1] =  x * v.getY();
00528         result[0][2] =  x * v.getZ();
00529         result[0][3] =  0.0;
00530 
00531         result[1][0] =  y * v.getX();
00532         result[1][1] =  y * v.getY();
00533         result[1][2] =  y * v.getZ();
00534         result[1][3] =  0.0;
00535 
00536         result[2][0] =  z * v.getX();
00537         result[2][1] =  z * v.getY();
00538         result[2][2] =  z * v.getZ();
00539         result[2][3] =  0.0;
00540 
00541         result[3][0] =  result[3][1] =  result[3][2] =  result[3][3] =  0.0;
00542 
00543         
00544         COME_Matrix resultM( result );
00545         return resultM;
00546 }

Generated on Thu Dec 1 10:13:36 2005 for COME - Biomechanical Joint Model by  doxygen 1.4.5