I saw a great Peter Colling Ridge tutorial on
http://www.petercollingridge.co.uk/pygame-physics-simulation/
and I am expanding the PyParticles script
The code is available on the site (for free), I use PyParticles4.py
Classes used in the textbook
Particle class
Round 2d objects with radius, mass, speed, location
Spring Class
A Spring, which binds 2 objects (Particles) and uses Hooke's law (F = -kx) to determine the interaction between them
Environment class
The environment in which particles interact
I was wondering if I can use 2 particles and create a class "Rod" (for example, the Spring class in the tutorial), which had a certain length and did not allow particles to come closer, go further than this (specified) length.
Besides,
Applying an effort (when necessary) to each Particle so that if one is pulled to the left, then the other, but Realistically ..
It is very likely that two different types of balls were connected (from the center) using a steel rod, but in 2 ..
And I do not want to use third-party modules
Thanks in advance.
EDIT / UPDATE:
Tried to apply the constraint theorem (it failed)
Here is 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'
pradyunsg
source share