# Physics

education

School assignments for year 2 classes. Most of the work below was created in a framework supplied by our teacher Mr. Dini.

N-body Simulation>

## N-body Simulation #

This simulation shows several bodies. The red ones have a mass between 2 and 3 kg and the green bodies have a mass between 1 and 2 kg. one larger mass (shown green) is spawned in the center with a mass of 50kg.

All bodies have a random velocity at initialization. Collision is ignored in this simulation.

Soft-body Dynamics>

# Soft-body Dynamics #

This simulation uses Euler integration (and is therefore really unstable.) Used both a fixed time-step of 1.0f / 200.0f and sub-stepping to avoid the cloth from breaking.

Spherical Collision>

# Spherical Collision #

Small spheres bouncing on top of a larger sphere. The collision response gets calculated like this:

``````10void BallResponse(Ball& b1, Ball& b2)
11{
12	// Axis of collision
13	Vec3f Axis = (b2.mPos - b1.mPos).Normalize();
14
15	// Velocity projected on the collision axis
16	Vec3f velBefore1 = Axis * DOT(Axis, b1.mVelocity);
17	Vec3f velBefore2 = Axis * DOT(Axis, b2.mVelocity);
18
19	// Velocity after collision
20	float rMass = (1.0f / (b1.mMass + b2.mMass);
21	Vec3f velAfter1 = ((b1.mMass * velBefore1) - (b2.mMass * velBefore1) + (2.0f * b2.mMass * velBefore2)) * rMass);
22	Vec3f velAfter2 = ((2.0f * b1.mMass * velBefore1) - (b1.mMass * velBefore2) + (b2.mMass * velBefore2)) * rMass);
23
24	// the new velocity
25	b1.mVelocity = b1.mVelocity - velBefore1 + velAfter1;
26	b2.mVelocity = b2.mVelocity - velBefore2 + velAfter2;
27}``````
Bouncing Cube>

# Bouncing Cube #

This was the final assignment for the Physics course. A cube bouncing of the floor, and converting its energy in rotational and linear force.

The challenge of this assignment was primarily understanding the enormous formula. (and making sure the simulation keeps its energy when the coefficient of restitution is 1.0f)

Author
Daniel Wustenhoff
‘Software Engineer’