Ball Collision Simulation

This is a simple physics engine for simulating sphere collision.
1.2K Downloads
Updated 16 Jan 2015

View License

This matlab function simply simulates the collision of balls. Each ball has three properties: radius, mass and charge quantity. The program detects possible collisions in each frame.
Examples:
>>SphereCollider([1.25 1 0;1.25 1 0],[-5 0 0;1.25 0 0],[3 0 0;0 0 0],...
'g',0,'debug','off','t',25)
>>SphereCollider('g',0,'debug','off')
>>SphereCollider([1 1 0],[0 0 0],[0 0 0],...
'GravityVec',[0 -1 0],'GroundPoint',[0 -10 0],...
'g',1,'dt',0.025,'debug','on','t',20)
>>SphereCollider([0.5 1 0],[-5 0 0],[0 1.15 0],...
'sphere',[2 0 0 0],'GravitySrc',[10 0 0 0],...
'G',-1,'g',0,'debug','off','t',300)
The movement of walls is defined by anonymous functions of time. The corresponding input argument is a cell that contains handles of such functions,
{...
{@(t) vx, @(t) vy, @(t) vz},... velocity of the first wall
{@(t) vx, @(t) vy, @(t) vz},... velocity of the second wall
...
}
For example:
f1 = @(t) 0.2*heaviside(t)-0.2*heaviside(t-20);
f2 = @(t) 0;
v = {{f1,f2,f2}};
SphereCollider([1 1 0;1 1 0;1 1 0],[0 4 0;0 -4 0;-4 0 0],[2 -2 0;1 1 0;2 4 0],'sphere',[2 0 0 0],'g',0,'debug','off','t',250,'sphere_velocity',v)

Cite As

Ligong Han (2024). Ball Collision Simulation (https://www.mathworks.com/matlabcentral/fileexchange/41032-ball-collision-simulation), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2012a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Physics in Help Center and MATLAB Answers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.4.0.0

- problems with parameter assignment fixed
- new demos added
- I include IdealGasSimulation.m in this submittion

1.3.0.0

- new feature added, walls can move now
- added demos

1.2.0.0

minor bug fixes

1.0.0.0