Class: BulldogPhysics::Particles::Generators::ParticleDrag
- Inherits:
-
ParticleForceGenerator
- Object
- ParticleForceGenerator
- BulldogPhysics::Particles::Generators::ParticleDrag
- Defined in:
- lib/Particles/particle_drag.rb
Instance Attribute Summary collapse
-
#k2 ⇒ Object
readonly
holds the velocity squared drag coefficient.
-
#kl ⇒ Object
readonly
holds the velocity drag coefficient.
Attributes inherited from ParticleForceGenerator
Instance Method Summary collapse
-
#initialize(k1, k2) ⇒ ParticleDrag
constructor
A new instance of ParticleDrag.
- #update_force(particle, duration) ⇒ Object
Constructor Details
#initialize(k1, k2) ⇒ ParticleDrag
Returns a new instance of ParticleDrag.
9 10 11 12 13 |
# File 'lib/Particles/particle_drag.rb', line 9 def initialize(k1,k2) super @k1 = k1 @k2 = k2 end |
Instance Attribute Details
#k2 ⇒ Object (readonly)
holds the velocity squared drag coefficient
7 8 9 |
# File 'lib/Particles/particle_drag.rb', line 7 def k2 @k2 end |
#kl ⇒ Object (readonly)
holds the velocity drag coefficient
6 7 8 |
# File 'lib/Particles/particle_drag.rb', line 6 def kl @kl end |
Instance Method Details
#update_force(particle, duration) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/Particles/particle_drag.rb', line 15 def update_force(particle, duration) force = particle.velocity.dup dragCoeff = force.magnitude dragCoeff = k1 * dragCoeff + k2 * dragCoeff * dragCoeff force.normalize force *= -dragCoeff particle.addForce(force) end |