Biomechanical Joint Model
 Author: Anderson Maciel

comecollision.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2002 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 <physics/comecollision.h>
00033 #include <math.h>
00034 
00035 
00039 COME_Collision :: COME_Collision(){
00040 
00041         
00042 }
00043 
00044 // Fabi and Jean Version
00045 /*COME_Collision :: COME_Collision( COME_BioStructure* organ1N, int faceInOrgan1N, COME_BioStructure* organ2N, int faceInOrgan2N ){
00046 
00047         organ1 = organ1N;
00048         organ2 = organ2N;
00049 
00050         faceInOrgan1 = faceInOrgan1N;
00051         faceInOrgan2 = faceInOrgan2N;
00052         
00053         penetrationDistance = calculatePenetrationGlobalPosition();
00054 
00055         //***************** Calculation of Spring constant using constant and masses **************************
00056         
00057         //double M1 = organ1->getTissue()->getMass();
00058         //double M2 = organ2->getTissue()->getMass();
00059         //springConstant = M1 < M2 ? M1 * K*2 : M2 * K*2;
00060         
00061         //***************** Calculation of Spring constant using young modulus **************************
00062         
00063         COME_Molecule* mol1 = organ1->getSurface()->getAFace( faceInOrgan1).getNearestMolecule();
00064         COME_Molecule* mol2 = organ2->getSurface()->getAFace( faceInOrgan2).getNearestMolecule();
00065         double allowedDistance = ( mol1)->getRadius() + (mol2)->getRadius();                                                    
00066         springConstant = ( ( mol1->getMaterial()->getYoungsModulus()+ mol2->getMaterial()->getYoungsModulus() ) / 2 ) * allowedDistance;
00067         
00068         
00069         forceInFaceOrgan1 = ( organ2->getSurface()->getAFace( faceInOrgan2 ).getNormalGlobalPosition() * penetrationDistance ) * springConstant;
00070         forceInFaceOrgan2 = ( organ1->getSurface()->getAFace( faceInOrgan1 ).getNormalGlobalPosition() * penetrationDistance ) * springConstant;
00071                 
00072 }
00073 */
00074 
00075 // Andi new version
00076 COME_Collision :: COME_Collision( COME_BioStructure* organ1N, int faceInOrgan1N, COME_BioStructure* organ2N, int faceInOrgan2N ){
00077 
00078         organ1 = organ1N;
00079         organ2 = organ2N;
00080 
00081         faceInOrgan1 = faceInOrgan1N;
00082         faceInOrgan2 = faceInOrgan2N;
00083         
00084         penetrationDistance = calculatePenetrationGlobalPosition();
00085 
00086         //***************** Calculation of Spring constant using constant and masses **************************
00087         
00088         //double M1 = organ1->getTissue()->getMass();
00089         //double M2 = organ2->getTissue()->getMass();
00090         //springConstant = M1 < M2 ? M1 * K*2 : M2 * K*2;
00091         
00092         //***************** Calculation of Spring constant using young modulus **************************
00093         
00094         COME_Molecule* mol1 = organ1->getSurface()->getAFace( faceInOrgan1).getNearestMolecule();
00095         COME_Molecule* mol2 = organ2->getSurface()->getAFace( faceInOrgan2).getNearestMolecule();
00096         double allowedDistance =  mol1->getRadius() + mol2->getRadius();
00097         
00098         springConstant = ( ( mol1->getMaterial()->getYoungsModulus()+ mol2->getMaterial()->getYoungsModulus() ) / 2.0 ) * allowedDistance * 10;// * 100;
00099         
00100         
00101         forceInFaceOrgan1 = ( organ2->getSurface()->getAFace( faceInOrgan2 ).getNormalGlobalPosition() * penetrationDistance ) * springConstant;
00102         forceInFaceOrgan2 = ( organ1->getSurface()->getAFace( faceInOrgan1 ).getNormalGlobalPosition() * penetrationDistance ) * springConstant;
00103                 
00104 }
00105 
00106 
00107 COME_Collision :: ~COME_Collision(){
00108 
00109         
00110 }
00111 
00115 
00116 
00117 
00121 int
00122 COME_Collision :: getFace( COME_BioStructure* organ ) const{
00123 
00124         if ( organ == organ1 ){
00125         
00126                 return faceInOrgan1;
00127         
00128         }
00129         else{
00130                 
00131                 return faceInOrgan2;
00132         
00133         }
00134 }
00135 
00136 double          
00137 COME_Collision :: getPenetrationDistance() const{
00138 
00139         return penetrationDistance;
00140 
00141 }
00142 
00143 double          
00144 COME_Collision :: getSpringConst() const{
00145 
00146         return springConstant;
00147 
00148 }
00149 
00150 COME_Force      
00151 COME_Collision :: getForceInFace( COME_BioStructure* organ ) const{
00152 
00153         if ( organ == organ1 ){
00154         
00155                 return forceInFaceOrgan1;
00156         
00157         }
00158         else{
00159                 
00160                 return forceInFaceOrgan2;
00161         
00162         }
00163 
00164 }
00165         
00166 COME_BioStructure*              
00167 COME_Collision :: getOrgan1(){
00168 
00169         return organ1;
00170 
00171 }
00172 
00173 COME_BioStructure*              
00174 COME_Collision :: getOrgan2(){
00175 
00176         return organ2;
00177 
00178 }
00179 
00180 
00184 double                          
00185 COME_Collision :: calculatePenetration(){
00186 
00187         return (organ1->getSurface()->getAFace( faceInOrgan1 )).distanceFaceFace( organ2->getSurface()->getAFace( faceInOrgan2 ));
00188 
00189 }
00190 
00191 double                          
00192 COME_Collision :: calculatePenetrationGlobalPosition(){
00193 
00194         return organ1->getSurface()->getAFacePt(faceInOrgan1 )->distanceFaceFaceGlobalPosition( organ2->getSurface()->getAFacePt( faceInOrgan2 ));
00195 
00196 }

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