PhysEng is a fully Python-based physics engine designed for simulating physical systems in 3D. It's user-friendly and highly flexible, enabling the creation of complex simulations with ease.
- Particle Simulation: Create and simulate particles with mass, charge, and velocity.
- Soft Body Simulation: Create and simulate soft bodies such as balls and anchored cloth.
- Physics Fields: Add physics fields such as gravity, drag, and electrostatic fields.
- Collision Detection: Detect and resolve collisions between particles and soft bodies.
- Visualization: Visualize and interact with the simulation in real-time.
- Customization: Customize the simulation with custom physics fields and soft bodies.
Follow these steps to install PhysEng:
- Clone the repository.
- Install the library and dependencies using pip:
This library is verified to run on Python 3.10 and above. While this library is a standalone library, it is recommended to install the following dependencies to ensure compatibility with the library. The phyiscs engine is completely written in python however it requires some dependancies to visualize and render the simulation.
pip install ffmpeg-python==0.2.0
pip install numpy==1.26.4
pip install pygame==2.5.2
pip install ffmpeg-python==0.2.0
pip install scipy==1.10.1
pip install matplotlib==3.5.1
pip install imageio==2.33.1
pip install imageio-ffmpeg==0.4.9
- Step 1: Create a new Python file and import the necessary libraries
import pygame as pg
import PhysEng as pe
from PhysEng.Environment import Environment
from PhysEng.Visualize import Visualize
from PhysEng.Visualize.pygametoxy import pygame_to_xy
import numpy as np- Step 2: Create a new environment and add some particles
#.....Previous code
env = Environment()- Step 3 : Create the visualization so we can see and interact with the simulation at runtime.
#.....Previous code
new_visualization = Visualize(env) #pass the environment- Step 4: ADD PARTICLES The Library has a few built in basic objects such as particles, balls and anchored cloth. You can create these objects and add them to the environment. As such we also have a few built in physics fields such as gravity, drag and electrostatic fields.
#.....Previous code
from PhysEng.Bodies import Particle
#adding a few particle
for _ in range(2000):
env.add_particle(pe.Particle(mass = np.random.randint(1,15), position = np.random.rand(3) * 200 -100, radius=2))
#adding fields
env.add_uniform_acceleration_field(name='gravity', a=[0, 9.8, 0])
env.add_drag(name='drag')- Step 5: Run the simulation
#.....Previous code
new_visualization.simulationheight = [0, 50]
new_visualization.simulationwidth = [-100, 100]
new_visualization.show()