Page 1 of 1

Setting Up Attracting Force Between Bodies

Posted: Thu Oct 28, 2021 3:51 pm
by jzhong2
Hi there! I am new to pybullet, and am trying to find a way to simulate collisions between spheres/boxes with dipoles (which just means they can attract or repel each other at one specific point). I am able to create the bodies, but am currently stuck at figuring out how to set up this dipole moment on them. I read the quick start guide but it seems like pybullet still don't have this feature yet...? I'm so sorry for the probably intuitive question, I'm just a desperate undergraduate not knowing a way to initiate their capstone project :cry:

Re: Setting Up Attracting Force Between Bodies

Posted: Thu Oct 28, 2021 6:19 pm
by drleviathan
A few things:

(1) You might have more success if you move your question to the PyBullet Support and Feedback section of this forum. This General Biullet Physics Support and Feedback section is more about the C++ API.

(2) Are you sure you want to perform your simulation using PyBullet rather than C++? You'll experience better performance under C++. Also, I have an idea how you might go about it within the C++ API...

(3) ... in short you could create a single custom class (let's call it ElectricFieldAction) derived from the pure virtual btActionInterface. You would implement its ElectricFieldAction::updateAction(btCollisionWorld* collisionWorld, btScalar deltaTimeStep) method to push the dipole objects around. Then you would instantiate an ElectricFieldAction instance and add it to the world:

Code: Select all

ElectricFieldAction action = ElectricFieldAction();
world->addAction(&action);
The Bullet API will then call action.updateAction(world, deltaTimeStep) every substep of the simulation. This happens after the integration, collision resolution, and object deactivation phases of the substep.

(4) It is possible PyBullet exposes the ability to create custom Actions like that: dunno.

Re: Setting Up Attracting Force Between Bodies

Posted: Fri Oct 29, 2021 12:18 am
by jzhong2
Thank you so much!!