src/vamos/body/Contact_Point.cc

Go to the documentation of this file.
00001 //      Contact_Point.cc - a particle that responds to collisions.
00002 //
00003 //  Copyright (C) 2002 Sam Varner
00004 //
00005 //  This file is part of Vamos Automotive Simulator.
00006 //
00007 //  This program is free software; you can redistribute it and/or modify
00008 //  it under the terms of the GNU General Public License as published by
00009 //  the Free Software Foundation; either version 2 of the License, or
00010 //  (at your option) any later version.
00011 //
00012 //  This program is distributed in the hope that it will be useful,
00013 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 //  GNU General Public License for more details.
00016 //
00017 //  You should have received a copy of the GNU General Public License
00018 //  along with this program; if not, write to the Free Software
00019 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 
00021 #include <vamos/body/Contact_Point.h>
00022 
00023 //* Constructors
00024 
00025 Vamos_Body::Contact_Point::
00026 Contact_Point (double mass, const Vamos_Geometry::Three_Vector& position, 
00027                            const Vamos_Geometry::Three_Matrix& orientation,
00028                            Vamos_Geometry::Material::Material_Type type,
00029                            double friction, double restitution) 
00030   : Particle (mass, position, orientation),
00031         m_contact (false)
00032 {
00033   m_material = new Vamos_Geometry::Material (type, friction, restitution);
00034 }
00035 
00036 // Take the parent's orientation.
00037 Vamos_Body::Contact_Point::
00038 Contact_Point (double mass, const Vamos_Geometry::Three_Vector& position,
00039                            Vamos_Geometry::Material::Material_Type type,
00040                            double friction, double restitution ) 
00041   : Particle (mass, position),
00042         m_contact (false)
00043 {
00044   m_material = new Vamos_Geometry::Material (type, friction, restitution);
00045 }
00046 
00047 // Default constructor.
00048 Vamos_Body::Contact_Point::
00049 Contact_Point ()
00050 {
00051 }
00052 
00053 // Handle collisions.  The return value is how much the particle has
00054 // moved as a result of the contact.  For a Particle, this is always
00055 // 0.  But, for derived classes that model moving parts, a non-zero
00056 // value may be returned.
00057 double Vamos_Body::Contact_Point::
00058 contact (const Vamos_Geometry::Three_Vector& position,
00059                  const Vamos_Geometry::Inertia_Tensor& inertia,
00060                  const Vamos_Geometry::Three_Vector& velocity, 
00061                  double, // distance,
00062                  const Vamos_Geometry::Three_Vector& normal,
00063                  const Vamos_Geometry::Three_Vector& ang_velocity,
00064                  Vamos_Geometry::Material_Handle material)
00065 {
00066   // POSITION - the world-frame vector from the body's center of mass to
00067   //   the particle.
00068   // INERTIA - the body's inertia tensor.
00069   // VELOCITY - the particle's velocity normal to the surface in the
00070   //   body frame.
00071   // ANG_VELOCITY - the angular velocity about the normal to the
00072   //   surface. 
00073   // NORM - the normal vector in the body frame.
00074   // MATERIAL - the material properies of the thing collided with.
00075 
00076    Vamos_Geometry::Three_Vector v_perp = rotate_in (velocity.project (normal));
00077 
00078   // Find the effective mass.
00079   double meff = inertia.inertia (position, normal);
00080   m_impulse = -(1.0 + (m_material->restitution_factor () 
00081                                            * material->restitution_factor ())) * meff * v_perp;
00082 
00083   Vamos_Geometry::Three_Vector v_par = rotate_in (velocity) - v_perp;
00084   m_impulse -= v_par.unit () * m_material->friction_factor ()
00085         * material->friction_factor () * m_impulse.abs ();
00086 
00087   m_contact = true;
00088   
00089   return 0;
00090 }
00091 
00092 
00093 // Find and store the forces and torques for the current
00094 // configuration.
00095 void Vamos_Body::Contact_Point::
00096 find_forces ()
00097 {
00098   if (!m_contact)
00099         {
00100           m_force.zero ();
00101           m_impulse.zero ();
00102           m_torque.zero ();
00103         }
00104 }
00105 
00106 // Do any neccary cleanup at the end of a time step.
00107 void Vamos_Body::Contact_Point::
00108 end_timestep ()
00109 {
00110   m_contact = false;
00111 }

Generated on Thu Oct 19 04:05:55 2006 by  doxygen 1.4.6