Class: BulldogPhysics::Particles::Generators::ParticleDrag

Inherits:
ParticleForceGenerator show all
Defined in:
lib/Particles/particle_drag.rb

Instance Attribute Summary collapse

Attributes inherited from ParticleForceGenerator

#registrations

Instance Method Summary collapse

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

#k2Object (readonly)

holds the velocity squared drag coefficient



7
8
9
# File 'lib/Particles/particle_drag.rb', line 7

def k2
  @k2
end

#klObject (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

  dragCoeff = force.magnitude

  dragCoeff = k1 * dragCoeff + k2 * dragCoeff * dragCoeff

  force.normalize
  force *= -dragCoeff
  particle.addForce(force)
end