Class: BulldogPhysics::Particles::Collisions::ParticleRod
- Inherits:
-
ParticleLink
- Object
- ParticleContactGenerator
- ParticleLink
- BulldogPhysics::Particles::Collisions::ParticleRod
- Defined in:
- lib/Particles/particle_rod.rb
Overview
Cables link a pair of particles, generating a contact if they stray too far apart.
Instance Attribute Summary collapse
-
#length ⇒ Object
Holds the length of the rod.
Attributes inherited from ParticleLink
Instance Method Summary collapse
-
#add_contact(contactArray, limit) ⇒ Object
-
Fills the given contact structure with the contact needed to keep the rod from extending or compressing.
-
- #current_length ⇒ Object
-
#initialize(particle1, particle2, length) ⇒ ParticleRod
constructor
A new instance of ParticleRod.
Constructor Details
#initialize(particle1, particle2, length) ⇒ ParticleRod
Returns a new instance of ParticleRod.
14 15 16 17 18 |
# File 'lib/Particles/particle_rod.rb', line 14 def initialize(particle1, particle2, length) super(particle1, particle2) @length = length puts "CREATING ROD WITH LENGTH #{@length}" end |
Instance Attribute Details
#length ⇒ Object
Holds the length of the rod
11 12 13 |
# File 'lib/Particles/particle_rod.rb', line 11 def length @length end |
Instance Method Details
#add_contact(contactArray, limit) ⇒ Object
-
Fills the given contact structure with the contact needed to keep the rod from extending or compressing.
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 |
# File 'lib/Particles/particle_rod.rb', line 21 def add_contact(contactArray, limit) current_len = current_length if( current_len == @length) return 0 end contact = ParticleContact.new(@particle1, @particle2) normal = @particle2.position - @particle1.position normal.normalize # The contact normal depends on whether we’re extending or compressing. contact.contact_normal = normal if( current_len > @length) contact.penetration = (current_len - @length) else contact.contact_normal *= -1 contact.penetration = @length - current_len end contact.restitution = 0 contactArray << contact return 1 end |
#current_length ⇒ Object
50 51 52 |
# File 'lib/Particles/particle_rod.rb', line 50 def current_length (@particle1.position - @particle2.position).magnitude end |