KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have seen the great tutorial by Peter Colling Ridge on http://www.petercollingridge.co.uk/pygame-physics-simulation/ and I am extending the PyParticles script The code is available on the site(for free), I am using PyParticles4.py Classes used in the tutorial The Particle Class Circular 2d objects with radius,mass,velocity,location The Spring Class A spring that binds 2 objects (Particles) and uses the Hooke's law (F = -kx) to determine the interaction between them The Environment Class The Environment where the Particles interact I was wondering if I could to use 2 Particles and make a 'Rod' class (like the Spring class in the tutorial) that had a specific length and didn't allow the particles to come closer go further than that (specified) length. Also, Appling a force (when needed) to each Particle such that if one is pulled toward the left, so does the other, but Realistically.. Much like if a 2 different types of balls were joined(from the center) using a steel rod, but in 2-d.. And I don't want to use 3rd party modules Thanks in advance.. EDIT/UPDATE: Tried to apply constraint theorem (it failed) Here's the code: class Rod: def __init__(self, p1, p2, length=50): self.p1 = p1 self.p2 = p2 self.length = length def update(self): 'Updates The Rod and Particles' # Temp store of co-ords of Particles involved x1 = self.p1.x x2 = self.p2.x ###### Same for Y ####### y1 = self.p1.y y2 = self.p2.y # Calculation of d1,d2,d3 and final values (x2,y2) # from curr
Tags (comma-separated)
Save Edits
Cancel