Setting Up Attracting Force Between Bodies

Post Reply
jzhong2
Posts: 2
Joined: Tue Oct 26, 2021 2:52 pm

Setting Up Attracting Force Between Bodies

Post 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:
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: Setting Up Attracting Force Between Bodies

Post 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.
jzhong2
Posts: 2
Joined: Tue Oct 26, 2021 2:52 pm

Re: Setting Up Attracting Force Between Bodies

Post by jzhong2 »

Thank you so much!!
Post Reply