| 1 | #ifndef __RIGIDBODY_HPP__ | 
| 2 | #define __RIGIDBODY_HPP__ | 
| 3 |  | 
| 4 | #include <vector> | 
| 5 | //#include "primitives/Atom.hpp" | 
| 6 | //#include "types/AtomStamp.hpp" | 
| 7 | #include "types/RigidBodyStamp.hpp" | 
| 8 | #include "primitives/StuntDouble.hpp" | 
| 9 | using namespace std; | 
| 10 |  | 
| 11 | class Atom; | 
| 12 | class AtomStamp; | 
| 13 |  | 
| 14 | typedef struct { | 
| 15 | double vec[3]; | 
| 16 | double& operator[](int index) {return vec[index];} | 
| 17 | } vec3; | 
| 18 |  | 
| 19 | typedef struct { | 
| 20 | double mat[3][3]; | 
| 21 | double* operator[](int index) {return mat[index];} | 
| 22 | } mat3x3; | 
| 23 |  | 
| 24 | class RigidBody : public StuntDouble { | 
| 25 |  | 
| 26 | public: | 
| 27 |  | 
| 28 | RigidBody(); | 
| 29 | //RigidBody(const RigidBody& rb); | 
| 30 |  | 
| 31 | virtual ~RigidBody(); | 
| 32 |  | 
| 33 | void addAtom(Atom* at, AtomStamp* ats); | 
| 34 |  | 
| 35 | void getPos( double theP[3] ); | 
| 36 | void setPos( double theP[3] ); | 
| 37 |  | 
| 38 | void getVel( double theV[3] ); | 
| 39 | void setVel( double theV[3] ); | 
| 40 |  | 
| 41 | void getFrc( double theF[3] ); | 
| 42 | void addFrc( double theF[3] ); | 
| 43 | void zeroForces(); | 
| 44 |  | 
| 45 | bool isLinear() {return is_linear;} | 
| 46 | int linearAxis() {return linear_axis;} | 
| 47 |  | 
| 48 | double getMass( void ) { return mass; } | 
| 49 |  | 
| 50 | void printAmatIndex( void ); | 
| 51 | void setEuler( double phi, double theta, double psi ); | 
| 52 | void getQ( double the_q[4] ); // get the quanternions | 
| 53 | void setQ( double the_q[4] ); | 
| 54 |  | 
| 55 | void getA( double the_A[3][3] ); // get the full rotation matrix | 
| 56 | void setA( double the_A[3][3] ); | 
| 57 |  | 
| 58 | void getJ( double theJ[3] ); | 
| 59 | void setJ( double theJ[3] ); | 
| 60 |  | 
| 61 | virtual void setType(char* type) {strcpy(rbName, type);} | 
| 62 | virtual char* getType() { return rbName;} | 
| 63 |  | 
| 64 | void getTrq( double theT[3] ); | 
| 65 | void addTrq( double theT[3] ); | 
| 66 |  | 
| 67 | void getI( double the_I[3][3] ); | 
| 68 | void lab2Body( double r[3] ); | 
| 69 | void body2Lab( double r[3] ); | 
| 70 |  | 
| 71 | double getZangle( ); | 
| 72 | void setZangle( double zAng ); | 
| 73 | void addZangle( double zAng ); | 
| 74 |  | 
| 75 | void calcRefCoords( void ); | 
| 76 | void doEulerToRotMat(vec3 &euler, mat3x3 &myA ); | 
| 77 | void calcForcesAndTorques( void ); | 
| 78 | void updateAtoms( void ); | 
| 79 |  | 
| 80 | //void yourAtomsHaveMoved( void ); | 
| 81 |  | 
| 82 | // Four functions added for derivatives with respect to Euler Angles: | 
| 83 | // (Needed for minimization routines): | 
| 84 |  | 
| 85 | void getGrad(double gradient[6] ); | 
| 86 | void getEulerAngles( double myEuler[3] ); | 
| 87 |  | 
| 88 | double max(double x, double y); | 
| 89 | double min(double x, double y); | 
| 90 |  | 
| 91 |  | 
| 92 | // utility routines | 
| 93 |  | 
| 94 | void findCOM( void ); | 
| 95 |  | 
| 96 | virtual void accept(BaseVisitor* v); | 
| 97 |  | 
| 98 | vector<Atom*> getAtoms() { return myAtoms;} | 
| 99 | int getNumAtoms() {return myAtoms.size();} | 
| 100 |  | 
| 101 | void getAtomPos(double theP[3], int index); | 
| 102 | void getAtomVel(double theV[3], int index); | 
| 103 | void getAtomRefCoor(double pos[3], int index); | 
| 104 | protected: | 
| 105 |  | 
| 106 | double mass;     // the total mass | 
| 107 | double pos[3];   // the position array (center of mass) | 
| 108 | double vel[3];   // the velocity array (center of mass) | 
| 109 | double frc[3];   // the force array    (center of mass) | 
| 110 | double trq[3];   // the torque vector  ( space fixed ) | 
| 111 | double ji[3];    // the angular momentum vector (body fixed) | 
| 112 | double A[3][3];  // the rotation matrix | 
| 113 | double I[3][3];  // the inertial tensor (body fixed) | 
| 114 | double sU[3][3]; // the standard unit vectors (body fixed) | 
| 115 | double zAngle;   // the rotation about the z-axis (body fixed) | 
| 116 |  | 
| 117 | bool is_linear; | 
| 118 | int linear_axis; | 
| 119 | double momIntTol; | 
| 120 |  | 
| 121 | vector<Atom*> myAtoms;  // the vector of atoms | 
| 122 | vector<vec3> refCoords; | 
| 123 | vector<mat3x3> refOrients; | 
| 124 |  | 
| 125 | char rbName[100]; //it will eventually be converted into string | 
| 126 | }; | 
| 127 |  | 
| 128 | #endif |