1 // Particle.h - a massive particle which is part of a rigid body. 2 // 3 // Copyright (C) 2001--2002 Sam Varner 4 // 5 // This file is part of Vamos Automotive Simulator. 6 // 7 // This program is free software; you can redistribute it and/or modify 8 // it under the terms of the GNU General Public License as published by 9 // the Free Software Foundation; either version 2 of the License, or 10 // (at your option) any later version. 11 // 12 // This program is distributed in the hope that it will be useful, 13 // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 // GNU General Public License for more details. 16 // 17 // You should have received a copy of the GNU General Public License 18 // along with this program; if not, write to the Free Software 19 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 21 #ifndef _PARTICLE_H_ 22 #define _PARTICLE_H_ 23 24 #include "../geometry/Three_Vector.h" 25 #include "../geometry/Three_Matrix.h" 26 #include "../geometry/Inertia_Tensor.h" 27 #include "../geometry/Material.h" 28 #include "Frame.h" 29 30 namespace Vamos_Body 31 { 32 // Particle is a point mass which may be part of a rigid body. It 33 // has position and orientation information inherited from Frame. A 34 // Particle can exert forces and torques. 35 class Particle : public Frame 36 { 37 public: 38 // Specify position and orientation. 39 Particle (double mass, 40 const Vamos_Geometry::Three_Vector& position, 41 const Vamos_Geometry::Three_Matrix& orientation, 42 const Frame* parent = 0); 43 44 // Take the parent's orientation. 45 Particle (double mass, 46 const Vamos_Geometry::Three_Vector& position, 47 const Frame* parent = 0); 48 49 // The particle's frame is coincident with the parent's. 50 Particle (double mass = 0.0, 51 const Frame* parent = 0); 52 ~Particle()53 virtual ~Particle () {}; 54 55 // Return the force exerted on the rigid body in the body's frame. force()56 virtual Vamos_Geometry::Three_Vector force () const 57 { return rotate_to_parent (m_force); } 58 59 // Return the impulse exerted on the rigid body in the body's 60 // frame. impulse()61 virtual Vamos_Geometry::Three_Vector impulse () const 62 { return rotate_to_parent (m_impulse); } 63 64 // Return the torque exerted on the rigid body in the body's frame. torque()65 virtual Vamos_Geometry::Three_Vector torque () const 66 { return rotate_to_parent (m_torque); } 67 68 // Classes derived from Particle may lie about their positions 69 // for collisions... contact_position()70 virtual Vamos_Geometry::Three_Vector contact_position () const 71 { return position (); } 72 73 // ...for exerting forces and impulses... force_position()74 virtual Vamos_Geometry::Three_Vector force_position () const 75 { return position (); } 76 77 // ...for exerting torques... torque_position()78 virtual Vamos_Geometry::Three_Vector torque_position () const 79 { return position (); } 80 81 // ...or for constructing the inertia tensor of the rigid body. mass_position()82 virtual Vamos_Geometry::Three_Vector mass_position () const 83 { return position (); } 84 contact(const Vamos_Geometry::Three_Vector & impulse,const Vamos_Geometry::Three_Vector & velocity,double distance,const Vamos_Geometry::Three_Vector & normal,const Vamos_Geometry::Three_Vector & angular_velocity,const Vamos_Geometry::Material & material)85 virtual double contact (const Vamos_Geometry::Three_Vector& impulse, 86 const Vamos_Geometry::Three_Vector& velocity, 87 double distance, 88 const Vamos_Geometry::Three_Vector& normal, 89 const Vamos_Geometry::Three_Vector& angular_velocity, 90 const Vamos_Geometry::Material& material) 91 { return 0.0; } 92 93 // Return the particle's mass. mass()94 double mass () const { return m_mass; } 95 single_contact()96 virtual bool single_contact () const { return true; } 97 98 // Return the material properties. material()99 const Vamos_Geometry::Material& material () const 100 { return m_material; } 101 102 // Find and store the forces, impulses, and torques for the 103 // current configuration. find_forces()104 virtual void find_forces () {}; 105 106 // Propagate the Particle forward in time by TIME. propagate(double time)107 virtual void propagate (double time) {}; 108 109 // Undo the last propagation. rewind()110 virtual void rewind () {}; 111 112 // Do any necessary cleanup at the end of a time step. end_timestep()113 virtual void end_timestep () {}; 114 115 // Set the force, impulse and torque to zero; 116 virtual void reset (); 117 118 protected: set_mass(double new_mass)119 void set_mass (double new_mass) { m_mass = new_mass; } 120 set_material(const Vamos_Geometry::Material & new_material)121 void set_material (const Vamos_Geometry::Material& new_material) 122 { m_material = new_material; } 123 set_force(const Vamos_Geometry::Three_Vector & new_force)124 void set_force (const Vamos_Geometry::Three_Vector& new_force) 125 { m_force = new_force; } 126 set_impulse(const Vamos_Geometry::Three_Vector & new_impulse)127 void set_impulse (const Vamos_Geometry::Three_Vector& new_impulse) 128 { m_impulse = new_impulse; } 129 set_torque(const Vamos_Geometry::Three_Vector & new_torque)130 void set_torque (const Vamos_Geometry::Three_Vector& new_torque) 131 { m_torque = new_torque; } 132 133 private: 134 // The mass of the particle. 135 double m_mass; 136 137 // Material properties for the particle. 138 Vamos_Geometry::Material m_material; 139 140 // The resultant force exerted by the component. 141 Vamos_Geometry::Three_Vector m_force; 142 143 // The impulse exerted by the component. 144 Vamos_Geometry::Three_Vector m_impulse; 145 146 // The resultant torque exerted by the component. 147 Vamos_Geometry::Three_Vector m_torque; 148 }; 149 } 150 151 #endif // not _PARTICLE_H_ 152