[go: up one dir, main page]

Menu

[9202b6]: / body / Particle.h  Maximize  Restore  History

Download this file

152 lines (118 with data), 5.0 kB

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