Saturday, 2 May 2026

Visualizing Particle Kinematics with Python

Understanding the relationship between position, velocity, and acceleration is fundamental to physics. However, seeing how these variables evolve simultaneously can be challenging with equations alone. In this post, we use Python, NumPy, and Matplotlib to model a particle's motion. By leveraging lambda functions and vectorized operations, we can generate a high-resolution continuous model while calculating specific discrete data points for a clear, side-by-side comparison.

The Python Script



import numpy as np
import matplotlib.pyplot as plt

# 1. Define Kinematic Functions using Lambda and NumPy
# These handle both single numbers and arrays automatically
pos = lambda t: 2 * np.sin(np.pi * t / 4)
vel = lambda t: 2 * np.pi / 4 * np.cos(np.pi * t / 4)
acc = lambda t: -2 * (np.pi / 4) ** 2 * np.sin(np.pi * t / 4)

# 2. Generate Discrete Data Points
time_steps = [t / 10 for t in range(21)]
positions, velocities, accel = [], [], []

print(f"{'Time(s)':<10 100="" 10="" 1="" 2="" 3.="" 4.="" 45="" a:="" a="" a_curve="" acc="" accel.append="" accel="" acceleration="" article="" ax1.grid="" ax1.plot="" ax1.scatter="" ax1.set_title="" ax1.set_ylabel="" ax1="" ax2.grid="" ax2.plot="" ax2.scatter="" ax2.set_ylabel="" ax2="" ax3.grid="" ax3.plot="" ax3.scatter="" ax3.set_xlabel="" ax3.set_ylabel="" ax3="" cc="" cm="" code="" color="green" curves="" el="" f="" fig="" figsize="(8," for="" gen_tpts="" generate="" ime="" in="" kinematics:="" label="Continuous Acc" linestyle="--" os="" p:="" p="" p_curve="" plot="" plotting="" plt.show="" plt.subplots="" plt.tight_layout="" position="" positions.append="" positions="" print="" rue="" s2="" s="" sharex="True)" smooth="" time_steps:="" time_steps="" ts:="" ts="" v:="" v="" v_curve="" vel="" velocities.append="" velocities="" velocity="" visualization="">
Conclusion As shown in the resulting plots, Python provides a powerful environment for physics simulation. By using numpy.linspace, we created a smooth curve that represents the true continuous nature of the motion, while the scatter points highlight our specific calculated intervals. This "stacked" subplot approach is particularly useful because it allows us to see exactly how a peak in position corresponds to a zero-crossing in velocity, making the abstract calculus of motion much more intuitive.

Visualizing Particle Kinematics with Python

Understanding the relationship between position, velocity, and acceleration is fundamental to physics. However, seeing how these variables e...